Backtesting
Look-ahead bias: the quiet way backtests lie
· 1 min read
Look-ahead bias means your simulation used information that did not exist yet when the trade would have been placed. It is the most common reason a backtest looks better than reality, and it is usually an accident.
01
The classic mistake
You compute a signal from today's closing price and then earn today's return with it. In real life you only know the close after the market closes, so the earliest you can act on it is tomorrow.
python
signal = (prices > prices.rolling(50).mean()).astype(int)
# Wrong: uses today's close to earn today's return
bad = (signal * returns).mean()
# Right: trade on the next bar
good = (signal.shift(1) * returns).mean()02
Other places it hides
- Using restated financial data instead of what was published at the time.
- Normalising with the mean and standard deviation of the whole sample, not just the past.
- Choosing today's index constituents for a historical test, which also introduces survivorship bias.
A good habit is to ask of every column in your dataset: on the morning of this date, could I have known this?
Educational content only, not investment advice.