Purged Walk-Forward Validation, Explained Simply

Purged walk-forward validation removes training samples whose labels overlap the test window, then adds an embargo. Here is why it matters and how it works.

Trigr Research6 min read
On this page
  1. Why does ordinary cross-validation fail on trading data?
  2. What are purging and embargo?
  3. How does purged walk-forward work, step by step?
  4. How is this different from scikit-learn's TimeSeriesSplit?
  5. What about combinatorial purged cross-validation?
  6. How does Trigr use purged walk-forward?
  7. What does purged validation not solve?
  8. Next steps

TL;DR: Purged walk-forward validation trains a model only on the past, tests it on the next block of time, and removes any training sample whose label overlaps that test block, plus an embargo gap beside it. It is the standard fix, from López de Prado's Advances in Financial Machine Learning, for the leakage that makes ordinary cross-validation look far better than live trading.

Why does ordinary cross-validation fail on trading data?

Standard k-fold cross-validation assumes observations are independent and identically distributed. You shuffle the rows, split them into folds, train on some and test on the rest. For market data, both assumptions break.

First, shuffling puts the future in the training set. A model trained on March and tested on February can learn the regime that followed, which it could never know in real time. Second, trading labels span time. If a label says "did this trade hit its profit target within 24 hours", then the label attached to a bar on Monday morning depends on prices through Tuesday morning.

That second point is the one people miss. Even if you keep time order and never shuffle, a label that starts just before the test window and ends inside it carries information about the test period into training. The result is a model that looks accurate in validation and falls apart live. It is a close cousin of look-ahead bias in backtests, just hidden in the labels instead of the features.

What are purging and embargo?

López de Prado describes two corrections in chapter 7 of Advances in Financial Machine Learning (Wiley, 2018).

Purging. Every training sample has a label interval: the bar where it starts and the bar where its outcome is determined. Purging drops any training sample whose interval overlaps the test period. What remains in training cannot contain an outcome that was decided by test-period prices.

Embargo. Markets have serial correlation. Volatility clusters, trends persist, and features built from rolling windows carry recent history forward. An embargo removes an extra band of samples next to the test period, so information cannot leak across the boundary through that correlation. López de Prado applies it after the test set in k-fold schemes, where training data can sit on both sides; in a pure walk-forward setup, where training is always in the past, the useful gap sits before the test block.

Correction What it removes Leak it prevents
Time ordering Future rows from training Training on regimes you could not have known
Purging Training samples whose label interval overlaps the test period Outcomes decided by test-period prices
Embargo An extra gap of samples beside the test period Serial correlation across the boundary

How does purged walk-forward work, step by step?

Walk-forward validation mimics how you would actually use a model: train on what you know, trade the next period, then retrain with more history.

  1. Sort all labeled events by start time.
  2. Split them into consecutive blocks.
  3. For each test block, take every earlier event as candidate training data.
  4. Purge any candidate whose label ends inside, or within the embargo distance of, the test block.
  5. Fit a fresh model on what remains, including any scaling or imputation, and predict the test block.
  6. Move to the next block and repeat.

Pool the predictions from every test block and you have a genuinely out-of-sample record, which you can score and turn into a gated equity curve.

A worked example

Suppose you trade 1-hour bars and each label looks up to 24 bars ahead. Your test block starts at bar 5,000.

  • An event that starts at bar 4,990 resolves somewhere between bars 4,991 and 5,014. If it resolves at bar 5,006, its label depends on test-period prices from bars 5,000 to 5,006. Purging removes it.
  • An event that starts at bar 4,960 and resolves at bar 4,984 does not overlap. It stays, unless it falls within the embargo band.
  • With an embargo at least as long as the label horizon, the events just before the test block are dropped as well, even when their labels end in time, so the correlation between the last training labels and the first test bars cannot help the model.

The cost is a few dozen training rows per fold. The benefit is that the test score now means something.

Anchored or rolling?

In an anchored (expanding) walk-forward, every fold trains on all history up to the test block. In a rolling walk-forward, the training window has a fixed length and slides forward. Anchored gives the model more data and more stable estimates. Rolling adapts faster when markets change but trains on less. With the short histories typical of crypto perps, anchored is usually the better default.

How is this different from scikit-learn's TimeSeriesSplit?

