Backtesting Rigorously · Validation · Module 5

Combinatorial Purged Cross-Validation (CPCV)

Standard cross-validation breaks on financial data: shuffling destroys temporal structure, and label windows that span multiple bars create leakage between training and test sets. Combinatorial Purged Cross-Validation (CPCV) addresses both problems, generating a distribution of out-of-sample performance paths that enables the Probability of Backtest Overfitting — the most rigorous diagnostic for detecting overfit strategies.

Module 5 — Backtesting Rigorously: Backtesting Pitfalls (pillar) · Walk-Forward Analysis · Deflated Sharpe Ratio · CPCV ← you are here · Survivorship Bias · Look-Ahead Bias

Why Standard Cross-Validation Fails for Financial Data

In standard k-fold cross-validation, observations are shuffled randomly into k groups and each group is used once as the test fold while the remainder forms the training fold. This procedure assumes that observations are exchangeable — that the order they appear in the dataset is irrelevant to their statistical properties. For financial time series, this assumption is wrong in two ways.

First, temporal ordering matters. A model trained on 2023 data and tested on 2022 data has implicitly used future information for training. Random k-fold creates such violations routinely. For backtesting purposes, training data must always precede test data in time.

Second, labels overlap across adjacent observations. In financial machine learning, a label is often a future return: for each daily observation on day T, the label might be the cumulative return from day T to day T+20. The labels for days T and T+1 both include the return from day T+1 to T+20 — they share 19 of 20 days. Including observations T and T+1 in different folds (one in training, one in test) means a piece of training data is derived from the same market events as a piece of test data. This is look-ahead leakage at the label level, invisible without explicit accounting for label windows.

The Three Components of CPCV

1. Combinatorial splits

Rather than a single rolling train-test split (as in walk-forward analysis), CPCV generates all valid train-test combinations from a set of non-overlapping data folds. If the dataset is divided into k groups, CPCV generates C(k, φ) paths by selecting φ groups as test data and the remaining k−φ groups as training data, for all valid combinations. This produces many more paths than a single rolling walk-forward, covering more of the data's temporal variation. Each path provides an OOS performance estimate; together they form a distribution.

2. Purging

For each train-test split, purging removes any training observation whose label window extends into the test period. If observation T has a 20-bar lookahead label and the test period begins at bar T+5, then T's label overlaps with the test set. Purging drops T from the training fold. The purging boundary is computed from the known label window length; any training observation whose label crosses the test boundary is excluded.

3. Embargo

Even after purging, adjacent observations at the boundary of a train-test split may be serially correlated in their returns (not their labels). An embargo adds a fixed gap between the last training observation and the first test observation — typically a few bars to weeks depending on the autocorrelation structure of the series. The embargo size is set based on the half-life of serial correlation in the residuals. Together, purging and embargo eliminate the two dominant forms of leakage in financial cross-validation.

CPCV vs Walk-Forward Analysis vs Simple Holdout

Method OOS paths Label leakage Serial correlation PBO computation
Simple holdout 1 point estimate Unaddressed Unaddressed Not possible
Walk-Forward Analysis Several point estimates (one per window) Unaddressed Partially (temporal ordering preserved) Not possible
CPCV Many distributional paths C(k, φ) Eliminated by purging Eliminated by embargo Yes — PBO directly computable

The Probability of Backtest Overfitting (PBO)

PBO is computed by applying the Combinatorial Symmetric Cross-Validation (CSCV) procedure: for each combinatorial path, identify the strategy configuration that performed best in-sample. Then measure whether that IS champion outperforms the median OOS configuration on the path's test set. PBO is the fraction of paths where the IS champion fails to beat the OOS median — i.e., where in-sample optimization did not predict OOS selection.

A PBO near 0 means the IS champion consistently also wins OOS: evidence that the optimization is finding real signal, not noise. A PBO near 0.5 means the IS champion wins OOS approximately at random: the optimization is fitting noise. Bailey & López de Prado introduced PBO in their 2016/17 paper (SSRN 2326253, Journal of Computational Finance 20(4)).

