Fix future-price leakage in indicator aggregate fallbacks - #486
Open
Aarav-Nagar wants to merge 1 commit into
Open
Aarav-Nagar wants to merge 1 commit into
Aarav-Nagar wants to merge 1 commit into
Conversation
Contributor
|
@Aarav-Nagar is attempting to deploy a commit to the allan-feng's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
TechnicalIndicators.calculate_indicatorsreceives the complete backtest frame. Its short-history and library-failure fallbacks broadcast the full frame's close mean/min/max to earlier rows, allowing later prices to change earlier indicators.For closes
[100, 110, 90], the SMA fallback was[100, 100, 100]; at the second bar, only 100 and 110 are available, so the fallback should be 105.Change
docs/indicator-lookahead-regression.md.The test approach is inspired by Freqtrade lookahead-analysis. This is original ATL test code, not a port of Freqtrade's CLI: timestamps and frame length are fixed, future prices are perturbed, and earlier indicator values must remain exactly equal.
Validation
Against original
features.pyat85c02d5f09670b3a39405346a5d4b17f78413ff2, the new tests produce 49 failed, 3 passed. With the fix, all 52 are included in this passing run:277 passed, 2 skipped locally on Windows/Python 3.12 with the pinned project dependencies.
pip checkandgit diff --checkpass. The full backend suite is left to repository CI.This does not prove platform-wide absence of lookahead or restart equivalence, and no portfolio-return improvement is claimed. Extending a frame across the existing minimum-history thresholds can still switch fallback values to library warm-up NaNs; a uniform readiness policy is a separate change.