Systematic Trading Field Guide
2.5 · Not fooling yourself

Backtest overfitting: PBO and a walk-forward protocol

~14 min read
Mechanism

The best-performing configuration among many is partly — often mostly — selected noise, so its backtest systematically overstates what it will do next. The probability of backtest overfitting (PBO) measures how often your in-sample champion falls into the bottom half out-of-sample; a pre-committed walk-forward protocol is the working defence. If the in-sample winner keeps losing the out-of-sample tournament, you don't have a strategy — you have a leaderboard.

The idea

Every systematic trader eventually produces the heatmap. Two parameters — say a fast and a slow moving-average window — swept over a grid, each cell coloured by backtest Sharpe. Somewhere on it glows a beautiful island: (14, 87), Sharpe 1.9. The cells around it are decent; the far corners are red. The temptation is physical: the market likes 14 and 87.

Here's the reframe this lesson exists to install. That heatmap is not a map of the market. It is a map of one historical path's noise, with any real signal buried somewhere under the topography. The market does not know what a 14-day average is. If the underlying effect ("trend exists at multi-week horizons") is real, it is smeared broadly across the grid; the specific glow at (14, 87) is where the effect plus this sample's luck happened to peak. Pick the peak and you have selected luck along with signal — and luck does not persist. Re-run history with different noise and the island moves; your live trading is exactly such a re-run.

This is lesson 2.3's selection problem wearing practical clothes, and the pseudo-mathematics paper (Bailey, Borwein, López de Prado & Zhu 2014) proved the uncomfortable theorem behind it: with enough configurations, you can always find one with an excellent in-sample Sharpe on pure noise — and the minimum backtest length needed to defend against this grows with the number of trials. Given how cheap trials are, the practical conclusion is stark: an in-sample Sharpe, alone, no matter how high, is not evidence. What is evidence? A procedure that measures how much of the champion's performance survives when the data that crowned it is taken away. Two tools: PBO to diagnose, walk-forward to operate.

PBO — putting a number on "was the winner luck?" The probability of backtest overfitting (Bailey, Borwein, López de Prado & Zhu 2016) asks a beautifully direct question: when your in-sample champion is evaluated on data it wasn't selected on, how often does it land in the bottom half of its own peer group? If selection were pure skill, the IS winner should stay near the top OOS. If selection were pure luck, its OOS rank should be uniform — bottom half about 50% of the time. The method (combinatorially symmetric cross-validation) reuses your existing grid search: take the matrix of returns (configurations × time), cut time into SS blocks, and for every way of choosing half the blocks as "in-sample": find the IS champion, then look up its rank out-of-sample on the other half. Repeat over all (SS/2)\binom{S}{S/2} complementary splits. PBO is the fraction of splits where the IS champion finished below the OOS median. Read it like a corruption index for your selection process: PBO near zero — selection is finding something real; PBO near 0.5 — your grid search is a lottery; and the companion statistic (the slope of IS vs OOS performance) tells you how much Sharpe evaporates between selection and deployment.

Walk-forward — overfitting-resistant operation. The diagnosis is useless without a way of operating that doesn't re-commit the crime. Walk-forward simulation is that way, but only under a discipline most people skip: the entire procedure is written down before it runs. Choose the parameter grid, the selection rule ("highest Sharpe" or, better, "centre of the widest acceptable plateau"), the in-sample window length, the refit frequency — all fixed, in writing. Then simulate history as it would actually have unfolded: stand at each refit date, select using only the trailing window, trade the selection forward until the next refit, repeat. Stitch together only the traded segments and evaluate the result. What you get is the backtest of the process — selection rule included — rather than the backtest of one lucky configuration. The stitched track record inherits the process's honest properties: every parameter choice in it was made without seeing the data it was graded on.

The subtle point that makes this work, and the one people most often violate: the walk-forward gets run once. Run it, dislike the result, adjust the grid, run again — and you are now grid-searching over walk-forwards; the outer loop is overfitting even though every inner step is clean. The stitched Sharpe you eventually like is the max over process-variants, right back in lesson 2.3's expected-maximum machinery. Iterating on research is fine — necessary — but every outer-loop iteration goes in the trial count, and the final verdict belongs to data no iteration ever touched.

The maths

PBO's bookkeeping, compactly. You have MM configurations and TT return observations arranged in a matrix. Cut time into SS equal blocks. For each of the C=(SS/2)C = \binom{S}{S/2} ways to pick half the blocks, form in-sample set JJ (the chosen blocks, concatenated) and out-of-sample set Jˉ\bar J (the rest). Let m\*m^\* be the configuration with the best performance on JJ, and let ω\omega be its relative rank on Jˉ\bar J, scaled to (0,1)(0,1) — ω=1\omega = 1 means it was also the best OOS, ω=0.5\omega = 0.5 the median, ω→0\omega \to 0 the worst. Then:

PBO  =  1C∑c=1C1 ⁣[ ωc<12 ]\text{PBO} \;=\; \frac{1}{C} \sum_{c=1}^{C} \mathbf{1}\!\left[\,\omega_c < \tfrac{1}{2}\,\right]
PBO is the probability that the in-sample champion performs below the median of its own peer group out-of-sample. S blocks give C complementary splits; ω is the champion's OOS relative rank on each.

