Skip to content
LeetQuant
QT09 Trading Signals and Systematic Strategies

QT09 · Trading Signals and Systematic Strategies · Lesson 3 of 4

Backtesting Intuition

What a backtest actually estimates, look-ahead and survivorship bias, in- and out-of-sample testing, the standard error of a Sharpe ratio, and how many trials inflate the best result.

17 min

Objective

Traders are asked to judge backtests quickly: "Here is a Sharpe of 2 over five years. Do you believe it?" You should be able to say what the number estimates, list the biases that inflate it, put an error bar on it in your head, and ask how many things were tried before this one.

What a backtest estimates

A backtest replays a fixed rule on historical data and reports the P&L it would have produced. Treat it as one noisy draw of the strategy's performance under three assumptions:

  1. Information. Every input was known at the time the trade was placed.
  2. Execution. You could have traded at the assumed prices, in the assumed size, at the assumed cost, without moving the market.
  3. Stationarity. The future resembles the sample enough for the average to carry over.

Even when all three hold, the backtest Sharpe ratio is an estimate with a wide standard error. When they fail, it is biased, nearly always upward.

Look-ahead bias

Using information that was not available at decision time. Common forms:

  • Normalising or fitting with full-sample statistics (mean, volatility, regression coefficients, PCA loadings).
  • Using today's close to decide a trade executed at today's close.
  • Using revised data (GDP, earnings restatements) instead of the first-released value; using an announcement timestamped by date when it came out after the close.
  • Building the universe from today's index members.

The rule: a signal computed with data up to time tt trades at a price after tt. In code, that is one lag, applied in exactly one place.

Worked example

one missing lag

Simulate ten years of daily returns with no predictability at all. Trade a momentum rule (long if the return was positive, short if negative) once with the signal aligned to the same day's return and once with the correct one-day lag. What Sharpe ratios do you get, and why is the first so large?

Show solution
import random, statistics as st

random.seed(0)
rets = [random.gauss(0, 0.01) for _ in range(2520)]  # 10 years, no edge

def sharpe(pnl):
    return st.mean(pnl) / st.stdev(pnl) * 252 ** 0.5

# Signal: sign of the day's return (a momentum rule).
signal = [1 if r > 0 else -1 for r in rets]

# Wrong: trade today's return with today's signal.
cheat = [s * r for s, r in zip(signal, rets)]
# Right: yesterday's signal earns today's return.
honest = [s * r for s, r in zip(signal[:-1], rets[1:])]

print(f"look-ahead Sharpe: {sharpe(cheat):.1f}")
print(f"honest Sharpe:     {sharpe(honest):.2f}")

This prints a look-ahead Sharpe of 20.720.7 and an honest Sharpe of −0.47-0.47.

The misaligned version earns ∣rt∣|r_t| every day. For normal returns E∣r∣=σ2/π≈0.80σ\mathbb{E}|r| = \sigma\sqrt{2/\pi} \approx 0.80\sigma and sd⁡∣r∣=σ1−2/π≈0.60σ\operatorname{sd}|r| = \sigma\sqrt{1 - 2/\pi} \approx 0.60\sigma, so its daily Sharpe is about 1.321.32 and the annualised one is 1.32252≈211.32\sqrt{252} \approx 21, matching the simulation. The honest figure is noise: with ten years of data the standard error of an annual Sharpe is about 1/10≈0.321/\sqrt{10} \approx 0.32, so −0.47-0.47 is within 1.5 standard errors of zero. Any backtest Sharpe above about 3 on daily data deserves a hunt for a missing lag before anything else.

Survivorship bias

Testing only on assets that exist today drops the ones that were delisted, went bankrupt or were acquired. The dropped names are disproportionately the ones that collapsed, so returns are overstated. The damage is largest for strategies that buy losers: value, short-term reversal, distressed and small-cap strategies. A reversal backtest on today's index members buys stocks that fell and, by construction, never went to zero. The fix is a point-in-time universe including dead companies, with their delisting returns.

In sample and out of sample

Everything chosen while looking at the data (signal definition, lookback, thresholds, universe, the decision to keep the idea at all) is fitted to that data. Performance on it is in sample and is biased upward. Honest estimates need data that played no part in any choice:

  • Hold-out period: reserve the last few years and look once.
  • Walk-forward: fit on data up to tt, test on the next block, roll forward, and report only the stitched test blocks.
  • Different assets: a signal designed on US equities tested on European equities.

Expect the out-of-sample Sharpe ratio to be lower; a ratio of out-of-sample to in-sample Sharpe of a half is common, and a large drop is information about overfitting.

