Our partnerSkilling
  • Spreads from 0.1 pips
  • 1,000+ instruments
  • Free demo account

65% of retail investor accounts lose money when trading CFDs with this provider.

Open account
Module 5 · Test the robot properly

5.2 Optimisation and overfitting

Lesson 15 of 19Reading time: 2 min

The strategy testers can optimise: try thousands of combinations of settings and find the one that gave the best result. It sounds smart. It is also the most common way to fool yourself.

Backtest (data the robot is fitted to)Live / new dataOverfitted: 15 parametersSimple: 3 parametersIllustration. A perfect backtest is often a warning sign – not a seal of quality.
A strategy fitted to history in detail looks fantastic in the backtest – and falls apart on new data.

Overfitting

Overfitting means that the robot is fitted to the noise in historical data – not to a pattern that repeats. The more settings you optimise, and the more combinations you try, the greater the danger.

Marcos López de Prado shows in Advances in Financial Machine Learning that when you test enough variants, some of them will always look good – purely by chance.

How to protect yourself

1. Split the data. Optimise on the first 70% of the period (in-sample), and test on the last 30% that the robot has never “seen” (out-of-sample). If the result there is much worse, the robot is probably overfitted.

2. Walk-forward. Robert Pardo describes in The Evaluation and Optimization of Trading Strategies a method where you repeat this several times forward in time:

Walk-forward: optimise on one window, test on the nextRound 1Optimisation (in-sample)TestRound 2Optimisation (in-sample)TestRound 3Optimisation (in-sample)TestRound 4Optimisation (in-sample)TestTime
Walk-forward: optimise on one window, test on the next, and move the window forward.

3. Few settings. A robot with three settings is far more robust than one with fifteen.

4. Look for plateaus. A good setting sits in the middle of an area where many values give good results. If only an MA of 17 works, while 16 and 18 lose, 17 is probably chance.

5. Test several markets. A robust idea often works – at least reasonably – on several similar markets.

Kevin Davey’s rule of thumb

Kevin Davey, who has placed among the best in the World Cup Championship of Futures Trading, writes in Building Winning Algorithmic Trading Systems that he expects live results to be significantly worse than the test. He also lets new strategies run for a period on paper or demo – incubation – before using real money.

Try it yourself

Optimise one setting on 2018–2022, and test the best value on 2023–2025. Did the result hold?

Key takeaways

  • Overfitting is when the robot is fitted to noise in historical data.
  • Split the data, use walk-forward and keep the number of settings low.
  • Good settings sit on plateaus – not on isolated peaks.
Practise what you have learned – without riskTry it on a free demo account with Skilling, with real prices and virtual money.
Open a free demo account

65% of retail investor accounts lose money when trading CFDs with this provider.