Quant techniques · backtesting

Purged cross-validation: stop overlapping labels leaking across folds

A training row in finance often represents more than one timestamp. A label may ask whether a price barrier is hit over the next five days, or measure the return from entry until a variable exit. If a training label and a test label use some of the same future returns, the validation score is contaminated even when their row timestamps differ. Purged cross-validation removes those overlaps; an embargo can add a buffer for residual dependence.

Purge overlapping label horizons

Training observations excluded around a test block

Toy daily labels and a single held-out block; h observations on each side overlap its information window.

Labels are intervals

Represent observation ii by its feature time tit_i and label-information interval [ti,τi][t_i,\tau_i], where τi\tau_i is the last time used to determine its target. For each test fold, collect all test label intervals. Remove any training observation whose label interval intersects a test interval.

For a test label spanning [10,15][10,15], a training label spanning [13,17][13,17] overlaps it and must be purged—even if that training row began after the test row. Likewise, a training label from [7,11][7,11] shares information at times 10–11 and should be removed. The rule uses the full label horizon, not simply a fixed gap from the test timestamp.

Purging and embargo solve different problems

Purging removes training labels that directly overlap the information used by test labels. Embargo removes a buffer of training observations immediately after a test block, where serial dependence or delayed feature construction may still transmit information even without direct label-interval overlap.

For example, if the test block ends at date 20, an embargo of three sessions also excludes eligible training observations in dates 21–23. The embargo length should reflect how long features, outcomes, or information may remain dependent; choosing it by convention without checking the data can either leave leakage or waste scarce samples.

Purged folds are not automatically a final holdout

Purged k-fold can estimate performance under a particular resampling design, but training on observations both before and after a test fold is not a live deployment simulation. Use a final chronological holdout or walk-forward evaluation to answer whether the strategy would have worked using only information available at the time.

A fold construction recipe

  1. Define every feature timestamp and label end time, including variable-horizon labels.
  2. Split observations into contiguous test blocks, or use a carefully specified combinatorial scheme.
  3. For each split, identify test label intervals and remove all training intervals that intersect them.
  4. Apply an embargo after each test block if residual dependence or feature overlap warrants it.
  5. Fit preprocessing, feature selection, hyperparameter tuning, and calibration only inside the training portion of each split.
  6. Aggregate scores with awareness that folds overlap and their errors are dependent; do not treat every fold score as an independent experiment.

The split design must match the question. If the goal is purely prospective forecasting, chronological or rolling-origin validation is often the clearest estimate. Purged k-fold can be useful when scarce data make multiple train/test combinations valuable, but it does not erase non-stationarity or selection bias.

Worked overlap check

Suppose test observations have label intervals [10,14][10,14] and [15,18][15,18]. A training label [8,11][8,11] overlaps the first test interval, so purge it. A label [12,16][12,16] overlaps both and is purged. A label [19,21][19,21] does not overlap either interval; if an embargo of two sessions follows the test block ending at 18, however, this label is also excluded. A label ending at 9 has no overlap and lies before the test region, so this rule retains it.

Common mistakes

  • Purging by row timestamp only. Labels can continue well past their feature dates.
  • Assuming a gap of one day is enough when labels have variable horizons.
  • Letting scalers, feature selection, or target encoding see the test fold before fitting.
  • Calling shuffled purged CV a realistic live backtest. It can train on future regimes relative to a test fold.
  • Selecting the embargo length, model, and strategy on the same validation results, then reporting those results as unbiased performance.

Practice

OverlapA test label covers days 30–35. Should a training label covering days 27–31 be purged?
Show answer

Yes. The intervals overlap on day 30–31 (depending on the endpoint convention), so some return information contributes to both labels. Define interval endpoints consistently and purge intersections.

EmbargoA training label starts after the test interval and does not directly overlap it. Why might it still be embargoed?
Show answer

Features or returns may remain serially dependent, or feature/label construction may create delayed leakage around the test boundary. Embargo removes a post-test buffer for these residual effects.

EvaluationDoes purged k-fold alone establish that a strategy generalises to future unseen regimes?
Show answer

No. Purging addresses direct interval leakage, and embargo can address nearby dependence, but neither guarantees stationarity or prevents training on later regimes. Keep a chronological holdout or walk-forward assessment for prospective claims.

Further reading: López de Prado (2018), Advances in Financial Machine Learning, Chapter 7, “Cross-Validation in Finance.”