Claude Code · Setup

Backtest from Claude Code

Claude Code has native MCP support. Add Bagtester once and every session has a backtesting surface — submit a strategy, optimize parameters, run walk-forward, compare results, manage your plan. All from natural-language prompts.

Setup (2 minutes)

1

Get an API key

Sign up at bagtester.com/sign-up. Go to the dashboard and create a key — it starts with bag_.

2

Add the MCP server

One command in your terminal:

bash
claude mcp add bagtester \
  --transport http \
  https://bagtester.com/api/mcp \
  --header "Authorization: Bearer bag_YOUR_KEY"

Configures the server for your user account. Use --scope project to scope it to a specific repo instead.

3

Verify in a new session

Start a Claude Code session, then ask:

prompt
list bagtester tools

The reply should list all 14 tools — including submit_strategy, optimize_strategy, walk_forward, compare_backtests, and manage_subscription.

4

Run your first backtest

Try a natural prompt:

prompt
backtest an SMA crossover (fast=20, slow=50) on BTCUSDT for 2024 using hybrid mode

Claude Code writes the Python strategy, calls submit_strategy, and shows the results — equity sparkline, key metrics, any high-severity quality flags, and a share URL.

What an end-to-end session looks like

terminal
> backtest an SMA crossover on BTCUSDT for 2024

I'll write a Strategy subclass and submit it.

[tool: submit_strategy] code=..., mode=minute, symbol=BTCUSDT,
                       from_date=2024-01-01, to_date=2024-12-31

→ +24.7% return, Sharpe 1.83, max DD -14.2% over 87 trades
  ▁▂▂▃▅▆▇▇█▇▇▆▅▆▆▇█▇▇█
  https://bagtester.com/r/abc123

Two quality flags worth noting:
  - high_tail_risk: max drawdown (-14.2%) is 0.58× annual return
  - time_concentration: 62% of PnL came from Q2 alone

Want me to test parameter sensitivity?

> yes, sweep fast in [10, 20, 50] and slow in [100, 200]

[tool: optimize_strategy] code=..., param_grid={fast: [10,20,50], slow: [100,200]}

→ Created experiment exp_btc_smaXY. Best: fast=20, slow=100, Sharpe 2.14.
  Heatmap: https://bagtester.com/r/exp/xyz789

> run walk_forward on the best params to check overfit

[tool: walk_forward] in_sample_days=90, out_sample_days=30

→ OOS Sharpe 1.61 vs IS Sharpe 2.14 (75% retention). No major overfit.

Tips for Claude Code specifically

Connect it now

Free tier ships 500 credits/month. Run the claude mcp add command above and ask your agent to backtest something.