Interpretation anchors: a perfectly skill-driven selection gives PBO near 0; pure noise gives PBO near 0.5 (the champion's OOS rank is uniform); and values above 0.5 do occur — they mean configurations that win IS actively lose OOS, the signature of mean-reverting noise being fit as if it were persistent structure. Report PBO alongside the IS→OOS performance degradation (regress OOS performance of the IS champion on its IS performance across splits; the shortfall from slope 1 is your haircut estimate), and the deflated Sharpe of lesson 2.3 (Bailey & López de Prado 2014) as the final significance check.

Worked example

Worked example — PBO on a 400-configuration grid, and the honest walk-forward

The setup. A 20×20 grid of MA-crossover parameters on eight years of daily returns: M=400M = 400 configurations. Cut the eight years into S=8S = 8 annual blocks. Enumerate all (84)=70\binom{8}{4} = 70 complementary four-year splits.

The diagnostic run. For each split: select the best-Sharpe configuration on the four IS years; record its Sharpe rank among all 400 on the other four years. Two illustrative outcomes (numbers invented to show the shapes you'll meet):

OutcomeIS champion Sharpe (typical)OOS rank patternPBOVerdict
A1.8uniform: top-decile on 7 splits, bottom-half on 34 of 700.49selection is a lottery; the island was noise
B1.1above median on 61 of 70 splits, never bottom decile0.13the grid contains something real that selection reliably finds

Note the inversion worth staring at: outcome A had the higher champion Sharpe. Of course it did — noisier selection produces more flattering champions, precisely because it's free to chase luck. PBO is the tool that looks past the headline number at the reliability of the selection process, and it will regularly rank a modest-but-stable grid above a spectacular-but-fragile one.

The core of the computation is short enough to keep in your framework:

from itertools import combinations
import numpy as np

def pbo(returns):                      # returns: (T, M) config returns
    blocks = np.array_split(np.arange(len(returns)), 8)
    below = 0; splits = list(combinations(range(8), 4))
    for c in splits:
        is_idx  = np.concatenate([blocks[i] for i in c])
        oos_idx = np.concatenate([blocks[i] for i in range(8) if i not in c])
        sr = lambda idx: returns[idx].mean(0) / returns[idx].std(0)
        champ = sr(is_idx).argmax()
        omega = (sr(oos_idx) < sr(oos_idx)[champ]).mean()
        below += omega < 0.5
    return below / len(splits)

The operating run. Suppose the grid earns a PBO of 0.13 — worth operating. The pre-committed protocol: rolling three-year IS window; selection rule "highest median Sharpe over the 5×5 neighbourhood of the grid" (plateaus, not peaks); refit annually; costs included; the stitched OOS record is the only number reported. Simulating 2016–2024 under that protocol yields five annual OOS segments — that stitched Sharpe, typically noticeably below the heatmap's glow, is your honest estimate, and the gap between it and the island is the overfitting you just declined to buy.

How you'd use it

  1. Grid-search is allowed; believing the argmax is not. Sweep freely — the sweep is data. Then evaluate the selection process with PBO and quote the walk-forward stitched result, never the best cell.
  2. Prefer plateaus to peaks, structurally. Make "the neighbourhood must also work" part of the written selection rule. A real effect is smooth in its parameters (nothing in markets knows the difference between 14 and 15 days); an isolated spike is noise by construction.
  3. Write the protocol before the first run. Grid, selection rule, windows, refit cadence, costs, evaluation metric — committed to the research log (lesson 1.10) first. Every subsequent deviation is a new trial and gets counted (lesson 2.3).
  4. Keep a never-touched span. The last year or two of history stays outside every loop — no tuning, no PBO, no peeking — and delivers one final verdict, once, when you believe you're done.
  5. Report the haircut. IS champion Sharpe, stitched walk-forward Sharpe, PBO, deflated Sharpe. The distance between the first two numbers is your personal, measured overfitting rate — track it across projects and you'll learn how much to discount your own future enthusiasm, which may be the single most valuable statistic a solo researcher can own.

What goes wrong

The outer loop. Worth repeating because it is the failure mode: a clean walk-forward, re-run seventeen times with adjustments, is a dirty grid search over protocols. The seventeenth result is a champion of seventeen trials and must be deflated as such. The tell is psychological — if you know what result you're hoping the next re-run produces, you're in the outer loop.

Too few effective decisions. A walk-forward that refits annually over eight years makes eight selection decisions. Eight data points tell you little about the selection rule's skill (lesson 2.6's sampling error, applied to the protocol itself). More refits help statistics but chase noise faster and churn more; the tension is real, and breadth across assets — running the same protocol on thirty markets — is usually the only honest way to multiply decisions.

PBO on a degenerate peer group. PBO ranks the champion against its peers. If your grid is 400 nearly-identical variants, ranks are uninformative (everything correlates 0.98); if it mixes ten genuinely different strategy families, "below median" conflates selection skill with family quality. The clean unit is one family, meaningfully varied — and effective diversity of configurations is worth checking with the same correlation-clustering used for effective trial counts in lesson 2.3.

Regime luck in the blocks. With S=8S = 8 annual blocks, every split's OOS set is some bundle of years, and if one year (2008, 2020) dominates variance, PBO partly measures "did the champion hold up in the crisis year" — a regime question, not only an overfitting one. Inspect the splits that produced the worst ω\omega; if they all contain the same block, you've learned something about regime dependence (lesson 2.7), which is a different disease with a different treatment.

Protocol overfitting by community. The subtlest version: the field converges on protocols that flatter its favourite strategies (momentum looks better refit annually; mean reversion prefers monthly). You inherited your defaults from somewhere. Occasionally re-derive them from the mechanism — how fast does this edge's counterparty change behaviour? — rather than from what everyone's backtests happen to reward.

Further reading