Skip to content
GetProfitable
Search
Wiki

Walk-Forward Testing

The protocol for testing a rules-based strategy honestly: optimise on one window, validate on the next unseen window, roll forward, and judge the strategy only on the stitched out-of-sample results.

What it is

Walk-forward testing is a backtesting protocol that separates the data used to choose a strategy's parameters from the data used to judge it. You split history into consecutive windows; on each in-sample window you pick the best parameters, then you apply those parameters, frozen, to the following out-of-sample window and record the result. Rolling forward through history produces a stitched out-of-sample equity curve that approximates what you would have experienced if you had actually been re-fitting the strategy as time passed. It is the single most useful habit a systematic trader can adopt, and skipping it is the single most common way backtests lie.

It is a "playbook" in the sense that it is a repeatable process; it does not produce trades by itself. Every other quantitative article in this wiki assumes it.

The logic

Any strategy with adjustable parameters (a lookback, a threshold, a stop multiple) can be tuned to look good on past data, because with enough combinations one of them will fit the noise. That fit does not carry forward. Out-of-sample testing measures how much of the in-sample result was signal. If the strategy's out-of-sample performance is a reasonable fraction of its in-sample performance across many windows, the rules capture something persistent. If out-of-sample collapses, the rules captured the sample.

The "other side" here is your own hindsight-bias and overconfidence. The protocol exists to protect you from yourself, and it works only when you refuse to peek at the out-of-sample data while designing.

Setup rules

  • Data: the longest clean history you can get, survivorship-free, with realistic costs and a one-bar execution lag built into the simulator before any test begins.
  • Window sizes: in-sample windows long enough to contain at least 100 trades (for a daily-bar swing system, often 3 to 5 years); out-of-sample windows of one quarter to one third of the in-sample length. Anchored (growing in-sample) or rolling (fixed length) are both acceptable; rolling adapts faster and is noisier.
  • Parameter grid: a small, coarse grid decided before testing (for example, lookbacks of 20, 50, 100, 200, not every integer from 10 to 300). Fewer choices mean less overfitting.
  • Selection rule: choose the in-sample parameter set by a robust metric (profit-factor or return-to-drawdown), and prefer a parameter in the middle of a stable region over the single best point; a peak surrounded by cliffs is noise.
  • Frozen application: apply the chosen parameters to the out-of-sample window without any adjustment; record every trade.
  • Roll: advance both windows by the out-of-sample length and repeat until history is exhausted.
  • Judge: evaluate the strategy only on the stitched out-of-sample trades. The in-sample results are discarded as evidence.

Entry, stop, target

The protocol does not have entries and stops; the strategy under test does. What the protocol produces is a set of out-of-sample statistics that decide whether the strategy is deployed at all. The table shows what a walk-forward run looks like for a hypothetical swing system.

Window In-sample years Chosen lookback In-sample profit factor Out-of-sample year Out-of-sample profit factor
1 2008 to 2012 50 1.9 2013 1.4
2 2009 to 2013 50 1.8 2014 1.3
3 2010 to 2014 100 1.7 2015 0.9
4 2011 to 2015 100 1.7 2016 1.5
5 2012 to 2016 50 1.8 2017 1.2
Stitched 2013 to 2017 About 1.25

A walk-forward efficiency (out-of-sample divided by in-sample performance) around 50 to 70 percent is typical for a real effect; near 100 percent is suspicious (the parameters are barely doing anything, which can be fine) and near zero means the in-sample result was fitting.

Position sizing and risk

Walk-forward results are the input to sizing, not the output. The out-of-sample max-drawdown is the number to plan around, and even that understates the future, because the worst drawdown of the next decade is usually deeper than the worst of the last one. A common rule is to size a system so that 1.5 to 2 times its out-of-sample maximum drawdown is survivable within the limits at /learn/risk-management; /tools/position-size applies to each trade within the system once the per-trade risk is set.

What breaks it

  • Peeking. Looking at the out-of-sample results, adjusting the grid or the rules, and re-running. After the second iteration the out-of-sample data is in-sample in everything but name. Keep a log of every test run; if the log is long, the result is contaminated.
  • Too many parameters. A strategy with six tunable inputs can be walk-forward tested and still be overfit, because each in-sample window will find some combination that works. Fewer parameters, coarser grids.
  • Too few windows. A walk-forward with two out-of-sample windows is an anecdote. Aim for at least 5, preferably 10.
  • Regime concentration. If all out-of-sample windows fall in one regime (a decade-long bull market), the test says nothing about the other regime.
  • Costs. Underestimated costs make a break-even strategy look profitable in every window; set costs pessimistically before the first run.
  • Edge decay. Walk-forward cannot tell you whether the edge will survive; it can only tell you whether it existed in the past. A declining out-of-sample profit factor across windows is the closest thing to a warning it offers, and it should be taken seriously.

How to test it

The protocol is the test. To check that your implementation of it is honest, run it on a strategy you know is random (for example, entries on a coin flip with a fixed stop and target). The stitched out-of-sample profit factor should hover around what costs imply (below 1.0). If your random strategy walks forward profitably, there is a bug or a leak (look-ahead in the data, a target that uses the close of the bar it is filled on, a survivorship-biased universe). Do the same with a deliberately overfit strategy (100 parameters, tiny in-sample); it should fail out of sample. Only after both controls behave should you trust the protocol on a real candidate.

Variations

  • Anchored walk-forward: in-sample always starts at the beginning of history and grows; more data, slower adaptation.
  • Combinatorial purged cross-validation: a more advanced scheme that tests many train-test splits while removing overlapping trades; better statistics, harder to implement.
  • Parameter-free strategies (a fixed rule with no tuning, such as trend-following-200-day) that can be tested on the full history without walk-forward, because there is nothing to fit; still check robustness by perturbing the rule.

Further reading

backtesting, sample-size, profit-factor, max-drawdown, survivorship-bias, hindsight-bias, overconfidence, confirmation-bias, paper-trading, edge.

Related playbooks: expectancy-system-evaluation, systematic-momentum-rules, dual-momentum, credit-spread-program

See it drawn

Original diagrams for the ideas on this page. Illustrative, not real market data.

The spread of outcomes behind an expectancyA histogram of forty trades: a tall block of small losses on the left, a low spread of larger wins on the right, and a line marking the average outcome.NUMBER OF TRADES051024 LOSSES, AVG −$20016 WINS, AVG +$600EXPECTANCY +$120−$400−$200$0+$200+$400+$600+$800PROFIT OR LOSS PER TRADEexpectancy = (40% × $600) − (60% × $200) = +$120 per trade
Expectancy: the average trade. Forty trades sorted by outcome: 24 small losses and 16 larger wins. Weighting each side by how often it happens gives the average result per trade, marked here by the dashed line at +$120.
An equity curve and its drawdownAn account balance rising over a year, falling from a peak to a trough, then climbing back to the old peak.ACCOUNT EQUITY$20k$12k$8k024681012TIME (MONTHS)PEAK $16,000TROUGH $12,000DRAWDOWN−25%RECOVERY
Equity curve and drawdown. An account balance plotted month by month. The fall from the $16,000 peak to the $12,000 trough is a 25% drawdown, and the shaded area lasts until the balance climbs back to the old peak.

Educational only, not advice. Spotted an error? Post in Site Feedback.