TradeLabs AILearn

Model Evaluation and Cross-Validation

Standard cross validation leaks future data in time series. Learn time series splits, purging and embargo, combinatorial purged cross validation and good practice.

Advanced3 min readUpdated 3 Oct 2026
Markdown
Lesson 7 of 10

Cross validation estimates how well a model will perform on data it has not seen, by repeatedly training on part of the data and testing on the rest. In most machine learning tutorials, the data is shuffled randomly into folds. For financial time series, that standard approach is dangerous: it trains on the future to predict the past, and overlapping labels leak information between folds. The result is validation scores that look far better than anything achievable live. Time aware validation methods fix this.

Why random folds fail on market data#

ProblemExplanation
Training on the futureA random fold may train on 2024 and test on 2019
Serial correlationNeighbouring observations are similar, so test points have near copies in training
Overlapping labelsA 10 day forward return label on Monday overlaps the label on Tuesday
Regime informationTraining on future data lets the model learn which regime came next

Time series split#

The simplest correct method: always train on earlier data and test on later data. With an expanding window, each fold adds more history to training.

FoldTrainTest
12015 to 20172018
22015 to 20182019
32015 to 20192020
42015 to 20202021

scikit-learn's TimeSeriesSplit implements this pattern. See Walk-Forward Validation and Preventing Overfitting.

Purging and embargo#

When labels span future periods, training samples near the test period can contain information about it.

  • Purging: remove training samples whose label periods overlap the test period.
  • Embargo: also remove a short buffer of samples just after the test period, since serial correlation can leak information backwards.

These ideas were formalised by Marcos López de Prado in "Advances in Financial Machine Learning" (2018).

Combinatorial purged cross validation#

Single train and test paths can be lucky or unlucky. Combinatorial purged cross validation (CPCV) splits data into groups and tests on many combinations of groups, with purging and embargo, producing a distribution of backtest results instead of one number. This helps assess how likely a strategy's performance is to be due to chance. See Bootstrap and Permutation Tests.

Nested validation for tuning#

If you tune model settings using the same folds you report results on, the reported score is optimistic. Use an inner loop to choose settings and an outer loop, or a final untouched test period, to measure performance. See Parameter Optimization.

Good practice#

  1. Never shuffle time series before splitting.
  2. Purge and embargo when labels overlap.
  3. Keep a final holdout period that is used once. See In-Sample vs Out-of-Sample Testing.
  4. Report the spread of results across folds, not just the average.
  5. Count your trials: each experiment increases the chance of a lucky result. See P-Hacking and Multiple Testing.
  6. Test the trading rule with costs, not only prediction metrics.

Frequently asked questions#

Can I use k fold cross validation on stock data?#

Standard shuffled k fold leaks future information. Use time series splits, or k fold with purging and embargo designed for financial data.

What is purging in cross validation?#

Removing training samples whose label periods overlap the test period, so the model cannot learn test outcomes indirectly.

What is an embargo?#

A buffer of samples removed after the test period to prevent leakage caused by serial correlation.

Next, learn the walk forward approach in detail in Walk-Forward Validation and Preventing Overfitting.

Check your understanding

3 quick questions on this lesson. Get them all right to finish it.

Turn on JavaScript to take the quiz.

Finished this lesson?Sign in to save your progress across devices.
Next lessonWalk-Forward Validation and Preventing OverfittingWalk forward validation retrains a model on a rolling or expanding window and tests it on the next period, just as it would be used live. Learn setup and choices.

Mentioned in