FAQ · Getting systematic research right

How do I split data into in-sample and out-of-sample?

Split by time, never at random. Use the earlier part of your history, often about 70%, to build and tune the strategy, and keep the later 30% untouched until you have stopped changing it. Test once on the held-out part; if you tune again after seeing it, it is no longer out-of-sample.

Split by time, never at random. Use the earlier part of your history, often about 70%, to build and tune the strategy, and keep the later 30% untouched until you have stopped changing it. Test once on the held-out part; if you tune again after seeing it, it is no longer out-of-sample.

Why the split is by time

In most machine learning, rows are shuffled before splitting. Market data cannot be shuffled: neighbouring bars are related, and a strategy trained on bars from both sides of a test bar has effectively seen it. A time split keeps the test data strictly in the future of everything the strategy learned from, which is the position you will be in when you trade it.

How much to hold out

There is no single right ratio. What matters is that each part holds enough trades to mean something.

  • Count trades, not years. A test period with 15 trades cannot tell a good strategy from a lucky one. Aim for at least 30 to 50 trades in the held-out part, more for a high-frequency rule.
  • Cover different markets. If the in-sample period is all a rising market, an out-of-sample period that includes a fall tells you more than one that does not.
  • 70/30 or 80/20 is a common start. With a long history, a three-way split (build, validate, final test) lets you compare a few candidates on the middle part and still keep a clean final test.

Keeping it clean

The out-of-sample set loses its value the moment it influences a decision. That includes:

  • tuning parameters, then checking the test set, then tuning again;
  • trying ten strategies and keeping the one that did best on the test set;
  • adjusting the rules after looking at the test set's equity curve.

Each of these turns the test data into training data. Write down the selection rule before you run the test, run it once, and accept the answer. If you need many rounds of testing, use walk-forward testing, which builds repeated out-of-sample tests into the process.

Gaps between the two parts

If your strategy uses a 200-bar moving average, its first out-of-sample signals depend on the last 200 in-sample bars. That is normal and not a leak: those bars were known. What leaks is anything fitted on the out-of-sample period, such as a normalising mean, a volatility estimate or a hedge ratio. Fit those on the in-sample part only and carry the fitted values forward.

Some practitioners also leave a short gap (an embargo) between the two parts, so that trades open at the end of the training period do not overlap the test period.

How Reamer Research handles it

Reamer Research takes start= and end= on every run as epoch seconds UTC, both inclusive, so the in-sample and out-of-sample parts are two time ranges over the same file:

import reamer_research as rr

split = 1_640_995_200                     # 2022-01-01 00:00:00 UTC
ins  = rr.backtest(MyStrategy(), 'SPY.bin', end=split - 1)
oos  = rr.backtest(MyStrategy(), 'SPY.bin', start=split)
print(ins.sharpe_ratio, oos.sharpe_ratio, oos.closed_trades_count)

MyStrategy can be a class, a configured object or a plain function on_bar(data). The warmup for indicators starts inside each range, so the out-of-sample run uses only bars from its own range for its first window. Runs are byte-identical at a fixed seed, so running the held-out test again gives the same answer and you are never tempted to rerun it until it looks better.

Limits to know

  • Discipline is yours. The engine can run any range you ask for, including the test range a hundred times.
  • Long histories need a licence. Evaluation Mode runs one ticker over at most 30 days of bars.

A $20 month includes the full kit, so you can run both halves on your own history and cancel if it does not fit.

Every answer here restates the documents that ship in the kit, which are authoritative. All questions.

Reamer Research

Your first backtest in a minute

Backtesting and live trading in Python and C++. Free to install in Evaluation Mode, with no key or sign-up.

pip install reamer-research

A licence at $20 a month removes every limit. The same code runs unchanged.

Reamer Server

The order-management core for your firm

Your venues, your risk rules on every order, one strategy per CPU core, on your own Linux servers.

$24,000 / year

Or start with a 30-day trial at $2,000.