Portfolio Margin chart: stream sends an aggregated TOTAL StackedArea series, stored result keeps per-group Bar series

オープン
#10,135 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
1〜2日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
csharp
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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 BacktestResultPacket delta for Portfolio Margin contains exactly one series: TOTAL, SeriesType.StackedArea.
  • The stored result (what backtests/read and the chart read return once the backtest completes) contains the per-group series only: SPY, SeriesType.Bar (and OTHERS when present). There is no TOTAL.

Values match between the two (the single-group case sums to the same numbers), only the shape differs.

Steps to reproduce
  1. Run any backtest that holds one equity for the whole period (for example buy and hold SPY over 2020) on master v18263 or later.
  2. Subscribe to the backtest result packets while it runs and look at results.charts["Portfolio Margin"].series: one series named TOTAL with seriesType 5 (StackedArea).
  3. After Completed, read the stored result's charts["Portfolio Margin"].series: one series named SPY with seriesType 3 (Bar), no TOTAL.
  4. 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

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.
主要言語
C#
スター
22.6k
フォーク
5.4k
平均マージ
11時間 39分
マージ済み PR(30日)
104

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

QuantConnect/Lean のほかの issue

QuantConnect/Lean の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。