Backtesting with LLMs and AI Agents: Avoiding Look-Ahead and Memorisation

LLM backtesting means letting a language model or AI agent propose, run and evaluate trading strategies against historical data. It adds a failure mode classic backtests do not have: the model may already know what happened, because market history was part of its training data.

The memorisation problem

Look-ahead bias is using information that was not available at the decision time — revised macro data, restated financials, fundamentals before their filing date. With language models there is a second, subtler source: the model itself. Research on look-ahead bias in LLM forecasting (arxiv.org/abs/2601.13770) shows that models can recall past market outcomes, so a "backtest" over periods inside the training window may partly measure memory rather than reasoning.

This means an AI agent backtesting a strategy can produce a beautiful equity curve for the wrong reason: not because the strategy works, but because the model remembers how the story ended. Guarding against this requires controls at the data layer, not just better prompts.

Control 1: as_of-pinned tools

The first control is to make it impossible for the data itself to leak the future. On FinzData's remote MCP, every tool accepts an as_of parameter: prices, fundamentals and macro are returned exactly as they were known on that date. Fundamentals come as first reported, usable after the filing's acceptance time; macro series come from ALFRED, which keeps every vintage of FRED series, so the agent sees the number as first published, not today's revision.

When every tool call is pinned to a decision date, the agent physically cannot fetch tomorrow's value — whatever it remembers is all it can cheat with, which brings us to the next control.

Control 2: blind mode

Blind mode hides the tickers from the agent. The model receives the data — prices, fundamentals, macro — but not the identity of the company: tickers in the output are replaced by neutral labels. Without a name to anchor on, memorised associations ("this is the stock that crashed in 2008") have nothing to attach to, and the model is forced to reason from the numbers in front of it.

Blind mode does not prove a strategy is real, but it removes the cheapest form of memorisation and makes the agent's performance a much cleaner signal.

Control 3: trial counting and the deflated Sharpe report

Agents iterate fast — far faster than a human. An agent that tries dozens of variants and reports the best one is running into the same multiple-testing problem as any quant, only at machine speed. FinzData's server-side backtests keep the count for you: every run returns n_trials, a deflated Sharpe ratio and a verdict ("likely real" ≥ 0.95, "inconclusive" ≥ 0.5, otherwise "likely overfit"). The deflated Sharpe ratio (Bailey and López de Prado, 2014) adjusts the Sharpe for the number of variants tried and for non-normal returns — see our explainer.

# An agent's run_backtest call over MCP (POST https://api.finzdata.com/mcp, tools/call):
{"name": "run_backtest",
 "arguments": {"as_of": "2026-10-01",
   "spec": {"universe": "all", "start": "2010-01-01", "end": "2025-12-31",
            "rebalance": "M", "top_n": 20, "costs_bps": 10, "side": "long_short", "blind": true,
            "signal": {"type": "expr", "expr": "rank(ret(252)) - rank(vol(60))"}}}}
# The result includes stats, a benchmark and an "overfitting" block: n_trials, dsr and a verdict.

Connecting your agent

FinzData exposes a market data MCP server built for AI agents. Point your MCP client at https://api.finzdata.com/mcp and create an agent key with POST https://api.finzdata.com/v1/agent/keys. Every tool carries as_of, backtests run server-side with the deflated Sharpe report, and blind mode can be switched on for memorisation-resistant evaluation. The underlying data is survivorship-free US stocks (8,500+ delisted symbols, 231 ETFs), bars from 1-minute to daily since 2000, point-in-time SEC fundamentals, 13F since 2013, COT since 1986 and 20,000+ macro series with every vintage — with a free 12-month tier to start.

FAQ

What is look-ahead bias in LLM backtesting?

Look-ahead bias means using information that was not available at the decision time. With language models there are two sources: the data pipeline (revised macro data, restated financials, fundamentals before their filing date) and the model itself, which may have memorised market history during training.

Can language models memorise market history?

Yes. Research on look-ahead bias in LLM forecasting (arxiv.org/abs/2601.13770) shows that models can recall past market outcomes, so a "backtest" over periods inside the training data may partly measure memory rather than reasoning. This is why as_of-pinned data and blind testing matter.

What is blind mode?

Blind mode hides the tickers from the agent. The model sees the data and must reason about it without knowing which company or period it is looking at, which neutralises memorised associations about specific stocks.

How do I connect an AI agent to FinzData?

Point your agent at the remote MCP endpoint https://api.finzdata.com/mcp and create a key with POST https://api.finzdata.com/v1/agent/keys. Every tool accepts an as_of parameter, backtests run server-side with a deflated Sharpe report, and blind mode can be enabled.