Portfolio Margin chart: stream sends an aggregated TOTAL StackedArea series, stored result keeps per-group Bar series
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
The split lives in three places: GetOrAddSeries in Common/Securities/Positions/PortfolioMarginChart.cs, the streaming aggregate call near line 203 of Engine/Results/BacktestingResultHandler.cs, and the final-result filter near line 345 of the same file. Read Chart.Aggregate in Common/Chart.cs to see what the stream sends, then compare it with the final-result path. The issue asks which shape is intended, so a maintainer decision is needed before any change; done means both paths emit the same series set and types, confirmed by a test around the portfolio margin chart.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
The Portfolio Margin chart that a running backtest streams is a different chart from the one stored in the final result. The stream carries a single aggregated TOTAL series of type StackedArea; the stored result keeps one Bar series per position group (for example SPY, plus OTHERS). A client that follows the stream and then loads the stored result therefore shows two different pictures of the same backtest: a continuous area while running, bars per group once finished.
Expected behavior
The streamed Portfolio Margin chart and the stored Portfolio Margin chart have the same series set and series types, so a result viewer renders the same chart during and after the backtest.
Actual behavior
- While the backtest runs, every
BacktestResultPacketdelta forPortfolio Margincontains exactly one series:TOTAL,SeriesType.StackedArea. - The stored result (what
backtests/readand the chart read return once the backtest completes) contains the per-group series only:SPY,SeriesType.Bar(andOTHERSwhen present). There is noTOTAL.
Values match between the two (the single-group case sums to the same numbers), only the shape differs.
Steps to reproduce
- Run any backtest that holds one equity for the whole period (for example buy and hold
SPYover 2020) on master v18263 or later. - Subscribe to the backtest result packets while it runs and look at
results.charts["Portfolio Margin"].series: one series namedTOTALwithseriesType5 (StackedArea). - After
Completed, read the stored result'scharts["Portfolio Margin"].series: one series namedSPYwithseriesType3 (Bar), noTOTAL. - In the VS Code extension or the web terminal, watch the Portfolio Margin panel: a continuous area while streaming, then one bar per daily sample once the final result is loaded.
Where the split happens
PortfolioMarginChart.GetOrAddSeriesbuilds the chart with oneBarseries per position group: https://github.com/QuantConnect/Lean/blob/78de2ccd1/Common/Securities/Positions/PortfolioMarginChart.cs#L117BacktestingResultHandleraggregates the chart only when packing streaming deltas:updates = updates.Aggregate(SeriesType.StackedArea);https://github.com/QuantConnect/Lean/blob/78de2ccd1/Engine/Results/BacktestingResultHandler.cs#L203Chart.Aggregatesums every series into oneTOTALseries of the requested type: https://github.com/QuantConnect/Lean/blob/78de2ccd1/Common/Chart.cs#L201- The final result path only drops single-point series and keeps the per-group
Barseries: https://github.com/QuantConnect/Lean/blob/78de2ccd1/Engine/Results/BacktestingResultHandler.cs#L345
The stream-side aggregate was added in #9011 ("Improve portfolio margin chart").
Evidence from a client run
Streaming packets (first, middle, last), Portfolio Margin series as received by the result viewer:
"TOTAL":{"type":5,"n":11,"first":[1578027600,49.87],"last":[1578891600,49.87]}
"TOTAL":{"type":5,"n":31,"first":[1578978000,49.88],"last":[1581570000,49.88]}
"TOTAL":{"type":5,"n":36,"first":[1605762000,49.89],"last":[1608786000,49.89]}
Chart read of the stored result, at open and again at finish:
"SPY":{"type":3,"unit":"%","n":5,"first":[1578027600,49.87],"last":[1578796298,49.87]}
"SPY":{"type":3,"unit":"%","n":164,"first":[1578027600,49.87],"last":[1609352050,49.89]}
Questions
Which shape is the intended one? Either the stored chart should be aggregated the same way the stream is, or the stream should carry the per-group series, or the difference is intentional and viewers should expect it. Any of the three is fine from the viewer side, as long as it is one of them.
Environment
- Lean master v18263 (2026-11-13), cloud backtest.
- Observed through the QuantConnect VS Code extension's backtest result panel and the web terminal, both of which render streamed packets and the stored result with the same chart code.
- Ngôn ngữ chính
- C#
- Star
- 22.6k
- Fork
- 5.4k
- Merge trung bình
- 11 giờ 39 phút
- Pull request đã merge (30 ngày)
- 104
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của QuantConnect/Lean
-
priority:p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
QuantConnect/Lean#10216 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
priority:p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
QuantConnect/Lean#10206 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
priority:p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
QuantConnect/Lean#10199 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
priority:p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
QuantConnect/Lean#10198 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
priority:p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
QuantConnect/Lean#10197 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của QuantConnect/Lean
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
dotnet-outdated/dotnet-outdated#871 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
triage/untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
unoplatform/uno#26676 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
.NET bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[问题] 导出文件时,提示后面还有1243390911步Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
jhaizhou-ops/S2Arm#2177 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area-CodeGen-coreclr untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotnet/runtime#138181 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày