A lookahead bug rarely makes a backtest look absurd. More often it makes a mediocre strategy look decent. This note puts a number on that for the simplest case.
Setup
Daily returns are i.i.d. normal, , so no strategy has a real edge. The strategy holds the sign of today's return for one day:
A correct engine computes from information up to the close of day . The buggy engine, on a random fraction of days chosen independently of returns, computes the signal from tomorrow's return instead, so on those days.
The calculation
On a leaked day the strategy earns . On a clean day it earns , which has mean zero because and are independent. So
In both cases , so and . The annualized Sharpe ratio is
cancels: the inflation does not depend on volatility.
What the formula gives
| Leak share | Annualized Sharpe ratio |
|---|---|
| 0% | 0.00 |
| 5% | 0.63 |
| 10% | 1.27 |
| 20% | 2.57 |
| 30% | 3.91 |
The small- line is close all the way to 30%: the exact value there is 3.91, against about 3.8 from .
Why the equity curve will not tell you
Over a two-year backtest (504 days), the sample Sharpe of the honest strategy has a standard deviation of about . Treating it as normal, an honest strategy reaches a Sharpe of 0.63 or more with probability about 19% ( standard deviations), and 1.27 or more with probability about 4% (1.8 standard deviations).
So a 5% leak produces a result that pure luck produces about one time in five, and a 10% leak looks like a good but believable strategy. Looking at performance alone cannot separate them.
What does catch it
Check what the strategy was allowed to see, not how well it did. At every decision time , record the latest timestamp in the data the strategy received and assert that it is not after . This check is deterministic: it fails on the exact bar where the leak happens, whatever the returns were.
That is the probe check for trap T1 (price lookahead) in the Backtest Bias Test Suite, where the same setup is also available as an interactive chart.
Limits of this model
Returns here are i.i.d. normal and the leak is independent of returns. Real leaks are usually systematic, for example filling at the same close the signal was computed on every day, and real returns have fat tails and autocorrelation. The point of the model is the order of magnitude: small, intermittent leaks are enough to manufacture a plausible Sharpe ratio.