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)
Get an API key
Sign up at bagtester.com/sign-up. Go to the dashboard and create a key — it starts with bag_.
Add the MCP server
One command in your terminal:
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.
Verify in a new session
Start a Claude Code session, then ask:
list bagtester tools
The reply should list all 14 tools — including submit_strategy, optimize_strategy, walk_forward, compare_backtests, and manage_subscription.
Run your first backtest
Try a natural 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
> 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
- Sparklines render in your terminal. Claude Code's CLI displays Unicode sparklines inline. PNG visuals show up as URLs you can cmd-click to open.
- Long-running backtests auto-async. If a sweep is estimated to take >200 seconds, the tool returns immediately with status "running". Claude Code knows to poll
get_backtest_resultswhen you ask "is it done?" - Subscription management lives in MCP. Ask "cancel my subscription" — Claude Code calls
manage_subscriptionand hands you a Stripe customer-portal URL. No dashboard visit needed. - Use the share URL in PR descriptions. Every backtest gets a
/r/<token>URL with an OG card. Paste it in a PR description and reviewers see the result in the preview.
Connect it now
Free tier ships 500 credits/month. Run the claude mcp add command above and ask your agent to backtest something.