Skip to content
LeetQuant
QR08 Backtesting and Research Design

QR08 · Backtesting and Research Design · Lesson 2 of 6

In-Sample and Out-of-Sample Testing

How to split data, why holdouts must be touched once, why the selected strategy's Sharpe ratio falls out of sample, and how to compute the expected maximum Sharpe ratio from many trials.

16 min

Objective

You should be able to design a train/validation/holdout split for a time series, explain why the out-of-sample Sharpe ratio of a selected strategy is predictably lower than its in-sample value, quantify that drop under a simple model, and compute the luck benchmark for the best of NN trials.

Splitting a time series

Three roles, in time order:

  • Training (in sample): fit parameters, explore, iterate freely.
  • Validation: choose between the candidates the training stage produced. Choosing is fitting, so the validation score of the winner is also biased upward.
  • Holdout (test): run once, on the single chosen specification, and report that number.

Splits are chronological, not random: random splits put tomorrow's data in the training set and leak autocorrelated information. A gap between blocks is needed when labels overlap (see Walk-Forward Validation). Alternatives to a time holdout are different assets (design on US equities, test on Europe) and live paper trading, the only holdout that cannot be peeked at.

Holdout discipline

A holdout is out of sample only until you react to it. Look, adjust, and look again, and it has become validation data. Rules that work in practice:

  • Decide the success criterion before the first look.
  • If the holdout result fails and you revise, the revised strategy needs new untouched data; the old holdout is now in sample.
  • Count holdout looks in the research log like any other trial.

The holdout length is a trade-off. A Sharpe estimate from YY years has standard error about 1/Y1/\sqrt{Y}, so a 2-year holdout of a strategy with true Sharpe 1 has an expected t-statistic of 2≈1.41\sqrt2 \approx 1.41 and a one-sided 5% test detects it only about 41% of the time. A short holdout can catch a disaster but rarely confirms a modest edge, which is why the evidence from the mechanism and the trial count still matters.

Why the winner degrades out of sample

Let each candidate strategy ii have a true annualised Sharpe μi\mu_i, and let the in-sample estimate be S^i=μi+εi\hat S_i = \mu_i + \varepsilon_i with εi∼N(0,σ2)\varepsilon_i \sim N(0, \sigma^2), σ2=1/YIS\sigma^2 = 1/Y_{\text{IS}}. Suppose true Sharpes across ideas are spread as μi∼N(0,τ2)\mu_i \sim N(0, \tau^2). Then (μi,S^i)(\mu_i, \hat S_i) are jointly normal and

E[μi∣S^i]=τ2τ2+σ2 S^i.\mathbb{E}[\mu_i \mid \hat S_i] = \frac{\tau^2}{\tau^2 + \sigma^2}\,\hat S_i .

The out-of-sample estimate has fresh noise with mean zero, so its expectation is E[μi∣S^i]\mathbb{E}[\mu_i \mid \hat S_i]. Two consequences:

  1. The expected out-of-sample Sharpe is the in-sample Sharpe times a shrinkage factor τ2/(τ2+σ2)<1\tau^2/(\tau^2 + \sigma^2) < 1. Selecting the in-sample winner does not change this factor, because the posterior depends only on the winner's own estimate; selection just guarantees that you are looking at a large S^i\hat S_i, which is mostly noise.
  2. If no idea has an edge (τ=0\tau = 0) the factor is zero: the winner's expected out-of-sample Sharpe is zero however impressive its in-sample number.

A ratio of out-of-sample to in-sample Sharpe well below one is therefore the normal outcome of selection, not a sign that "the market changed". It becomes a warning when it is far below what this calculation predicts.

The expected maximum Sharpe from many trials

If all NN trials have no edge and independent estimates with standard deviation σS\sigma_S, the best has expectation σS E[max⁡NZ]\sigma_S\,\mathbb{E}[\max_N Z]. Exact values of E[max⁡NZ]\mathbb{E}[\max_N Z]:

NN1020501001000
E[max⁡NZ]\mathbb{E}[\max_N Z]1.541.872.252.513.24

Bailey and López de Prado give a closed-form approximation, with γ≈0.5772\gamma \approx 0.5772 the Euler–Mascheroni constant:

E[max⁡NZ]≈(1−γ) Φ−1 ⁣(1−1N)+γ Φ−1 ⁣(1−1Ne),\mathbb{E}[\max_N Z] \approx (1 - \gamma)\,\Phi^{-1}\!\left(1 - \frac1N\right) + \gamma\,\Phi^{-1}\!\left(1 - \frac{1}{N e}\right),

