FAQ · Getting systematic research right

Why do AI-written backtests give misleading results?

AI assistants write backtests that run but often trade on the signal bar, leave out costs, fit values on the whole history, or test today's survivors. The code looks right and the numbers look great. Check the fill timing, the costs and the data the same way you would check a person's code, or run the strategy on an engine that enforces the timing for you.

AI assistants write backtests that run but often trade on the signal bar, leave out costs, fit values on the whole history, or test today's survivors. The code looks right and the numbers look great. Check the fill timing, the costs and the data the same way you would check a person's code, or run the strategy on an engine that enforces the timing for you.

Why it happens

An assistant writes the most common pattern it has seen, and the most common backtesting code online is a short pandas script. Those scripts are written to show an idea, not to model trading, so they usually skip the details that decide whether a result is real. The assistant also has no way to tell a good backtest from a broken one: both run without errors, and a broken one often prints better numbers.

The usual mistakes

  • No shift on the signal. df['ret'] * df['signal'] on the same row trades a return the signal already used. It needs df['signal'].shift(1). See look-ahead bias.
  • Fills at the signal bar's close. The decision is made at the close, so the fill can only come after it.
  • No costs. Commission, spread and slippage are left at zero, which flatters any rule that trades often. See how realistic costs need to be.
  • Stops that fill at the stop price. A stop hit by a gap fills at the next available price, often far worse.
  • Whole-sample statistics. A z-score, scaler or hedge ratio computed over all the data, then used at every bar.
  • A fixed list of today's tickers, which builds in survivorship bias.
  • Invented library calls. A method name that looks plausible but does not exist, or exists with different arguments. This one at least fails loudly.
  • Tuning by conversation. Asking an assistant to "improve the Sharpe ratio" ten times is a parameter search over the same data, with the same overfitting risk as any other.

How to check an AI-written backtest

  1. Find where each order fills and confirm it is after the bar that produced the signal.
  2. Find the costs and set them to realistic values.
  3. Find anything computed over the whole data set before the loop, and move it inside the loop or into an in-sample period.
  4. Delay every signal by one bar. If most of the return disappears, there was a leak.
  5. Run it twice. If the numbers change between identical runs, find out why before trusting either.
  6. Ask the assistant to explain each line, then check the explanation against the code yourself.

How Reamer Research handles it

Reamer Research moves the parts assistants most often get wrong out of the strategy and into the engine. The strategy only decides; the engine fills. The window passed to on_bar holds only closed bars, and an order returned from a bar fills from the next bar's ticks, so code written by an assistant cannot fill on its own signal bar. Stops that gap fill at the first tick past the level, and spread, slippage and commission are set in one place on the run:

import reamer_research as rr

result = rr.backtest(strategy, 'SPY.bin', spread=0.01, slippage=0.01, commission_per_unit=0.005)

strategy can be a function on_bar(data), a class or a configured object, and assistants write all three readily. Runs are byte-identical at a fixed seed, so when an assistant changes one line, a change in the result comes from that line. The full order log, with reject reasons, is in result.json(), and result.open_viewer() opens the run in the visual trade diagnostics tool to check each entry and exit against the bars.

There is also a Reamer Research MCP server, so an assistant such as Claude can run the backtest itself and read the real results instead of guessing them.

Limits to know

  • Data and logic are still yours to check. The engine fixes the fill timing; a hedge ratio fitted on the whole history before the run still leaks.
  • No native Windows build. It runs on Linux x86-64, on macOS on Apple Silicon, and on Windows through WSL2.

A $20 month includes the full kit, so you can run an assistant's strategy through it and compare the result with the script it wrote.

Next questions

What is look-ahead bias and how do I find it in my backtest?Look-ahead bias is a backtest using information that was not available when the decision was made, such as filling at the close of the bar that produced the signal or reading data published later. Find it by checking when each value was known, shifting signals by one bar, and seeing whether results collapse.How realistic do slippage and spread need to be in a backtest?Realistic enough that the result survives them. Set spread, slippage and commission per instrument from what your broker actually charges, let spread and slippage widen when the market moves fast, and then rerun at one and a half and two times those costs. A strategy whose edge disappears under slightly higher costs was never a reliable edge.How do I know if my backtest is overfit?You cannot prove a backtest is not overfit, but you can test for the signs. An overfit result holds at one parameter set and collapses at its neighbours, fails on data it was not tuned on, rests on a handful of trades, or disappears once realistic costs are applied. Check each one, on a tool that gives the same answer every run.Why do I get different backtest results each time I run it?Because something in the run is not fixed. Usually it is unseeded randomness, data that changed between runs, an order of operations that is not guaranteed, or a library or setting that drifted. Run the same backtest twice, compare the trade logs, and find the first trade that differs. A seeded engine gives byte-identical output, which leaves your own code and data as the only things to check.

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.