Repository navigation
Fix Alpha calculation when target and reference sample counts diverge (#9936) - #9947
Open
abhi-byte62 wants to merge 1 commit into
Open
abhi-byte62 wants to merge 1 commit into
abhi-byte62 wants to merge 1 commit into
Conversation
…QuantConnect#9936) Fixes QuantConnect#9936 Alpha previously required _targetROC.Samples == _referenceROC.Samples before recalculating. When one symbol receives more data points (e.g. earlier IPO date, longer benchmark history, or missing/halted bars on the other asset), the two lifetime sample counters permanently diverge, causing Alpha to freeze at 0 even when all components are ready and timestamp-matched data arrives. - Synchronize Alpha calculations by checking observation timestamp alignment rather than lifetime sample counts, supporting both identical timestamps and resolution-adjusted UTC cross-timezone feeds. - Prevent duplicate calculation on redundant updates for the same bar. - Fix copy-pasted Beta instantiation in AlphaIndicatorTests.IndicatorShouldHaveSymbolAfterUpdates. - Add regression tests covering sample count divergence and multi-timezone feeds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9936
Summary
The
Alphaindicator previously gated recalculation on_targetROC.Samples == _referenceROC.Samples. When one symbol receives more data points (e.g. earlier IPO date, longer benchmark history, warm-up differences, or missing/halted bars), these lifetime sample counters permanently diverge. As a result,ComputeAlpha()is never called again andAlpharemains frozen at 0 even after all sub-indicators (_beta,_targetROC,_referenceROC) are ready and receiving timestamp-matched data.Changes
Indicators/Alpha.cs, track observation timestamps (_targetEndTime,_referenceEndTime) and evaluateComputeAlpha()when both observations are aligned for the current time step (AreObservationsAligned()), rather than checking equal lifetime sample counts.MarketHoursDatabase._lastComputedEndTime.Tests/Indicators/AlphaIndicatorTests.cs:Betainstantiation inIndicatorShouldHaveSymbolAfterUpdates.AlphaCalculatesWhenSampleCountsDivergereproducing the issue (2 leading reference bars, followed by 5 timestamp-matched pairs).AlphaCalculatesWithDifferentTimeZonesWhenSampleCountsDiverge.