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 needsdf['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
- Find where each order fills and confirm it is after the bar that produced the signal.
- Find the costs and set them to realistic values.
- Find anything computed over the whole data set before the loop, and move it inside the loop or into an in-sample period.
- Delay every signal by one bar. If most of the return disappears, there was a leak.
- Run it twice. If the numbers change between identical runs, find out why before trusting either.
- 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.