which gives 1.581.58, 2.532.53 and 3.263.26 for N=10,100,1000N = 10, 100, 1000, within about 0.040.04 of the exact values. The cruder 2ln⁡N\sqrt{2\ln N} overstates it (3.03 at N=100N = 100). In practice σS\sigma_S is estimated as the cross-sectional standard deviation of the trials' Sharpe ratios and NN is an effective number of independent trials, smaller than the raw count when variants are correlated.

Worked example

the in-sample winner, out of sample

You test 100 ideas, each on 5 years in sample and 5 years out of sample. True annualised Sharpe ratios across ideas are N(0,0.32)N(0, 0.3^2). (a) What is the expected in-sample Sharpe of the winner? (b) What is its expected out-of-sample Sharpe? Check by simulation.

Show solution

Variances. σ2=1/5=0.2\sigma^2 = 1/5 = 0.2 and τ2=0.09\tau^2 = 0.09, so the in-sample estimates are N(0,0.29)N(0, 0.29) with standard deviation 0.5390.539.

(a) The winner is the maximum of 100 such draws: 0.539×2.51≈1.350.539 \times 2.51 \approx 1.35.

(b) The shrinkage factor is 0.09/0.29≈0.310.09/0.29 \approx 0.31, so the expected out-of-sample Sharpe is 0.31×1.35≈0.420.31 \times 1.35 \approx 0.42. The idea may be genuinely good, but two thirds of its in-sample Sharpe was luck.

import random, statistics as st

random.seed(1)
TAU, YEARS, N, REPS = 0.3, 5, 100, 2000
se = 1 / YEARS ** 0.5            # s.e. of an annualised Sharpe estimate

best_is, best_oos = [], []
for _ in range(REPS):
    true = [random.gauss(0, TAU) for _ in range(N)]
    is_ = [t + random.gauss(0, se) for t in true]
    oos = [t + random.gauss(0, se) for t in true]
    k = max(range(N), key=is_.__getitem__)       # pick the in-sample winner
    best_is.append(is_[k])
    best_oos.append(oos[k])

print(f"winner in sample:     {st.mean(best_is):.2f}")
print(f"winner out of sample: {st.mean(best_oos):.2f}")
print(f"ratio:                {st.mean(best_oos) / st.mean(best_is):.2f}")

This prints 1.351.35, 0.420.42 and a ratio of 0.320.32, matching the calculation.

Worked example

is the best of 1000 backtests interesting?

An automated search runs 1000 signal variants on 3 years of daily data. The best has an annualised Sharpe ratio of 2.1. The cross-sectional standard deviation of the 1000 Sharpe ratios is 0.60. Is the winner interesting?

Show solution

Benchmark from the trials themselves. Under the null that no variant has an edge, the best of 1000 is about 0.60×3.24≈1.940.60 \times 3.24 \approx 1.94.

Benchmark from theory. Three years of daily data give a standard error of 1/3≈0.5771/\sqrt3 \approx 0.577, close to the observed dispersion of 0.600.60 (the slightly larger spread allows a little true variation). This gives 0.577×3.24≈1.870.577 \times 3.24 \approx 1.87.

Verdict. The winner's 2.1 is only about 0.160.16 to 0.230.23 above the luck benchmark, well under half a standard error of 0.5770.577. Its naive t-statistic of 2.13≈3.62.1\sqrt3 \approx 3.6 looks spectacular and means almost nothing here. Before spending holdout data on it, require a mechanism and look at whether neighbouring variants also work.

Knowledge check

True annualised Sharpe ratios across your ideas are spread as N(0,0.52)N(0, 0.5^2) and each in-sample test uses 4 years of daily data. Your best idea shows an in-sample Sharpe of 1.4. What is its expected out-of-sample Sharpe?

Knowledge check

A strategy has a true annualised Sharpe ratio of 1. You reserve a 2-year daily holdout and require a one-sided 5% test to pass. Roughly how often does the holdout confirm the strategy?

Knowledge check

Your holdout result was poor, so you changed the stop-loss rule and reran on the same holdout, which now looks good. What is the status of that holdout?

Key takeaways

  • Split chronologically into training, validation and a holdout used once on one specification.
  • A holdout you react to becomes in sample; revisions need fresh data.
  • Under a normal prior, expected out-of-sample Sharpe is in-sample Sharpe times τ2/(τ2+σ2)\tau^2/(\tau^2 + \sigma^2); with no real edges, it is zero.
  • The best of NN null trials has expected Sharpe σS E[max⁡NZ]\sigma_S\,\mathbb{E}[\max_N Z]: about 1.54σS1.54\sigma_S, 2.51σS2.51\sigma_S, 3.24σS3.24\sigma_S for 10, 100, 1000 trials.
  • Short holdouts have little power; they guard against disasters rather than confirm small edges.

Practice problems

Finished reading?

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