Skip to content
Wildflower
Join waitlist

In-sample and out-of-sample testing: what they mean

By Bec, futures trader and founder of Wildflower · Updated

In-sample is the part of the price history you use to build and adjust a strategy’s rules. Out-of-sample is a part you keep back and test the finished rules on once, unchanged. It shows how the rules behave on prices they weren’t shaped to fit.

In-sample: build and adjustOut-of-sample: test once
A made-up example: the rules from the overfitting page, built on the left, tested once on the right.
In-sampleOut-of-sample
A made-up example: the rules from the overfitting page, built on the left, tested once on the right.

What in-sample and out-of-sample mean

A runs a strategy’s rules over past prices. While you build a strategy, you look at those results, change a rule, run it again, and so on. The history you do that on is : it’s inside the sample the rules were shaped on.

history is history you set aside before you start and don’t look at. When the rules are finished, you run them on it once, without changing anything. It’s the closest a backtest gets to prices the rules have never seen.

Think of practice questions and a real exam. A student who has seen the practice answers can score well on them by memory. The exam, with new questions, shows what they actually learned.

Why traders keep some history back

Every time you adjust a rule after seeing a result, the rules fit that history a little better. Some of that fit is real. Some of it is fitting the noise: moves that happened once and won’t happen the same way again. That’s called . Read about overfitting.

In-sample results can’t tell those two apart, because the rules were tuned to look good there. Out-of-sample history wasn’t used to tune anything, so it’s a fairer check. If the rules only fitted noise, they tend to look quite different on it.

How to do an out-of-sample test, step by step

Here’s the made-up example from the overfitting page. The rule buys when a candle closes above the highest high of the 3 candles before it, with a stop 2 points below the entry and a target 3 points above, plus two extra rules, added along the way, that skip some signals. It isn’t a strategy, only a way to show the method.

In-sampleOut-of-sample

1. Split the history before you look

Decide where the line goes first. Here the first 24 candles are in-sample and the last 16 are kept back.

In-sample

2. Build and adjust on the in-sample part

Test, change, test again, as much as you like. Here the finished rules take two trades, and both reach their targets.

Out-of-sample

3. Run the finished rules once on the rest

Same rules, same settings, no changes. Here they take three trades: one target and two stops.

2 targets1 target, 2 stops

4. Compare the two

Put the two results side by side. Here they look quite different. That’s the sign to look into.

Five trades in all is far too few to say much either way. It’s a picture of the method, not a result. Read about sample size.

Ways to split the history

Two parts, in time orderBuildTestBuild first, then test what came after.
Three partsBuildCheckTestChoose on the middle, test once at the end.

By time. Many traders keep the most recent stretch back. Then the test runs on prices that came after the ones the rules were built on, the way live trading does.

Three parts. Some split the history in three: build on the first, check and choose between versions on the second, then run one final test on the third. The middle part is often called validation. Once you’ve chosen a version using it, it’s in-sample too.

Another market. Some test finished rules on a different but similar market, or a different year, as a second kind of out-of-sample.

Again and again. repeats the split through the history: build on one window, test on the stretch after it, move on. Read about walk-forward testing.

How much to keep back has no single answer. Some keep back a share of the history, others the most recent months or years. Many decide before looking at any results, and check that each part holds enough trades to mean something.

What keeps a test out-of-sample, and what doesn’t

Run once, unchanged✓A fair test of these rules.
Changed after looking✕Now it’s in-sample too.
Very few tradesOne trade says very little.

Once, unchanged. The finished rules run on the kept-back part one time. That’s what makes it a test.

Looking, then changing, uses it up. Say you see the result above and add rule 4: skip a signal candle whose body is under 1 point. It removes the first stop on the right. But now those candles helped write the rules. They’re in-sample, and there’s no fresh history left to test on.

Peeking counts too. Glancing at the kept-back chart while building, or trying ten versions on it and keeping the one that looks good there, has the same effect. The more times it’s used, the less it can tell you.

Too short says little. A kept-back part with one or two trades can look good or bad by chance alone.

No future prices. A rule mustn’t use anything it couldn’t have known at the time, in either part. That’s a different mistake, called .

Reading an out-of-sample result

  • Similar to in-sample. A sign the rules aren’t only fitted to the in-sample stretch. It isn’t proof: one stretch of history can look similar by chance.
  • Very different. The rules may be overfit. Or the market may simply have behaved differently in the kept-back stretch, such as a quiet year after a busy one.
  • Few trades either side. Neither result says much yet. More history, or another market, may help.

Whatever it shows, an out-of-sample test is still a backtest. Live trading adds fills, slippage and fees. Read why backtest and live results differ.

Where the terms come from

Both terms come from statistics, where a model fitted to one set of data is checked on data it wasn’t fitted to. In machine learning the same split is called a training set and a test set, and the kept-back part is sometimes called a holdout. Traders use the words for strategy rules and price history.

Often confused with

Walk-forward testing. Many in-sample and out-of-sample splits in a row, moving through the history. This page is one split. Read about walk-forward testing.

Forward testing. Running the finished rules on new prices as they happen, often on a demo account. It’s out-of-sample by nature, because those prices didn’t exist when the rules were built. Read about forward testing.

Sample size. How many trades a test holds. An out-of-sample test with very few trades is still a small sample. Read about sample size.

Testing your own rules on dates you kept back

Choose your dates, build, then test once

Wildflower’s Backtest runs your own rules over the dates you pick and draws every trade on the chart. So you can build and adjust your rules on one stretch of dates, then run the same version, unchanged, on dates you kept back. Each result is saved with its version and its dates in My backtests, so you can see which dates each version has been run on. Compare two runs shows what changed between two versions of your rules. Nothing is marked or ranked. What you make of it is up to you.

Telling Backtest your rules in your own words.

Free on a practice chart

Common questions

What is out-of-sample testing?

Running finished rules, unchanged, on history you kept back while building them.

What is in-sample data?

The part of the price history you use to build and adjust a strategy’s rules.

What is the difference between in-sample and out-of-sample?

In-sample history shaped the rules. Out-of-sample history didn’t, so it’s a fairer check of them.

How much data should be out-of-sample?

There’s no single rule. Some keep back a share of the history, others the most recent months or years. Many also check that each part holds enough trades to mean something.

Can I change my strategy after an out-of-sample test?

You can, but then that history has shaped the rules, so it’s in-sample. A new test needs history the new version hasn’t seen.

Is out-of-sample the same as walk-forward testing?

Walk-forward testing is many in-sample and out-of-sample splits in a row. Read about walk-forward testing.

Why do my out-of-sample results look worse?

It may be overfitting, a market that behaved differently, or chance with few trades. The test shows the gap. Finding the reason is up to you.

Does a good out-of-sample result mean a strategy works?

No. It means the rules held up on one stretch they weren’t tuned on. Another stretch, or live trading, can look different.

What is a validation set?

A middle part some traders use to choose between versions before a final test. Once it’s used to choose, it counts as in-sample.

Learn it step by step in Wildflower Trading School, starting with the lesson “In-sample and out-of-sample data”.

In the help centre