Out-of-sample testing: how to check a backtest
By Oalgo · Last reviewed
Out-of-sample testing means building and tuning your rules on one part of the past prices, the in-sample part, and then checking them once on a later part they were never tuned on, the out-of-sample part. It is a way to catch rules that only fit the stretch they were tuned on, which is overfitting.
How does the split work?
#- Cut the past prices by time, for example the first 70% for in-sample and the last 30% for out-of-sample. The later part is always the out-of-sample part, so the rules never see the future.
- Tune: change rules and settings only while looking at the in-sample part.
- Check: run the finished rules once on the out-of-sample part. If you change the rules after looking at the result, that part has become in-sample too.
- Compare the two parts: the number of trades, the win rate, the largest fall and the change in account value.
| Made-up example | Candles | Used for |
|---|---|---|
| In-sample | 1 to 700 | Building and tuning the rules |
| Out-of-sample | 701 to 1,000 | One check of the finished rules |
How do you read the two parts?
#| What you see | What it suggests |
|---|---|
| Similar numbers in both parts, with a fair number of trades in each | No sign that the rules were tuned to the first part. It does not show how they will behave on new prices. |
| Much weaker numbers in the out-of-sample part | A possible sign of overfitting, or that the market changed after the cut. |
| Very few trades in the out-of-sample part | Too few to say anything. |
| Better numbers out-of-sample than in-sample | Can happen by chance, and says little when there are few trades. |
What does the Oalgo backtest report show?
#The Risk tab of the report has a card named Did It Hold Up?. It cuts the run by time into the first 70% (In-sample) and the last 30% (Out-of-sample) and shows the number of trades, the win rate, the largest fall and the change in account value for each part. A line under the card says the later part holds up when its change is zero or more, or more than half the change of the earlier part. If the later part has no trades, the card says there is nothing to check yet.
This card divides the results of one run you have already seen in full. It does not stop you from having tuned the rules on the whole range first, so it is a quick check and not a clean out-of-sample test. For a clean one, tune on an earlier part of the past prices, then run the finished rules once on a later part, or forward test them on new prices, which cannot have been tuned on.
What can out-of-sample testing not tell you?
#- It uses one cut. A lucky or an unlucky cut can mislead, so try more than one.
- It can be used up. Each time you look at the out-of-sample part and change the rules, it becomes less of a fresh check.
- The later part can be a different kind of market from the earlier one, which says something about the market and not about the rules.
- It does not prove the rules will hold up on new prices. It makes a chance fit easier to spot.
The backtest report guide shows where the other numbers sit. A backtest itself is the run that the split cuts in two.
In Oalgo you can tell Oalgo AI your rules in your own words, check the rules it builds, and test them on one part of the past prices and then on another. After testing, if you choose, you Go Live with your own Live Strategy on your own Venue Account at a Supported Venue.
Read next
- What is overfitting?Overfitting is tuning rules so closely to past prices that they stop working on new ones. Learn why it fools people and how to check for it.
- What is forward testing?Forward testing runs your rules on new prices as they arrive, with simulated funds only. Learn how it differs from a backtest and when to use it.