Skip to content

Fix look-ahead bias in swing_highs_lows#103

Open
atharvajoshi01 wants to merge 1 commit intojoshyattridge:masterfrom
atharvajoshi01:fix/101-lookahead-bias-swing-highs-lows
Open

Fix look-ahead bias in swing_highs_lows#103
atharvajoshi01 wants to merge 1 commit intojoshyattridge:masterfrom
atharvajoshi01:fix/101-lookahead-bias-swing-highs-lows

Conversation

@atharvajoshi01
Copy link
Copy Markdown

Fixes #101.

The centered window in swing_highs_lows() used shift(-(swing_length // 2)) which pulls in future bar data. This inflates backtest results significantly (as reported: PF 7.32 vs 1.82 without bias).

Replaced with a confirm-bars approach:

  • Candidate bar must be the extreme (highest high / lowest low) in the past lookback window
  • Confirmed by confirm_bars subsequent bars all being less extreme
  • No future data is used at any point

The deduplication logic (removing consecutive same-direction swings) and boundary handling are unchanged.

The centered window approach used shift(-(swing_length // 2))
which peeks into future bars, inflating backtest results.

Replaced with a confirm-bars method: candidate bar must be the
extreme in the past lookback window, then confirmed by subsequent
bars all being less extreme. No future data is used.
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.

Look-ahead bias in swing_highs_lows() — backtest results are inflated

1 participant