Concepts / Walk-forward vs CPCV
Walk-forward vs CPCV
3 min read · Concept
In everyday words
Revising from old exam papers, then sitting one you have never seen. Only the paper you have not seen shows what you learned.
An example in pounds
Say a rule is tuned on the years 2015 to 2018, where it turns £1,000 into £1,600. It is then tried on 2019, a year it never saw, and turns £1,000 into £1,040. The second figure is the fair one.
The short version
Two ways of testing a rule on prices it was not tuned on.
On Quantis today
Quantis runs a walk-forward inside Prove it, on the years before any sealed months. It does not run a CPCV. Both are further down, under On a Quantis result.
- Tuned on
- Tried on
What it is
A rule that is tuned on past prices can end up fitting those prices and nothing else. The fair check is to tune it on one stretch of history, then try it on a different stretch it has never seen. Walk-forward and CPCV are two ways of cutting history up to do that.
Walk-forward goes in date order. The rule is tuned on the early years and tried on the next year. Then the line moves forward a year and the same thing is done again.
CPCV stands for combinatorial purged cross-validation. It cuts history into blocks and tries many combinations. The rule is tuned on most of the blocks and tried on the few left out. Then a different few are left out.
A worked example
There are seven years of prices, 2015 to 2021. Walk-forward in three steps goes like this. The rule is tuned on 2015 to 2018 and tried on 2019. It is tuned on 2015 to 2019 and tried on 2020. It is tuned on 2015 to 2020 and tried on 2021. That gives three years the rule never saw while it was being tuned.
For CPCV, the same history is cut into 10 blocks. Two blocks at a time are left out. There are 45 different ways to pick the two, so the rule is tuned and tried 45 times.
What it does not tell you
- What comes next. Both methods describe history, cut up in different ways.
- Much, from one number. How far apart the years or blocks came out says more than their average.
- Anything fresh, once it has been used to choose. If the unseen years are used to pick between versions of a rule, they are no longer unseen for the version that was picked.
This leaves out how the blocks are kept from leaking into each other, and what each method reports. The exact version is below.
On a Quantis result
Quantis does not run a full CPCV. An ordinary test uses one fixed set of settings from start to finish. No part of it was kept back from that choice, and the result says so.
Prove it, the extra check you can run on a result, includes a walk-forward. It picks the best settings on the early years, then runs them on the stretch that follows. It does this a few times, moving forward each time.
Quantis also seals the newest months of each idea until you finish. Then the rule runs on them once. The page on the sealed test explains how.
A goal search holds prices back too. That is a test where you name a target and Quantis tries a range of rules. It picks a winner on the first 70% of the history. Then it reports how that winner did on the last 30%.
The exact mathsFor anyone who wants the detail. Nothing above depends on reading it.
The problem they both solve
A backtest that fits parameters on the same data it is judged on tells a story about that data and nothing more. The fix is out-of-sample (OOS) testing: split the data, fit on one slice (in-sample), evaluate on a different slice (out-of-sample). The two methods differ in how they split.
Walk-forward: temporal, sequential
Walk-forward splits the timeline into N expanding (or rolling) windows. Each window: fit on the past, evaluate on the next chunk forward, then roll the cutoff forward and repeat. The example below uses 3 windows with expanding training sets and equal-size out-of-sample blocks.
# Walk-forward (3 windows, expanding train)
window 1: train [2015-2018] test [2019]
window 2: train [2015-2019] test [2020]
window 3: train [2015-2020] test [2021]
# Final OOS Sharpe = average of 3 OOS SharpesWalk-forward mimics how a rule is traded in practice, refitting as new data arrives. Its weakness is that there are only 3 out-of-sample data points, all from the most recent stretch of history. If that stretch was unusual, the out-of-sample figures say little about any other kind of market.
CPCV: combinatorial, mixed across history
CPCV is from López de Prado, Advances in Financial Machine Learning (2018). The data is split into N groups (10 in this example), then every combination of training and test groups is run. With 10 groups partitioned 8 train / 2 test, you get 45 train/test splits. Each group is tested in 9 of them, so the splits recombine into 9 full backtest paths, each combining a different mix of historical periods for training and evaluation.
# CPCV (10 groups, 2-group test sets: 45 splits, which would give 9 paths)
group 1: 2015-Q1 group 6: 2016-Q2
group 2: 2015-Q2 group 7: 2016-Q3
...etc until 10 groups across the full sample
splits = combinations(10, 2) = 45
paths = splits * 2 / 10 = 9 # each group is tested in 9 of the 45 splits
for each split:
test on this 2-group slice
train on the other 8 groups (purged of overlap)
record OOS Sharpe
# Headline: median test-set Sharpe across the 45 splits (or across the 9 paths)
# Also report: fraction with positive SharpeThe “purged” part matters. If a rule looks back 5 days and is judged on the 5 days ahead, a naive split lets information leak across the boundary between training and test data. Purging removes the observations on both sides of the boundary; an embargo extends the gap past the test window.
Why the gap between them matters
They answer different questions, and the gap between them is informative.
- Walk-forward Sharpe high, CPCV Sharpe low: the strategy did well in the most recent stretch and poorly on average across the mix of history. The result belongs to one kind of market.
- CPCV Sharpe high, walk-forward Sharpe low: the strategy did well across most of history and poorly in the most recent stretch. That can be bad luck or a lasting change; the figures alone do not say which.
- Both high, both steady: the result held across the ways of cutting the history.
- Fraction of CPCV paths positive: a strategy with a median Sharpe of 0.8 and 90% of paths positive is a very different result from one with a median of 0.8 and 55% positive. The second depends on which slice of history happened to be drawn.
What Quantis runs today
Quantis does not run a rolling walk-forward or a full CPCV. Prove it runs an anchored walk-forward, and every idea keeps its newest months sealed until the sealed test is opened. Here is what it runs.
- Walk-forward (Prove it). The tested period is cut into a first window of at least a year and up to 5 consecutive folds of at least half a year. In each fold every setting of a small grid, fixed before any run, is run on all the years before the fold, and the one with the highest Sharpe there (a fitted figure) is chosen. The engine runs the chosen setting on the fold. The folds are stitched into one curve. It passes when the stitched Sharpe is above zero and keeps at least half of the fitted mean. With so few folds, a pass is not evidence of an edge.
- The sealed test (result card). The last 12 months of a test of at least 60 months, or the last fifth of a shorter one, are kept away from every test of the idea until the sealed test is opened, once. It is the one stretch no choice of yours has looked at; the sealed test page has the rules.
- Time-slice stability (result card). The card compares three later slices of the run (60 to 80%, 70 to 90% and 80 to 100% of the history) with the period before each. The parameters stay the same throughout and nothing is re-fit per slice, so this shows whether performance held up over time. The card labels it as not out-of-sample validation.
- Sharpe across sub-periods (result card, 100+ bars). The card cuts the same fixed-parameter run into 10 consecutive blocks and takes the Sharpe of every pair of blocks, 45 pairs in all. It borrows CPCV's way of cutting the history, but no bars are dropped and nothing is re-fitted, so it is not cross-validation: it shows how much the Sharpe depends on which stretch of history is looked at. A real CPCV with these settings would give 9 paths; the card's 45 pairs overlap, each block appearing in 9 of them.
- Goal search: one in-sample / out-of-sample split. When you give the agent targets (for example a Sharpe above 1.2 with less than half the benchmark's drawdown), every candidate runs on the first 70% of the history (in-sample) and on the last 30% (out-of-sample). The winner is chosen on the in-sample numbers only, and the verdict is its result on the held-out 30%. That is a genuine out-of-sample check, but a single split, not a rolling walk-forward or CPCV.
What to look at on the result
- Time-slice consistency. If only 1 of the 3 later slices is good, the headline Sharpe leans on one stretch of history. Three roughly similar slices is the steadier picture, though it is still not out-of-sample proof.
- Pairs at or below zero. The sub-period panel counts the block pairs with a Sharpe at or below zero, out of 45, and gives each block's own Sharpe. The card sets no pass mark: the parameters are the same throughout, so a low count is not validation.
- Per-regime breakdown. Quantis splits the run's Sharpe by what the benchmark had been doing before each day: after an uptrend, after a downtrend and after a volatile month. The label describes the 60 trading days before (21 for volatility), not the day itself, so the benchmark can gain on days labelled after a downtrend. Each figure comes with the number of days in its group and its standard error.
Where these methods mislead
- One out-of-sample Sharpe quoted alone. It is a point estimate. The spread across walk-forward windows or CPCV paths is what shows whether it means anything.
- Settings tuned on walk-forward results. Once variants are chosen on their walk-forward out-of-sample performance, that data has become in-sample for the choice.
Read next
- Overfitting → the problem these methods exist to catch.
- The sealed test → the newest months, kept apart until you finish.
- Sharpe vs PSR vs DSR → two checks on how much of a result could be luck.
- Start here → shares, funds and tests on past prices, from zero.
- López de Prado (2018). Advances in Financial Machine Learning. Wiley.