Skip to content

Out-of-sample testing and walk-forward analysis, explained

Optimising a strategy on a block of history and then judging it on the same block tells you how well you fitted the past, not how it may behave next. Out-of-sample testing and walk-forward analysis are the standard ways to ask the better question: does the rule still work on data it was not tuned on?

In-sample and out-of-sample

In-sample data is what you use to design and tune the strategy. Out-of-sample data is held back and used only to judge the finished result. The out-of-sample result is the more honest estimate, because the strategy had no chance to adapt to it.

How to split the data

  • Split by time, not at random: use earlier data for tuning and later data for testing, so that the test mimics the real order of events.
  • Keep the out-of-sample block large enough to contain a meaningful number of trades and more than one type of market condition.
  • Decide the split before you look at results.

The main trap: peeking

If you look at out-of-sample performance, change the strategy, and test again, the out-of-sample block has quietly become part of the tuning. After a few rounds it is no longer out of sample. Use it sparingly, ideally once, and keep a fresh final block if you can.

What walk-forward analysis does

Walk-forward analysis repeats the process through time. You optimise on one window, test on the window that follows, then roll both forward and repeat. The stitched-together test windows form one out-of-sample record that was generated the way you would actually have used the strategy.

  • Choose a training window and a test window, for example a longer period to tune and a shorter one to test.
  • Optimise only on the training window, then record results on the test window without changing anything.
  • Slide both windows forward and repeat until the data ends.
  • Judge the combined test results, and check how stable the chosen parameters are from one window to the next.

What to look for

  • Test results that are broadly consistent with training results, rather than far worse.
  • Parameters that stay in a similar range between windows.
  • Acceptable results in most windows, not only a few.
  • Costs and slippage included in every window.

Limits

Neither method proves a strategy will work. Markets change, and a stable past can be followed by a different regime. These tests reduce the chance of being fooled by a fitted result; they do not remove risk.

Where TradeCC fits

In TradeCC the evaluation plan in a strategy draft shows the date range, time zone, out-of-sample split and spread or cost before you confirm a backtest in the conversation, so you can check that the split was fixed before you saw any result and that costs are included. You can also describe your own test design to CC and ask whether it leaks future information. It is a research aid, not investment advice.

Frequently asked questions

What fraction of the data should be out-of-sample?

There is no fixed rule. It should be large enough to hold a meaningful number of trades and several market conditions; many practitioners hold back a substantial minority of the sample.

Why not split the data randomly?

Financial data has a time order and the future must not influence the past. Random splits can leak information from later periods into the training data and make results look better than they would be in real use.

Is walk-forward analysis the same as a live test?

No. It is a more realistic historical simulation. A forward test on new data as it arrives, even with a practice account, is a separate and valuable step.

Related guides

Research reference only — For research reference only; not investment advice and not an offer or solicitation to trade. Data may be delayed, incomplete or revised, and some content is compiled by AI from third-party sources. Check important facts against original sources before you rely on them.