How to Backtest an AI Trading Agent Before Going Live
A regime-by-regime method for backtesting agentic strategies, the report numbers that actually matter, and why LLM-driven backtests flatter themselves.

An agent you built from a plain-language prompt feels tested the moment it restates your strategy correctly. It isn't. Restating is comprehension; backtesting is evidence. Before any agent touches live capital, you want to know how its exact rules would have behaved through years of real market history, and to backtest an AI trading agent well you need three things: rules pinned down tightly enough to replay, test periods hostile enough to matter, and the discipline to read the report as a critic rather than a fan. This guide covers all three, plus a failure mode unique to LLM-driven strategies.
Pin the rules down until a machine could replay them
A backtest replays your logic against historical data, candle by candle. That only works if every decision your agent makes is computable from data that existed at that moment. "Buy when RSI(14) daily closes below 30 and price is above the 200-day moving average" replays perfectly. "Buy when the news feels overdone" does not, because "feels" isn't in any candle.
So the first job is turning your agent's restated conditions into a complete specification. A useful test: could a spreadsheet with historical prices and your rules decide every entry, every exit, and every position size, with no judgment calls left over? If a rule needs interpretation, the backtest engine will interpret it somehow, and its interpretation becomes your strategy without your consent.
Watch the quiet parameters too. Slippage and fees assumptions, order type (a market order fills; a limit order sometimes doesn't), and what happens to signals outside market hours for stocks. If you're new to how these engines work in general, our guide to backtesting software covers the fundamentals; this article stays focused on what's different for agents. And if you haven't yet defined entry, exit, size, and invalidation for your strategy, do that first; it's step two of creating an AI trading agent.
How to backtest an AI trading agent across market regimes
A strategy tested only on the recent past is a bet that the recent past continues. The fix is deliberate: pick test windows that stress different failure modes, and require the agent to survive most of them. Four regimes from the last decade cover a lot of ground:
| Period | What it was | What it stresses |
|---|---|---|
| 2018 | Grinding bear (crypto down ~80%, equities' sharp Q4 slide) | Exit discipline, DCA pain tolerance, death-by-a-thousand-cuts |
| Feb–Mar 2020 | Vertical crash, then V-shaped recovery | Stops under gap moves and slippage, whether you re-enter or stay scared |
| 2021 | Persistent melt-up | Whether shorts and mean-reversion rules fight the tape, premature profit-taking |
| 2022 | Rising-rate drawdown, stocks and crypto falling together | Correlation assumptions, trend filters, drawdown caps |
Run the agent's rules through each window separately, not just one long average. A dip-buying rule can shine in 2020 and 2021, then donate everything back in 2022; a single aggregate number hides that story. You're not demanding profit in all four regimes. You're demanding to know, in advance, which regime hurts your agent and whether its invalidation rule fires before the damage compounds.
This is where tooling matters practically: on Obside, the backtesting engine replays years of historical data in minutes with slippage assumptions built in, so testing four windows is four runs before lunch rather than a weekend project. Whatever engine you use, the principle stands: regimes, not averages.
Read the report like an adversary
A backtest report is a sales pitch written by your own hopes. Read each number for what it can and cannot tell you.
Sharpe ratio measures return per unit of volatility. Between roughly 0.5 and 1.5 is the honest zone for most retail strategies; a Sharpe above 3 in a backtest is more often a bug, a bias, or an overfit than a discovery.
Maximum drawdown is the deepest peak-to-trough loss. Compare it to what you can genuinely sit through, then assume live will be worse, because the historical worst case is a floor, not a ceiling.
Win rate means nothing alone. A 90% win rate with small wins and rare catastrophic losses describes a strategy that picks up coins in front of a roller; pair it with the average win/loss ratio before admiring it.
Trade count is your sample size. Under about 30 trades, you have an anecdote. Under 10, you have a story.
Exposure tells you how long capital sat in the market to earn the return, which is the risk the equity curve doesn't show.
Then run one stress variation: double the slippage and fee assumptions and rerun. Strategies that trade often, or trade thin assets, can watch their edge evaporate in that single test. If small parameter changes (RSI 30 versus 32, stop at 4% versus 5%) collapse the results, you're likely staring at curve-fitting; that whole failure family is dissected in our guide to backtest overfitting.
The LLM caveat: when the model already knows the ending
Agentic strategies introduce a failure mode classic bots never had. If a large language model makes decisions inside the backtest loop (picking assets, timing entries, weighing news), its training data may contain the very history you're testing on. The model isn't predicting 2021; it's remembering it.
This isn't hypothetical. Research on LLM-based investing strategies found backtests inflated by memorization and lookahead: models whose training data overlaps the test window can recall tickers, dates, and price moves, and performance often degrades out-of-sample ("Can LLM-based Financial Investing Strategies Outperform the Market?", arXiv:2505.07078, 2025). A follow-up memory-controlled benchmark showed that when memorized market history is properly excluded, the apparent skill of LLM trading agents drops sharply (arXiv:2605.28359, 2026). A survey of the field flags the same pattern across studies: short test windows, small universes, and lookahead risk (arXiv:2408.06361, 2024).
Two practical defenses. First, if an LLM decides trades, only trust test windows after its training cutoff, which usually leaves you months of data, not years. Second, and better for most retail use: keep the LLM out of the replay loop entirely. Let it translate your strategy into deterministic rules once, then backtest those rules the classical way. This is how Obside is built: the copilot interprets your language, but the backtest replays fixed conditions against historical candles, so there's no model in the loop to remember the answers.
Graduation criteria: what a passing backtest looks like
Before moving on, write down what "pass" means, then check the report against it coldly. A reasonable bar:
- Survives at least three of the four regimes, meaning losses stayed inside the invalidation rule, even where it wasn't profitable.
- Maximum drawdown at or below the number you declared tolerable before running the test.
- At least 30 trades across the full test, enough to mean something.
- Still positive after doubling cost assumptions.
- Neighboring parameter values give similar results, a plateau rather than a single magic peak.
- You can explain its worst losing streak in plain words: what market condition caused it and why the strategy is still sound.
Miss on one criterion and you have a redesign target. Miss on three and you have a different strategy to find. And a full pass still isn't permission to go live: a backtest can't test the translation of your intent on live data, execution timing, or your own behavior watching real drawdowns. That's what the next stage is for, and the same agent definition should move there unchanged; the case and the checklist live in our guide to paper trading an AI agent.
Where to go from here
Backtesting an agent is less about finding great numbers than about buying information cheaply: which regime breaks your rules, what your worst month looks like, whether costs eat the edge. Every one of those discoveries costs nothing in a backtest and real money live. Pin the rules, run the four regimes, read the report like an adversary, and keep any LLM away from the replay loop. When you want an engine that replays years in minutes, bakes in slippage, and promotes the exact same agent to paper trading in one step, run your next backtest on Obside.
Educational content only. This is not investment advice. Trading involves risk, including possible loss of capital.
FAQ
Far enough to include at least one bear market, one crash, and one strong rally; for most strategies that means five or more years. Length matters less than variety: three years covering 2020 through 2022 teaches more than eight years of steady bull market. For faster strategies, also confirm the sample size, since 30-plus trades is a reasonable floor before the statistics mean much.