How to backtest a trading idea with Claude or ChatGPT
A chatbot on its own can’t backtest: it has no price history and will make numbers up. Connect it to a tool that runs backtests on real data, and you can ask in plain words — “test a 50/200-day cross on SPY over 10 years” — and get the result next to buy and hold, year by year, with every trade and with costs included. With TradePuffin, Claude, ChatGPT or Gemini does this through its backtest tool, on one symbol or a whole watchlist.
Why you can’t just ask a chatbot
Without data, a model answers from memory: a plausible-sounding win rate, invented returns, no trades you can check. Even with a pasted CSV, it may do the arithmetic wrong. A backtest tool runs the rules on actual bars and returns figures you can audit.
A worked example: the 50/200-day cross on SPY
The “golden cross” — buy when the 50-day average crosses above the 200-day, sell when it crosses below — is often called a way to avoid crashes. We asked the agent to test it on SPY over 10 years, with commission and slippage:
| 50/200 cross | Buy and hold | |
|---|---|---|
| Total return | +97.2% | +260.9% |
| Per year | 7.0% | 13.7% |
| Worst drop | −29.3% | −34.1% |
| Trades | 4 | — |
The agent’s verdict: it didn’t beat buy and hold. It softened the worst drop a little but gave up most of the gain, and four trades in ten years are too few to judge by. That is the useful kind of answer — it stops you relying on an idea that sounds good.
How to do it
- Connect TradePuffin to your AI app (Claude, ChatGPT, Claude Code).
- Describe the rules in plain words: when to buy, when to sell, which symbols, how many years.
- The agent picks a built-in template or writes the rules as a short script, then calls
backtest. - Read the result next to buy and hold, then ask for the year-by-year breakdown and the trade list (
get_backtest). The run is saved in your app too. - Change one thing at a time — costs, period, symbols — and test again.
How to read a backtest honestly
- Compare with buy and hold. Making money in a rising market proves little; beating holding is the bar.
- Count the trades. Under 30 or so, results are mostly luck.
- Split the period. If it only worked in one half, or one year, be wary.
- Test many symbols. An idea that works on one stock and fails on the rest is probably fitted to that stock.
- Include costs. Commission and slippage turn many fast strategies negative.
- Don’t tune until it works. Trying settings until the past looks good guarantees a disappointing future.
Prompts to copy
Backtests are hypothetical and use past data; they don’t predict future results. The SPY figures are from a real run on TradePuffin, 10 years of daily bars to November 2026, with default commission (0.05%) and slippage (0.02%).
More guides
- How to let ChatGPT or Claude analyze stock charts
- How to scan the stock market with an AI agent
- The best MCP servers for stock charts and technical analysis (2026)
- How to get AI to draw support, resistance and trend lines on a chart
For information and education only; not investment advice. See the Disclaimer.