Walk-forward testing explained

Quantooo Lab ยท 2026-10-22

If you have ever split data randomly into "training" and "test" sets, you have probably let the future leak into the past without noticing. With stock data, the order of time is not a detail. It is the whole point.

What is walk-forward testing?

Walk-forward testing is a way of evaluating a trading model that respects time. You train the model on data up to a certain date, test it on the period right after, then move the cut-off forward and repeat. Every prediction is made by a model that has only seen earlier data, the way it would have worked in real life.

Why not use a random train and test split?

Because neighbouring days are related. Volatility, market regimes and many inputs change slowly. If Tuesday is in the training set and Wednesday is in the test set, the model has effectively seen the answer. Random splits also let a model learn from 2024 and then "predict" 2021, which no investor could ever do. Results from random splits are almost always too good.

How does a walk-forward test work step by step?

A typical setup, close to the one we use:

  1. Train on all data from the start until the end of year 1.
  2. Leave a gap, then predict every day of year 2.
  3. Add year 2 to the training data. Train again.
  4. Predict year 3. Repeat until the end of the data.
  5. Join all the out-of-sample predictions together and evaluate them as one record.

You end up with a full history of predictions, each made without knowledge of what came after.

Why leave a gap between training and testing?

Our target is the return over the next 20 trading days. A training example from 10 days before the cut-off has a target that overlaps the test period. Without a gap, sometimes called an embargo, that overlap leaks information. We leave a gap at least as long as the prediction horizon.

Does walk-forward testing guarantee a strategy will work?

No. It removes one kind of cheating, it does not create skill. You can still overfit by trying many models and keeping the best walk-forward result. That is why we also count every trial, compare against random rankings, and keep a final sealed holdout that no decision was allowed to see.

What did walk-forward testing show on this site?

All twelve models on our model leaderboard were evaluated walk-forward on 2020 to 2025 data. None showed a reliable ability to rank stocks by their next-month return. We also used walk-forward selection for the score's weights, choosing each year the weighting that had done best before. It did worse than leaving the weights equal, a neat demonstration of how overfitting punishes chasing past winners.

Open questions for students and researchers

Questions without a single right answer. Pick one and share your reasoning in the discussion below.

  1. How long should the gap (embargo) between training and testing be if the label is a 20-day return measured daily? Prove it.
  2. Expanding window or rolling window: which is better when markets change? Describe a test that would tell you.
  3. Walk-forward results are one path through history. How would you estimate the uncertainty of a walk-forward result?

Debate: three perspectives

An illustrative debate written by the author to lay out the main viewpoints. The three voices are roles, not real people. Your view is welcome in the discussion below.

The Sceptic: Walk-forward is the minimum standard, yet many papers still report random cross-validation for time series.

The Practitioner: Retraining every year is a choice with consequences. Retrain too often and you chase noise, too rarely and you miss regime shifts. Test the retraining frequency itself.

The Academic: Combinatorial purged cross-validation generalises walk-forward and gives a distribution of outcomes instead of one path. It deserves wider use.

Which view is closest to yours, and what evidence would change your mind?