The standard error of a Sharpe ratio

With TT i.i.d. normal returns and true per-period Sharpe ratio SR\text{SR}, the estimated per-period Sharpe ratio has standard error (Lo, 2002)

SE⁡(SR^)≈1+12SR2T.\operatorname{SE}(\widehat{\text{SR}}) \approx \sqrt{\frac{1 + \tfrac12 \text{SR}^2}{T}} .

With daily data the per-period SR is small, so the numerator is close to 1 and the annualised standard error is roughly 1/years1/\sqrt{\text{years}}. That one fact settles many interview questions: a Sharpe of 1 needs about 4 years to reach t≈2t \approx 2. Fat tails and autocorrelation make the true error bar wider than this formula.

Many trials

Selecting the best of NN backtests is a maximum of NN noisy estimates. For independent strategies with no edge, each annualised Sharpe is roughly N(0,1/years)N(0, 1/\text{years}), and the expected best is E[max⁡NZ]/years\mathbb{E}[\max_N Z] / \sqrt{\text{years}}, where E[max⁡NZ]≈1.87,2.25,2.51\mathbb{E}[\max_N Z] \approx 1.87, 2.25, 2.51 for N=20,50,100N = 20, 50, 100. Correlated trials (neighbouring parameter values) count as fewer independent ones, but the effective number is rarely as small as one. The honest questions are: how many variants were tried, and does the reported Sharpe clear the luck benchmark? Deflated-Sharpe and haircut methods formalise this; Bonferroni-style thresholds such as t>3t > 3 are the blunt version.

Finally, report drawdowns alongside the Sharpe ratio. Maximum drawdown is path-dependent, grows with the length of the sample, and is the number that gets strategies switched off in practice.

Worked example

putting an error bar on a backtest

A researcher shows a strategy with an annualised Sharpe ratio of 1.5 on three years of daily data. (a) What is the standard error of the annualised Sharpe ratio, and the t-statistic? (b) The researcher mentions trying 20 parameter settings, and the best one had Sharpe 1.2 on four years of data. How does that compare with luck?

Show solution

(a) The daily Sharpe is 1.5/252≈0.09451.5/\sqrt{252} \approx 0.0945, and T=756T = 756:

SE⁡daily=1+0.09452/2756≈0.0365,SE⁡annual=0.0365252≈0.58.\operatorname{SE}_{\text{daily}} = \sqrt{\frac{1 + 0.0945^2/2}{756}} \approx 0.0365, \qquad \operatorname{SE}_{\text{annual}} = 0.0365\sqrt{252} \approx 0.58 .

So the estimate is 1.5±0.581.5 \pm 0.58 and t≈2.6t \approx 2.6. A rough 95% interval (two standard errors) is 0.30.3 to 2.72.7: the data rule out zero but barely pin down the size. (The shortcut 1/3≈0.581/\sqrt{3} \approx 0.58 gives the same answer.)

(b) With four years each no-edge Sharpe is roughly N(0,0.52)N(0, 0.5^2). The expected best of 20 independent ones is 1.87×0.5≈0.931.87 \times 0.5 \approx 0.93. The reported 1.21.2 is only about half a standard error above what pure luck delivers, so it is weak evidence of an edge, and the out-of-sample Sharpe of the selected setting should be expected to fall well below 1.21.2.

Knowledge check

Roughly how many years of daily data are needed for a strategy with a true annualised Sharpe ratio of 1 to show a t-statistic of about 2?

Knowledge check

A short-term reversal strategy (buy last week's biggest losers) is backtested on the current members of an index over the past 20 years. Which bias is most clearly present, and in which direction?

Knowledge check

You test 50 unrelated strategies, none with a real edge, each on one year of data. What is roughly the best annualised Sharpe ratio you should expect to see?

Key takeaways

  • A backtest is one noisy sample under assumptions about information, execution and stationarity; violations bias it upward.
  • Look-ahead: lag the signal once and never use full-sample statistics. A daily Sharpe above about 3 usually means a missing lag.
  • Survivorship bias flatters loser-buying strategies most; use point-in-time universes with delisting returns.
  • SE⁡(SR^)≈(1+SR2/2)/T\operatorname{SE}(\widehat{\text{SR}}) \approx \sqrt{(1 + \text{SR}^2/2)/T} per period, about 1/years1/\sqrt{\text{years}} annualised for daily data.
  • Always ask how many variants were tried; compare the result with the expected best of that many lucky draws.

Practice problems

Finished reading?

Answer the 3 knowledge checks to complete this lesson (0 done).