Use case · Claude Code

Ask for a backtest. Get the code, the chart and the numbers.

The slow part of testing a trading idea isn't the idea, it's the data: finding clean daily prices, adjusting them for splits and dividends, and getting them into a form your code can read. With Kaairos added to Claude Code, that part is one tool call. Kaairos saves the price history from your own Alpaca account as a CSV in your project, and Claude Code writes the backtest, runs it, fixes what breaks and draws the result.

Updated 20 November 2026

Chart made by Claude Code: growth of $1 in SPY from November 2016 to November 2026, buy and hold ending near 3.8 against the 50/200-day crossover near 2.6

The session

This is a real Claude Code session from 20 November 2026, condensed. The request is the whole prompt; nothing else was set up beforehand except an empty folder with a Python environment that has pandas and matplotlib.

Claude Code · real session, 20 Nov 2026 · condensed
Backtest a 50/200-day moving-average crossover on SPY over the last 10 years, against simply buying and holding. Get the daily prices from Kaairos. Write backtest.py (use .venv/bin/python, which has pandas and matplotlib), run it, and save the equity curves of both as backtest.png. Then tell me each one's total return, CAGR, maximum drawdown and the number of trades.
kaairos_prices SPY · daily · 2015-11-01 to 2026-11-20
saved market-data/SPY_1Day.csv · 2,737 rows · 2016-01-04 to 2026-11-19 · last close 715.87 · adjusted for splits and dividends
write backtest.py, then .venv/bin/python backtest.py
Window: 2016-11-21 to 2026-11-19 Crossover: 5 buys, 4 sells Traceback (most recent call last): … pandas.errors.LossySetitemError
Claude Code finds the cause (a number written into a text column), edits its script and runs it again
.venv/bin/python backtest.py && ls -la backtest.png
50/200 crossover Buy & hold Total return 157.3% 279.1% CAGR 9.9% 14.3% Max drawdown -33.8% -33.8% Trades 9.0 1.0 -rw-r--r-- 1 … 100175 Nov 20 16:47 backtest.png
Buy and hold beat the 50/200 crossover on SPY over the last 10 years, 279% total return against 157%. The identical −33.8% drawdown is not a bug: the crossover was still long when the early-2020 crash began, because the 50-day average hadn't yet crossed below the 200-day. It took the full drop, then sat out much of the recovery, which is where most of the gap comes from.
The whole session took 36 seconds. Left out: Claude Code looking up the Kaairos tool and a design skill before starting. The error and the fix are exactly as they happened.

What it made

Three files in the project folder: market-data/SPY_1Day.csv (the prices Kaairos saved), backtest.py (about 60 lines of pandas) and backtest.png, the chart below, which is Claude Code's own and unedited.

Growth of $1 in SPY, November 2016 to November 2026: buy and hold ends near 3.8, the 50/200-day crossover near 2.6; the crossover line goes flat while it is in cash in 2019, 2020, 2022 and 2025
Growth of $1. The flat stretches are the crossover out of the market. Each time, it missed the rebound that followed.
SPY, 21 November 2016 to 19 November 2026, daily closes adjusted for splits and dividends.
50/200 crossoverBuy and hold
Total return157.3%279.1%
Yearly (CAGR)9.9%14.3%
Worst drawdown−33.8%−33.8%
Trades9 (5 buys, 4 sells)1

We checked the result independently. A total return of 279% over these ten years is what SPY did with dividends reinvested, and the −33.8% worst drop is the February–March 2020 crash. The code acts on each signal the next day, so it can't see the future, and the 200-day average is warmed up on data from before the window, so the strategy is live from the first day.

Why the data part matters

Most backtests people ask Claude Code for stall on data, or quietly use the wrong data. Unadjusted prices make every dividend look like a small crash and every split like a huge one; free sources often lack the last few months or rate-limit you halfway through a download. Kaairos's kaairos_prices tool fetches from your own Alpaca connection, adjusts for splits and dividends, and writes a plain CSV (time, open, high, low, close, volume) that any script can read.

What you get
Bar sizes1, 5, 15 and 30 minutes, 1 hour, 1 day, 1 week, 1 month
HistoryBack to 2016 on Alpaca's free market data
AdjustmentSplits and dividends, for stocks and ETFs; none for crypto
FreshnessFull-market prices up to 15 minutes ago, then the IEX exchange
Size limit200,000 bars per request for intraday sizes; daily data is never near it
Where it goesmarket-data/<SYMBOL>_<size>.csv in your project, or a path you name

The session above asked for prices from November 2015, and Kaairos returned what exists, starting 4 January 2016, with the first and last dates in its reply, so the limit is visible rather than papered over. The ten months before the test window were enough to warm up the 200-day average.

Ideas to try

  • “Test RSI(2) mean reversion on QQQ since 2016: buy under 10, sell above 70. Compare with buying and holding.”
  • “Run the 50/200 crossover on SPY, QQQ, IWM and EFA and show which it helped and which it hurt.”
  • “Get 5-minute bars for NVDA for the last month and measure the average move in the first 30 minutes after the open.”
  • “Backtest a monthly rebalance of 60% VTI and 40% BND since 2016, then show the drawdowns.”
  • “Take the strategy that did best and have Kaairos check its signal every weekday at the close.”

The last one is where the two meet: Claude Code finds the rule, and Kaairos runs it on a schedule after the terminal is closed. See turning an answer into a routine.

Set it up

  1. In Kaairos, connect Alpaca in Settings › Trading. A paper account is free and uses real market prices.
  2. In Settings › Claude Code, click Add Kaairos.
  3. Start a new Claude Code session in your project folder and ask in plain words. Type /mcp if you want to see Kaairos listed first.

Claude Code needs Python with pandas and matplotlib in the project, or it will offer to set them up. Kaairos must be open; if it isn't, the first request opens it.

Not advice

Kaairos and Claude Code report what the data shows. Neither gives investment advice, and a backtest describes the past, not the future. The paper account uses practice money.

Limits

  • History starts in 2016 on Alpaca's free data. Longer tests need another source.
  • A backtest ignores what it isn't told about: this one assumed no costs, no slippage, no taxes and no interest on cash, and said so.
  • Kaairos supplies the data; the code is Claude Code's. Read it before trusting a number, as you would any code.
  • Claude Code and Kaairos run on the same Mac.

Fair questions

Do I need an Alpaca account?

Yes, connected in Kaairos. A paper account is free, needs only an email, and uses the same market data.

Are the prices adjusted?

Yes, for splits and dividends, on stocks and ETFs. Crypto prices aren't adjusted.

How far back does the data go?

To 2016 on Alpaca's free market data.

Can it place the trades the backtest suggests?

Only if you ask, and only with your OK in the Kaairos window for each order. Backtests never trade.

Who pays for what?

Claude Code runs on your own Claude plan. Kaairos's data comes from your Alpaca account, free for paper.

Download and go

Your AI agent, already set up.

One button to set up. Its own private AI, free. Claude, ChatGPT or Gemini when you want more.

A Mac with Apple silicon (M1 or later), macOS 15 Sequoia or later. 14-day refund.