Skip to main content
Yuming Yang

Notes · · backtesting · bias

How much Sharpe does a little lookahead buy?

If a backtest engine lets a strategy see tomorrow's return on a fraction p of days, a strategy with no edge earns an annualized Sharpe of about 12.7p. A 5% leak is within the noise of an honest two-year backtest.

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, rt∼N(0,σ2)r_t \sim \mathcal{N}(0, \sigma^2), so no strategy has a real edge. The strategy holds the sign of today's return for one day:

st=sign⁡(rt),Xt+1=st rt+1.s_t = \operatorname{sign}(r_t), \qquad X_{t+1} = s_t \, r_{t+1}.

A correct engine computes sts_t from information up to the close of day tt. The buggy engine, on a random fraction pp of days chosen independently of returns, computes the signal from tomorrow's return instead, so st=sign⁡(rt+1)s_t = \operatorname{sign}(r_{t+1}) on those days.

The calculation

On a leaked day the strategy earns ∣rt+1∣|r_{t+1}|. On a clean day it earns sign⁡(rt) rt+1\operatorname{sign}(r_t)\, r_{t+1}, which has mean zero because rtr_t and rt+1r_{t+1} are independent. So

E[X]=p E∣r∣=p σ2/π.\mathbb{E}[X] = p\,\mathbb{E}|r| = p\,\sigma\sqrt{2/\pi}.

In both cases X2=rt+12X^2 = r_{t+1}^2, so E[X2]=σ2\mathbb{E}[X^2] = \sigma^2 and Var⁡(X)=σ2(1−2p2/π)\operatorname{Var}(X) = \sigma^2\left(1 - 2p^2/\pi\right). The annualized Sharpe ratio is

SR=252  p2/π1−2p2/π≈12.7 pfor small p.\begin{aligned} \mathrm{SR} &= \sqrt{252}\;\frac{p\sqrt{2/\pi}}{\sqrt{1 - 2p^2/\pi}} \\ &\approx 12.7\,p \quad \text{for small } p. \end{aligned}

σ\sigma cancels: the inflation does not depend on volatility.

What the formula gives

Leak share ppAnnualized Sharpe ratio
0%0.00
5%0.63
10%1.27
20%2.57
30%3.91

The small-pp line is close all the way to 30%: the exact value there is 3.91, against about 3.8 from 12.7p12.7p.

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 252/504≈0.71\sqrt{252/504} \approx 0.71. Treating it as normal, an honest strategy reaches a Sharpe of 0.63 or more with probability about 19% (0.63/0.71≈0.890.63 / 0.71 \approx 0.89 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 tt, record the latest timestamp in the data the strategy received and assert that it is not after tt. 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.

← All notes