Implementation

López de Prado's Advances in Financial Machine Learning (AFML, ch. 12) provides the CPCV algorithm in full, including Python pseudocode for label-window-aware purging and embargo calculation. The pypbo library (github.com/esvhd/pypbo) implements PBO, PSR, and DSR. The Wikipedia article on Purged cross-validation provides a concise summary of the method.

CPCV is computationally heavier than WFA: generating C(k, φ) paths requires fitting the model C(k, φ) times. For strategies with fast fitting (few parameters, simple objective), this is tractable; for large neural networks or computationally expensive portfolios, CPCV's cost may be prohibitive. In those cases, WFA with an added PBO approximation is a practical compromise.


Frequently Asked Questions

What is Combinatorial Purged Cross-Validation (CPCV)?
Combinatorial Purged Cross-Validation (CPCV), developed by López de Prado, is a backtesting validation framework that generates many train-test splits combinatorially, applies purging to remove training observations whose labels overlap with test observations in time, and applies an embargo period after each test fold to block serial-correlation leakage. The result is a distribution of out-of-sample performance across many test paths — a far richer picture than a single holdout estimate. The aggregated distribution also enables the Probability of Backtest Overfitting (PBO): the fraction of paths where the in-sample best configuration underperforms the out-of-sample median.
What is the difference between purging and embargoing in CPCV?
Purging removes training observations whose outcome labels overlap in time with the test period. In financial machine learning, a label for observation T is often computed over a lookahead window (e.g., the return over the next 20 bars). If that lookahead window overlaps with the test period, including T in training introduces look-ahead information. Purging drops those observations from the training set. Embargoing adds a gap of fixed length between the training set and the test set, blocking leakage from serial correlation. Even without label overlap, returns at the boundary of a train-test split can be correlated. The embargo ensures that the last training observation and the first test observation are separated by enough time to break that correlation.
What is the Probability of Backtest Overfitting (PBO)?
The Probability of Backtest Overfitting (PBO), introduced by Bailey and López de Prado, is the fraction of combinatorial train-test paths in which the strategy configuration with the best in-sample performance also underperforms the median configuration out-of-sample. A PBO near 0 means the in-sample champion reliably also wins out-of-sample — evidence of a genuine edge. A PBO near 0.5 means the champion wins out-of-sample approximately by chance — evidence of overfitting. PBO is computed via the Combinatorial Symmetric Cross-Validation (CSCV) procedure and requires multiple train-test splits, making CPCV a natural complement. The pypbo Python library provides a reference implementation.
Why does standard k-fold cross-validation fail for financial data?
Standard k-fold cross-validation shuffles observations randomly into k folds. For financial time series, this breaks the serial structure of the data: a training fold may contain observations from 2023 while the test fold contains observations from 2022, creating look-ahead leakage. Furthermore, if labels span multiple periods (e.g., a 20-day return label on a daily series), the same event contributes to overlapping label windows across adjacent observations. K-fold has no mechanism to detect or remove this overlap. CPCV addresses both problems: it preserves temporal ordering, purges overlapping labels, and adds an embargo to block residual serial-correlation leakage across fold boundaries.
How is CPCV different from walk-forward analysis?
Walk-forward analysis uses a rolling single train-test split: optimize IS, test OOS, step forward, repeat. It produces one OOS performance estimate per window — aggregated to a point estimate. CPCV generates combinatorially many train-test paths using all available data for both training and testing (via different splits). It produces a distribution of OOS performance paths, enabling PBO computation. Walk-forward analysis is the practitioner standard — simpler, faster, and sufficient for most strategies. CPCV is statistically superior when the goal is a rigorous distribution of OOS performance, when PBO is required, or when the sample is too short for many non-overlapping walk-forward windows.

Drill CPCV mechanics, PBO, and backtesting validation statistics with AlgoDrill's spaced-repetition flashcards.

Start Flashcards →   View Reading List →