TradeLabs AILearn

Look-Ahead Bias

Look ahead bias happens when a backtest uses information that was not available at the time. Learn common sources, real examples and how to prevent it in code.

Intermediate3 min readUpdated 3 Oct 2026
Markdown
Lesson 9 of 38

Look ahead bias occurs when a backtest uses information that would not have been known at the moment a trading decision was made. Even a small leak of future information can make a worthless strategy look brilliant, because knowing the future, even slightly, is enormously profitable on paper. It is one of the easiest mistakes to make and one of the hardest to spot, especially in vectorised code where all data is available at once.

Common sources#

SourceExample
Same bar signal and fillUsing today's close to generate a signal and also filling at today's close
Restated fundamentalsUsing revised earnings that were published months later. See Point-in-Time and Survivorship-Free Data
Reporting lags ignoredUsing quarterly results on the quarter end date rather than the filing date
Today's index membersSelecting stocks from the current index list for past dates. See Survivorship and Selection Bias
Full sample normalisationScaling data with the mean and standard deviation of the entire history
Centred indicatorsMoving averages or smoothing that use future values
Adjusted prices misuseUsing back adjusted futures levels for absolute price rules. See Continuous Futures and Back-Adjustment
Time zone misalignmentTreating a close in one market as known before another market's close. See Timestamps, Time Zones and Daylight Saving
Bar high and lowAssuming a stop and a target were both possible without knowing which was hit first

Examples#

How to prevent look ahead bias#

  1. Lag signals: trade on the next bar's open or later after a signal from a completed bar.
  2. Use point in time data with actual publication dates.
  3. Use historical index memberships.
  4. Compute all indicators with trailing windows only. See Rolling and Expanding Windows.
  5. Fit scalers and models on training data only, then apply them forward. See Data Leakage.
  6. Use event driven backtests that process data in time order. See Backtesting Methodology.
  7. Write tests: for example, shift data one bar into the future and confirm results change; if they do not, the code may already be using future data.

A quick sanity check#

If a strategy's backtest looks too good, try delaying all signals by one extra bar. Genuine edges usually weaken a little; strategies driven by look ahead bias often collapse completely. Also check performance on the exact day of the signal: returns concentrated on the same bar as the signal are a red flag.

In code#

In pandas, shift(1) moves data forward one row so today's decision uses yesterday's data:

df["signal"] = (df["close"] > df["close"].rolling(20).mean()).astype(int)
df["position"] = df["signal"].shift(1)   # act on the next bar
df["strategy_return"] = df["position"] * df["close"].pct_change()

Forgetting the shift is one of the most common bugs. See NumPy and Pandas for Traders.

Frequently asked questions#

What is look ahead bias?#

Using information in a backtest that would not have been available at the time of the trading decision, making results unrealistically good.

How do I avoid look ahead bias?#

Lag signals, use point in time data with real publication dates, compute indicators with trailing windows and fit models only on past data.

How can I detect look ahead bias in my backtest?#

Delay signals by an extra bar and see whether performance collapses, and check whether returns cluster on the same bar as the signal.

Next, learn about missing failures in data in Survivorship and Selection Bias.

Check your understanding

3 quick questions on this lesson. Get them all right to finish it.

Turn on JavaScript to take the quiz.

Finished this lesson?Sign in to save your progress across devices.
Next lessonSurvivorship and Selection BiasSurvivorship bias ignores failures; selection bias picks unrepresentative samples. Learn how both inflate backtests, fund returns and advice, and how to fix them.

Mentioned in