scikit-learn's TimeSeriesSplit produces expanding, time-ordered folds, and it has a gap parameter that excludes a fixed number of samples before each test set. That is a real improvement over shuffled k-fold, and for fixed-horizon labels a gap equal to the horizon approximates purging.

The difference is that TimeSeriesSplit works on row positions, not on label end times. When labels have variable lengths, as triple-barrier labels do because a stop can be hit after two bars or the time barrier after twenty-four, a fixed gap is either too small for some samples or wastefully large for others. Purging reads each sample's actual end time and removes exactly the overlapping ones. It is also why purged methods need a label-end series (often called t1) alongside the features.

What about combinatorial purged cross-validation?

Walk-forward produces one out-of-sample path, which is the path history happened to take. López de Prado's combinatorial purged cross-validation (CPCV) splits the data into N groups, chooses every combination of k groups as the test set, and purges and embargoes around each. That produces many train/test splits and several backtest paths from the same data.

CPCV is useful for measuring how stable a result is across different splits, and it is the natural input for estimating the probability of backtest overfitting. The trade-off is that CPCV trains on data from after some test groups, which is fine for estimating overfitting risk but is not how a model would be used live. Many practitioners use walk-forward for the headline number and CPCV for diagnostics.

How does Trigr use purged walk-forward?

Trigr's ML optimization follows the split described above, and the ML optimization docs spell out the details:

  • Anchored, purged walk-forward folds. Events are ordered by start time and split into consecutive blocks. The first block is training only; every later block is tested on a model trained strictly on earlier events whose labels ended before the test block, minus the embargo.
  • Embargo sized to the label. The embargo is at least as long as the triple-barrier label horizon (and never less than 1% of the bars), so the longest possible label cannot straddle the boundary.
  • Fresh fit per fold. Imputation, scaling and the model are refit inside every fold. Nothing is fit on the full sample and reused.
  • Model selection on out-of-sample results. LightGBM, random forest and XGBoost each run with fixed, disclosed parameters, and the family is selected on these walk-forward out-of-sample results. There is no hyperparameter search.
  • CPCV for diagnostics only. A separate combinatorial purged grid estimates PBO. It does not pick the model.
  • Embargo sensitivity check. The leak battery reruns with wider embargoes. If out-of-sample performance falls below half of its original level once the gap grows, the result is flagged as likely label-overlap leakage.

Features are point-in-time too, since purging cannot fix a feature that already contains future data. That half of the problem is covered in our point-in-time backtesting guide, and the whole pipeline is laid out in the machine learning without overfitting pillar.

What does purged validation not solve?

Purging makes each out-of-sample prediction honest. It does not make your research process honest by itself.

  • Selection across runs. If you run the whole procedure fifty times with different features and keep the best, the winning out-of-sample score is biased upward. Trigr's Deflated Sharpe Ratio counts the trials inside a run, but separate reruns are not yet accumulated, so repeated tuning still needs a fresh holdout or live validation.
  • Regime change. Walk-forward tests on history. A market that behaves unlike anything in the sample can still break the model.
  • Thin samples. With few events per fold, out-of-sample estimates are noisy. Trigr flags low-power runs rather than hiding them.

Backtests are not guarantees; perps are leveraged and can lose more than expected.

Next steps

Pair purged validation with labels that match how your trades resolve: read the triple-barrier method and meta-labeling in practice. If you want to try ML optimization on your own strategies, compare plans and credit allowances on the pricing page.

Frequently asked questions

What is purging in cross-validation?

Purging removes from the training set every observation whose label interval overlaps the test period. It prevents a model from training on outcomes that were partly determined by prices inside the test window.

What is an embargo in purged cross-validation?

An embargo is an extra gap of observations dropped next to the test period, on top of purging. It guards against serial correlation carrying information across the boundary.

Is scikit-learn's TimeSeriesSplit the same as purged walk-forward?

Not quite. TimeSeriesSplit keeps time order and offers a fixed gap parameter, but it does not know each label's end time. Purging uses the actual label intervals, so it removes exactly the samples that overlap the test window.

Should walk-forward validation be anchored or rolling?

Anchored (expanding) windows use all past data and give more training samples; rolling windows adapt faster to regime change but train on less. Anchored is a sensible default when data is scarce, which is usually the case in trading.

Put the idea to an honest test.

Describe a strategy in plain English or from your own AI assistant, backtest it on point-in-time data, and forward-test it on paper before any real money is involved.