TradeBuilder drops commissions reported after the first execution of an order
维护者通常 1 天内回复
已经有一个关联 PR 被合并了。
- #10188 来自 @quantconnect-kronos —— 已合并
评估
调研方向
The fee cache is in TradeBuilder.ProcessFill, keyed by order ID in _ordersWithFeesAssigned; the reproduction is a C# snippet that builds a SPY partial fill followed by a status-only Filled event with a $1 commission and checks ClosedTrades[0].TotalFees. Start by reading how ProcessFill decides whether an order's fee has already been assigned and separate commission handling from execution and price updates. Done means the snippet reports 1, duplicate commission reports are still ignored, and a regression test covers a status-only completion after a partial fill.
由索引模型根据 Issue 内容生成。
描述
Problem
TradeBuilder.ProcessFill records an order ID in _ordersWithFeesAssigned on its first execution, even when the reported fee is zero. Any commission reported by a later event for that order is then ignored by trade statistics.
For example, a partial buy execution can report no commission, followed by a final status-only event carrying the commission. After the position closes, ClosedTrades[].TotalFees is zero instead of the commission paid. This is independent of portfolio cash accounting: it concerns the fees attached to reconstructed trades.
Reproduction
var symbol = new Symbol(
SecurityIdentifier.GenerateEquity("SPY", Market.USA, mapSymbol: false), "SPY");
var time = new DateTime(2024, 1, 2, 15, 0, 0, DateTimeKind.Utc);
var builder = new TradeBuilder(FillGroupingMethod.FillToFill, FillMatchingMethod.FIFO);
builder.SetSecurityManager(new SecurityManager(new TimeKeeper(time)));
var noFee = new OrderFee(new CashAmount(0m, "USD"));
var commission = new OrderFee(new CashAmount(1m, "USD"));
builder.ProcessFill(new OrderEvent(1, symbol, time,
OrderStatus.PartiallyFilled, OrderDirection.Buy, 300m, 2m, noFee), 1m, 0m);
// The brokerage closes the order without another execution and reports its commission.
builder.ProcessFill(new OrderEvent(1, symbol, time.AddMinutes(1),
OrderStatus.Filled, OrderDirection.Buy, 300m, 0m, commission), 1m, 1m);
builder.ProcessFill(new OrderEvent(2, symbol, time.AddMinutes(2),
OrderStatus.Filled, OrderDirection.Sell, 301m, -2m, noFee), 1m, 0m);
Console.WriteLine(builder.ClosedTrades[0].TotalFees); // actual: 0; expected: 1
Verified with the QuantConnect.Common assembly built from master (0b5c3db88): the first closed trade has TotalFees = 0 for FillToFill, FlatToFlat, and FlatToReduced. The same missing commission remains with the zero-quantity statistics guards. It is not caused by those guards: the existing first-event fee cache already discarded it.
Expected result
Trade reconstruction must retain genuine commissions reported after an order's first execution, without inventing an execution or treating a status-only event's price as a market-price update. Existing protection against duplicate commission reporting must be preserved.
Suggestion: separate commission accounting from execution/price processing and define how incremental versus repeated order fees are handled. Add regression coverage for deferred commission, including a status-only completion after a partial fill.
Impact is limited to trade fee statistics; this reproduction does not imply missing portfolio cash charges.
- 主要语言
- C#
- 星标
- 22.6k
- 派生
- 5.4k
- 平均合并
- 11 小时 39 分钟
- 30 天内合并 PR
- 104
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
QuantConnect/Lean 的其他 Issue
-
priority:p2
难度 2/5 1-3 小时 新手友好度 72/100
QuantConnect/Lean#10216 ·
维护者通常 1 天内回复
-
priority:p2
难度 2/5 1-3 小时 新手友好度 78/100
QuantConnect/Lean#10206 ·
维护者通常 1 天内回复
-
priority:p2
难度 2/5 1-3 小时 新手友好度 85/100
QuantConnect/Lean#10199 ·
维护者通常 1 天内回复
-
priority:p2
难度 2/5 1-3 小时 新手友好度 76/100
QuantConnect/Lean#10198 ·
维护者通常 1 天内回复
-
priority:p2
难度 2/5 1-3 小时 新手友好度 78/100
QuantConnect/Lean#10197 ·
维护者通常 1 天内回复
查看 QuantConnect/Lean 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
dotnet-outdated/dotnet-outdated#871 ·
维护者通常 1 天内回复
-
triage/untriaged
难度 2/5 1-3 小时 新手友好度 78/100
unoplatform/uno#26676 ·
维护者通常 1 天内回复
-
.NET bug
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 62/100
jhaizhou-ops/S2Arm#2177 · 3 条评论 ·
维护者通常 1 天内回复
-
area-CodeGen-coreclr untriaged
难度 2/5 1-3 小时 新手友好度 65/100
dotnet/runtime#138181 · 1 条评论 ·
维护者通常 1 天内回复