Guide

Paper trading vs backtest: how to verify your live code matches your model

Backtesting fundamentals · ~6 min read

An honest backtest can still fail live for a reason that has nothing to do with markets: your live or paper-trading code doesn't actually implement the same logic your backtest tested. These are almost always two separate codebases, and nothing forces them to agree.

Quick answer

Feed identical historical bars into your backtest engine and your live or paper-trading execution path, bar by bar, and compare the signals and position sizes each one produces. If they diverge on the exact same data, the disagreement is a bug in one of your implementations — not a reflection of real trading conditions — and it needs fixing before you trust either result.

The gap most people never check

A backtesting engine and a live or paper-trading engine are, in almost every retail setup, two entirely different pieces of code. The backtest might be a vectorised pass over a pandas DataFrame. The live engine reacts to bars arriving one at a time from a broker's data feed, maintains running state, and places real orders. They were probably written at different times, sometimes by different people, and nothing automatically keeps their logic in sync.

This means a strategy can have a completely honest, non-overfit, properly out-of-sample-tested backtest — and still lose money live for a reason with nothing to do with markets at all: the live code simply computes a different signal than the backtest did, on the same data.

Where the two implementations quietly diverge

Indicator warm-up and rolling windows

A 50-period moving average needs 50 bars of history before its first value is valid. A backtest running on a long historical file has that history sitting right there. A live engine that just started this morning might not — and if it silently produces a signal anyway using a partially-filled window, that's a different calculation from what the backtest did on the identical timestamp.

Bar timing and when a signal is allowed to act

Does your system decide to trade using a bar's close, or as soon as the next bar opens? A one-bar timing difference between backtest and live execution is one of the most common causes of results that look similar in shape but consistently underperform the backtest in practice.

Look-ahead bias baked into the backtest itself

If the backtest computes an indicator using information that wouldn't genuinely have been available at that point in time — for example, using a bar's own closing price before that bar has actually finished — it will look better than any live implementation could ever replicate, because live trading only ever has truly completed data to work with. This isn't a mismatch between two implementations so much as one of them (the backtest) quietly cheating.

Rounding, position sizing, and order types

A backtest might allow fractional position sizes for simplicity; a live broker often can't. Market orders fill at a different price than the bar close a backtest assumes. These aren't bugs exactly, but they're real-world constraints a backtest can easily omit without anyone noticing until live results start drifting from expectations.

How to actually run the comparison

The most direct check: take a chunk of historical data your live system hasn't seen, and run it through both paths — the backtest engine, and your live or paper-trading engine fed the same bars one at a time as if they were arriving in real time. Then diff the outputs bar by bar: same entry signals, same position sizes, same exit timing. Any disagreement tells you exactly which bar the implementations parted ways, which is usually enough to find the bug.

Why this matters more than another backtest run No amount of additional backtesting will catch this class of bug, because the backtest is one of the two things you're trying to check. The only way to find an implementation mismatch is to run both systems side by side on the same data and look for disagreement.

Why paper trading is still worth doing even after this check

Matching signals on historical data proves your two implementations agree on stored data. It doesn't prove your live data feed is clean, your order handling is correct under a real network connection, or that your system reacts sensibly to a genuinely unexpected market event. Paper trading for a real stretch of time — with real-time data, even if the orders aren't real — is the only step that tests those things, and it's worth doing even when the backtest and live signal logic have already been confirmed to agree.

A simple pre-launch checklist

Get a backtest that's honest from the start

The Honest Backtest Engine builds every signal causally — no indicator ever sees a bar before it closes — so what you validate offline is the same logic you'd wire into a live or paper engine, with no hidden look-ahead to discover the hard way.

See how it works

Frequently asked questions

Why would live or paper trading give different signals than a backtest?

In most systems the backtest and the live execution engine are separate codebases written at different times, so a subtle difference in indicator warm-up, bar timing, or rounding can make them disagree on the exact same data without either side raising an error.

How do I check that my live trading code matches my backtest?

Feed the exact same historical bars into both the backtest engine and the live/paper execution path, bar by bar, and diff the signals and position sizes they each produce. Any disagreement on identical input data points to a bug in one implementation, not a market or performance issue.

What is look-ahead bias and how does it cause this mismatch?

Look-ahead bias is when a backtest accidentally uses information that would not have been available yet at that point in time, such as an indicator computed using a bar's own closing price before that bar has actually closed. It inflates backtest results in a way live trading can never replicate, because live trading only has access to genuinely completed data.

Should I paper trade before going live even after a good backtest?

Yes. Paper trading is the only step that tests your actual execution code, data feed, and order handling under real-time conditions, none of which a backtest exercises. A strategy can have an honest backtest and still fail live purely due to implementation bugs that only paper trading would surface.