# 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.

Source: https://learn.tradelabsai.com/research/look-ahead-bias/  
Track: Research and Backtesting · Level: Intermediate · Updated: 2026-10-03  
Publisher: TradeLabs AI (https://tradelabsai.com). Education, not financial advice.  
Cite as: TradeLabs Learn, "Look-Ahead Bias", https://learn.tradelabsai.com/research/look-ahead-bias/

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

| Source | Example |
|---|---|
| Same bar signal and fill | Using today's close to generate a signal and also filling at today's close |
| Restated fundamentals | Using revised earnings that were published months later. See [Point-in-Time and Survivorship-Free Data](https://learn.tradelabsai.com/programming/point-in-time-data/) |
| Reporting lags ignored | Using quarterly results on the quarter end date rather than the filing date |
| Today's index members | Selecting stocks from the current index list for past dates. See [Survivorship and Selection Bias](https://learn.tradelabsai.com/research/survivorship-and-selection-bias/) |
| Full sample normalisation | Scaling data with the mean and standard deviation of the entire history |
| Centred indicators | Moving averages or smoothing that use future values |
| Adjusted prices misuse | Using back adjusted futures levels for absolute price rules. See [Continuous Futures and Back-Adjustment](https://learn.tradelabsai.com/futures/continuous-futures/) |
| Time zone misalignment | Treating a close in one market as known before another market's close. See [Timestamps, Time Zones and Daylight Saving](https://learn.tradelabsai.com/programming/timestamps-and-time-zones/) |
| Bar high and low | Assuming a stop and a target were both possible without knowing which was hit first |

## Examples

**Example: The earnings date trap**
A value strategy ranks stocks by P/E at each month end and buys the cheapest. The backtest uses quarterly earnings dated to the quarter end (31 March), but companies typically report several weeks later. On 31 March, the strategy "knows" earnings it could not have known until late April or May. Shifting fundamentals to their actual filing dates reduces the strategy's annual excess return noticeably, because part of the original return came from trading on earnings surprises before they were announced. See [Fundamental Data](https://learn.tradelabsai.com/alternative-data/fundamental-data/).

**Example: Intrabar ambiguity**
A day trading backtest on 1 minute bars has a stop 10 points below entry and a target 10 points above. One bar's range covers both. The backtest assumes the target was hit first. In reality, without tick data, it is unknown. Assuming the favourable outcome in every ambiguous bar inflates results. A conservative rule assumes the stop was hit first, or uses finer data. See [Fill Models, Partial Fills and Order Queues](https://learn.tradelabsai.com/research/fill-models/).

## 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](https://learn.tradelabsai.com/math/rolling-and-expanding-windows/).
5. **Fit scalers and models on training data only,** then apply them forward. See [Data Leakage](https://learn.tradelabsai.com/research/data-leakage/).
6. **Use event driven backtests** that process data in time order. See [Backtesting Methodology](https://learn.tradelabsai.com/research/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:

```python
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](https://learn.tradelabsai.com/programming/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](https://learn.tradelabsai.com/research/survivorship-and-selection-bias/).

## Continue learning

- Next lesson: [Survivorship and Selection Bias](https://learn.tradelabsai.com/research/survivorship-and-selection-bias/)
- Previous lesson: [Overfitting and Curve Fitting](https://learn.tradelabsai.com/research/overfitting-and-curve-fitting/)
- Related: [Overfitting and Curve Fitting](https://learn.tradelabsai.com/research/overfitting-and-curve-fitting/): Overfitting means a strategy fits noise instead of a real pattern. Learn the warning signs, why it happens, how to measure it and practical ways to avoid it.
- Related: [Data Leakage](https://learn.tradelabsai.com/research/data-leakage/): Data leakage lets information from test data or the future slip into model training. Learn common leaks in trading and machine learning and how to prevent them.
- Related: [Point-in-Time and Survivorship-Free Data](https://learn.tradelabsai.com/programming/point-in-time-data/): Point in time data records what was known on each date, including restated figures and index changes. Learn why it matters and how to build point in time datasets.
- Related: [Survivorship and Selection Bias](https://learn.tradelabsai.com/research/survivorship-and-selection-bias/): Survivorship bias ignores failures; selection bias picks unrepresentative samples. Learn how both inflate backtests, fund returns and advice, and how to fix them.
- Related: [Backtesting Methodology](https://learn.tradelabsai.com/research/backtesting-methodology/): A backtest simulates a strategy on historical data. Learn the steps, the key performance metrics, common biases and a checklist for backtests you can trust.
- Related: [Timestamps, Time Zones and Daylight Saving](https://learn.tradelabsai.com/programming/timestamps-and-time-zones/): Time zone and timestamp errors silently break backtests. Learn UTC storage, daylight saving traps, exchange sessions, event versus receive time and bar labels.
