Skip to content

Fix Alpha calculation when target and reference sample counts diverge (#9936) - #9947

Open
abhi-byte62 wants to merge 1 commit into
QuantConnect:masterfrom
abhi-byte62:bug-9936-alpha-divergent-samples
Open

abhi-byte62 wants to merge 1 commit into
QuantConnect:masterfrom
abhi-byte62:bug-9936-alpha-divergent-samples

Conversation

@abhi-byte62

Copy link
Copy Markdown
Contributor

Fixes #9936

Summary

The Alpha indicator 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 and Alpha remains frozen at 0 even after all sub-indicators (_beta, _targetROC, _referenceROC) are ready and receiving timestamp-matched data.

Changes

  • In Indicators/Alpha.cs, track observation timestamps (_targetEndTime, _referenceEndTime) and evaluate ComputeAlpha() when both observations are aligned for the current time step (AreObservationsAligned()), rather than checking equal lifetime sample counts.
  • Add support for cross-timezone observation alignment (e.g. America/New_York vs UTC) by resolving exchange time zones from MarketHoursDatabase.
  • Avoid redundant recalculations on duplicate updates with _lastComputedEndTime.
  • In Tests/Indicators/AlphaIndicatorTests.cs:
    • Fix copy-pasted Beta instantiation in IndicatorShouldHaveSymbolAfterUpdates.
    • Add regression test AlphaCalculatesWhenSampleCountsDiverge reproducing the issue (2 leading reference bars, followed by 5 timestamp-matched pairs).
    • Add regression test AlphaCalculatesWithDifferentTimeZonesWhenSampleCountsDiverge.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alpha freezes when target/reference sample counts diverge

1 participant