Skip to content
Blog
8 min read

ChatGPT Trading Strategy Backtest: A Workflow That Holds Up

A ChatGPT trading strategy backtest workflow: why numbers in a chat are not results, prompts that produce runnable code, audit prompts for lookahead and fees, and real-data runs.

By Polarline Markets team

Asking ChatGPT "would this strategy have worked?" is the fastest way to get a confident answer that nobody measured. ChatGPT can help a great deal with a backtest: it can sharpen the idea, write the code, and audit it. The measuring still has to happen in code that runs on data you can identify. This guide gives you a workflow for each step.

Chat numbers are not backtest results

If a reply says a strategy returned 18% a year with a Sharpe of 1.4, ask where that number came from. Unless you can see the code that produced it, the data it used, and the trades it made, the figure is a plausible guess. Some ChatGPT setups can run code on files you upload; even then, check which data file was used and read the code before you trust the output.

→
Why this matters
In our ScoutBench AI trading benchmark, no agent scored above 28.3 out of 100 on hallucination resistance, which tests whether an agent invents tickers, fields, prices, or APIs. Treat unsourced numbers from any model as unverified.

Step 1: Turn the idea into rules

Before asking for code, ask ChatGPT to interrogate the idea. This turns a vague phrase like "buy the dip" into rules you can test.

I want to test this idea: "buy SPY after a sharp drop, sell when it recovers".
Do not write code yet. Ask me questions until every one of these is defined:
market and bar size, date range, entry rule, exit rule, stop, position size,
when orders fill, fees and slippage, and what result would make me drop the idea.

Our guide to going from plain English to a trading strategy shows how common phrases map to precise rules.

Step 2: Ask for runnable code, not a verdict

Write a self-contained Python backtest using pandas.
Load daily bars from spy.csv (columns: date, open, high, low, close, volume).
Entry: close falls 3% or more below the prior 10-day high, decided after the close.
Fill: next day's open. Exit: close reaches the prior 10-day high, or 10 days pass.
Costs: 0.05% per side. Long only, 100% of equity per trade.
Print CAGR, max drawdown, Sharpe, trade count, and every trade.
Do not guess or summarize results. I will run it.

Step 3: Audit the code with ChatGPT

Paste the code back into a new conversation and ask for a hostile review. A fresh conversation is less attached to the code it wrote.

Lookahead audit

Review this backtest for lookahead bias. For each signal and each fill,
state which bar's data it uses and whether that data was known at decision time.
Quote the exact lines. Flag any use of the current bar's close for a same-bar fill.

Costs and fills audit

Check how this backtest handles fees, slippage, and fills.
Are costs applied on both entry and exit? Can a position open and close on the
same bar? What happens on a gap through the exit level?

Overfitting audit

List every number in this strategy that I chose rather than derived.
Write a loop that reruns the backtest with each one 20% higher and 20% lower,
and prints a table so I can see whether results change sharply.

Step 4: Run it on data you trust

  • Use data from a source you can name, and record the date range.
  • Hold out a recent period you never looked at while designing the rules.
  • Compare against buy and hold over the same window.
  • Read the trade list, not just the summary metrics.

Our yfinance backtesting guide covers free daily data and its pitfalls.

Step 5: Use your OpenAI key inside a backtesting harness

Steps 3 and 4 are where most chat-driven backtests go wrong, because they depend on you remembering every check. A harness makes them automatic. Scout supports bring your own key, so you can run it with an OpenAI key:

  • Install the Scout CLI, then run /init and choose OpenAI.
  • Describe the rules from step 1. Scout writes a Python strategy that follows its strategy contract, where orders fill on the next bar and only the bar's open is treated as known at decision time.
  • Run /backtest for 60+ metrics and a trade log, then /backtest walkforward for an in-sample and out-of-sample verdict and /backtest sweep for nearby parameters.

The AI backtesting overview explains each check, and the Scout CLI, the AI trading terminal, page covers install and plans. Prefer Claude? See how to backtest a trading strategy with Claude.

Backtests are research, not investment advice. Past performance does not guarantee future results.