Skip to content

Fix future-price leakage in indicator aggregate fallbacks - #486

Open
Aarav-Nagar wants to merge 1 commit into
Open-Finance-Lab:mainfrom
Aarav-Nagar:codex/indicator-lookahead-fallbacks
Open

Aarav-Nagar wants to merge 1 commit into
Open-Finance-Lab:mainfrom
Aarav-Nagar:codex/indicator-lookahead-fallbacks

Conversation

@Aarav-Nagar

Copy link
Copy Markdown

Problem

TechnicalIndicators.calculate_indicators receives 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

  • Use expanding means and extrema through each row for aggregate fallbacks, including the exception handler.
  • Preserve normal pandas-ta calculations, their warm-up NaNs, and existing neutral defaults. These running values remain fallback approximations, not fully initialized indicators.
  • Add 52 synthetic regression cases covering future-price perturbations, indicator-length boundaries, missing library results/columns, early and late library exceptions, explicit expected fallback values, and unchanged normal library outputs.
  • Document reproduction and scope in 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.py at 85c02d5f09670b3a39405346a5d4b17f78413ff2, the new tests produce 49 failed, 3 passed. With the fix, all 52 are included in this passing run:

python -m pytest dashboard/backend/tests/backtesting dashboard/backend/tests/test_market_data_store.py dashboard/backend/tests/domain/backtesting/test_external_run_service_move.py --timeout=180 -q --tb=short

277 passed, 2 skipped locally on Windows/Python 3.12 with the pinned project dependencies. pip check and git diff --check pass. 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.

@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown
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.

@YangletLiu
YangletLiu requested a review from FlyM1ss September 19, 2026 07:04
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.

1 participant