StratoQuant
EN
Get the free code

B-02 · Build · validation

Walk-forward testing: a fairer test of a system

How walk-forward testing works, rolling and anchored windows, how to read its results, and the ways it can still be fooled.

By Baris Demirci · · Rev00


The idea

An ordinary backtest builds and judges a system on the same history, so it cannot tell a rule that captured something real from one that memorised the past. Walk-forward testing separates the two jobs. It builds the system on one stretch of history, tests it on the stretch that follows, then moves forward and does it again, all the way through the data.

It is a rehearsal of what really happens when you trade: you decide with the past you have, then live with a future you have not seen.

Rolling and anchored windows

Each step has a build window, where settings are chosen, and a test window right after it, where they are used unchanged. There are two common ways to move forward.

Rolling Anchored Build Test, settings frozen Time
Illustration. In both layouts the test windows line up end to end and never overlap, so together they cover a long stretch of history that no setting was chosen on.
  • Rolling. The build window has a fixed length and slides forward. The system always adapts to recent conditions and forgets the distant past.
  • Anchored. The build window always starts at the beginning and grows. Settings rest on more history each time, and change more slowly.

Neither is right in general. Rolling suits ideas that are expected to drift with conditions; anchored suits ideas that should hold across long periods.

One step at a time

Build window: try the settings Choose by a rule fixed in advance Freeze it, run on the next test window Record the test result More history left? Join the test pieces into one record No Yes: slide both windows forward
Illustration of the procedure. The choice in the second box must follow a rule written down before the test starts, such as "the middle of the best plateau", so that no human judgement leaks in between steps.

The output is not a single best setting. It is a long record made only of periods the system had not seen when its settings were chosen. That record is the closest thing to live results a backtest can give.

Reading the results

The most useful comparison is between each build window and the test window that follows it.

Build Test Step 1 Step 2 Step 3 Step 4 Step 5 Step 6
Illustration of a typical pattern, not results. Test results are smaller than build results, and one step lost. That is normal. What matters is whether the tests hold a reasonable share of the build results, step after step.
  • Test results should be smaller than build results. The build window always looks best, because settings were chosen on it. A test that holds a reasonable share of it, step after step, is a good sign.
  • A test that keeps collapsing to a small fraction of the build result, or flips to losses in many steps, says the build results were mostly fitting.
  • Consistency beats one great step. A system that is modestly positive in most test windows is more convincing than one carried by a single brilliant period.
  • The joined test record is the one to study: its growth, its drawdowns and its worst stretches. It is a fairer picture than any single backtest.

Choosing the windows

  • Long enough to mean something. Each build window needs enough trades to choose a setting, and each test window enough to judge it. A slow system that trades a few times a year needs windows of several years.
  • Test windows shorter than build windows, often a fifth to a third as long, so that there are many steps.
  • Decided before you look. Window lengths, the setting ranges and the rule for choosing are all part of the test. Fix them first.

How it can still be fooled

Walk-forward testing makes fitting harder. It does not make it impossible.

  • Tuning the walk-forward itself. Trying many window lengths or choice rules and keeping the one with the best joined record is just overfitting one level up.
  • Rerunning after looking. If the system is changed after seeing the test windows and the walk-forward is run again, those windows are no longer unseen.
  • Flattering assumptions. It inherits every flaw of the backtest underneath it: look-ahead, survivors only, perfect fills and bad data. See backtesting.
  • Too few steps. Three test windows are an anecdote. Many are evidence.

What it asks of you

  • Writing the rules of the test down first, including how a setting will be chosen.
  • Accepting a less impressive record. The joined test record will almost always look worse than the best backtest. It is also much closer to what live trading is likely to look like.

The short version

Walk-forward testing chooses settings on one stretch of history, uses them unchanged on the next, and repeats through the data. The result is a long record built only from unseen periods. Expect the tests to trail the builds, look for consistency across steps, fix every choice in advance, and remember that the walk-forward can be overfitted too.


Written for people building their own systematic portfolio management process. Nothing here is a recommendation to buy or sell anything. See the disclaimer.

← All articles