IndicatorHistory can feed quote bars where the live indicator gets trade bars

已关闭
#10,141 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@quantconnect-kronos 已经在做这个了。

开始于 2026年11月18日。

  • #10205 来自 @quantconnect-kronos —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
50/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
csharp
领域
data

调研方向

Start in Algorithm/QCAlgorithm.Indicators.cs at the IndicatorHistory overload that takes a dataType of null, then follow it into Common/Data/SliceExtensions.cs (PushThrough). Compare with how RegisterIndicator picks the data type it consolidates, and with Slice.CreateDynamicDataDictionary and SymbolData.GetData(). Done when the reproduction slices (trade close 100+i, quote close 200+i) feed the indicator trade bars, so the history matches the live values.

由索引模型根据 Issue 内容生成。

描述

priority:p2
What happens

IndicatorHistory can update an indicator with quote bars where the same indicator, registered for live updates, gets trade bars. Its values then differ from the live ones for the same period.

When no data type is given (dataType == null), IndicatorHistory pushes each slice through SliceExtensions.PushThrough, which hands the indicator slice[symbol]. A slice's value for a symbol is the type of the last default-type datum added for it (Slice.CreateDynamicDataDictionary, SymbolData.GetData()). For a security with both trade and quote data, such as a future, that can be a QuoteBar. Meanwhile RegisterIndicator consolidates trade bars for the same subscription.

Reproduction

A slice holding a TradeBar (close 100) and a QuoteBar (close 200) for one future symbol, three hours in a row:

var algorithm = new AlgorithmStub();
var symbol = Symbol.CreateFuture("ES", Market.CME, new DateTime(2024, 3, 15));
var slices = Enumerable.Range(0, 3).Select(i =>
{
    var time = new DateTime(2024, 1, 2, 10 + i, 0, 0);
    var trade = new TradeBar(time, symbol, 100 + i, 100 + i, 100 + i, 100 + i, 10, TimeSpan.FromHours(1));
    var quote = new QuoteBar(time, symbol, new Bar(200 + i, 200 + i, 200 + i, 200 + i), 1,
        new Bar(200 + i, 200 + i, 200 + i, 200 + i), 1, TimeSpan.FromHours(1));
    return new Slice(time.AddHours(1), new List<BaseData> { trade, quote }, time.AddHours(1));
}).ToList();

var rows = algorithm.IndicatorHistory(new SimpleMovingAverage(1), slices).Current;
// rows: 200, 201, 202 (the quote closes); an indicator taking IBaseData receives the QuoteBar objects

With real data, the history of an indicator over hourly continuous futures (ES, GC, CL) in January 2024 had a few rows computed from quote closes. At 2024-01-02 16:00 New York, ES's 1-hour rate of change in the history was 5331.950 / 5311.905 − 1 (quote closes), while the live indicator got 5332.089 / 5311.765 − 1 (trade closes). The live values and a replay of the same history's trade bars agree with each other.

Where
  • QCAlgorithm.IndicatorHistory(IndicatorBase<T>, IEnumerable<Slice>, Action<IBaseData>, Type), Algorithm/QCAlgorithm.Indicators.cs
  • SliceExtensions.PushThrough(IEnumerable<Slice>, Action<BaseData>, Type), Common/Data/SliceExtensions.cs
What a fix must achieve

IndicatorHistory updates an indicator with the same data type that RegisterIndicator would consolidate for it, so history and live values agree. A suggestion only: resolve the data type from the subscription when the selector doesn't imply one.

主要语言
C#
星标
22.6k
派生
5.4k
平均合并
11 小时 39 分钟
30 天内合并 PR
104

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

QuantConnect/Lean 的其他 Issue

查看 QuantConnect/Lean 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。