Comparison
Bagtester vs Lean CLI
Lean CLI is QuantConnect's command-line interface — a Dockerized local runner that syncs to QuantConnect's cloud for heavier backtests. Bagtester is an MCP server: your AI agent calls a tool, we run the backtest on hosted compute, results come back as structured JSON.
Both let you keep code in your editor. The difference is the execution surface — Docker container on your machine vs MCP call to our infrastructure.
Side by side
| Topic | Bagtester | Lean CLI |
|---|---|---|
| Invocation | MCP call from your AI agent. Agent submits Python code over JSON-RPC; we run it remotely. | `lean backtest`. Runs Lean engine locally (Docker), or `lean cloud backtest` to push to QuantConnect's compute. |
| Engine | Custom Python engine (subclass `bagtester.Strategy`, implement `on_bar`). Designed for the agent-callable surface. | Lean — open-source C# engine with Python wrapper. Heavy framework with `QCAlgorithm`, consolidators, scheduled events. |
| Local setup | None. The agent has the MCP URL + API key, and that's it. | Docker, Python virtualenv, project scaffolding via `lean create-project`. Cloud sync requires QuantConnect login. |
| Data | Hosted ~10-15 GiB lake — crypto top 50 (1m + tick top 10), FX 16 majors (tick from 2003), ~200 US stocks 1m + EOD, ETFs, fundamentals, perp funding. | Bring-your-own or download QuantConnect data buckets (locally cached). Free data limited; richer datasets behind paid tiers. |
| Compute | Sandboxed Cloud Run worker, scale-to-zero. Pay-per-credit; queue + DLQ behind the scenes. | Local CPU for `lean backtest`, QuantConnect cloud for `lean cloud backtest`. Cloud minutes tied to plan. |
| Iteration speed | Single `submit_strategy` call returns in ~7-15s for a 1-year minute-mode crypto run. | Locally: depends on your CPU and data path; faster for tight inner loops because no network. Cloud: queue + run. |
| Agent integration | Native MCP. No shell, no Docker, no path resolution from the agent's side. | Agent runs shell commands. Works, but requires you to grant Bash permissions and handle paths. |
| Result format | Structured JSON v2.0 — 107 metrics, 12 quality flags, sparkline, share URL, PNG visuals. Agent-friendly. | Lean's algorithm-output JSON + HTML tearsheet on disk. Rich for humans, prose-heavy for agents to parse. |
| Pricing | $0 / $19 / $39 tiers — credits-based; usage-aware. Top-ups for spikes. | Lean itself is free; QuantConnect cloud tiers run from $20 to $300+ depending on data + compute needs. |
When to pick Bagtester
- →You want the agent → backtest loop with zero local setup.
- →You'd rather not maintain Docker / data buckets on every dev machine.
- →You want structured JSON output your agent can act on.
- →Your strategy fits crypto / FX / US equities / ETFs.
When to pick Lean CLI
- →You need Lean's primitives (consolidators, scheduled events, deep options).
- →You want the same engine for backtesting and live deployment.
- →You prefer running locally and bringing your own data.
- →You're already invested in the QuantConnect ecosystem.
Frequently asked
Can I use Lean inside Bagtester?+
No. Bagtester ships its own engine; Lean is QuantConnect's. They share neither code nor framework. If you want Lean's primitives (consolidators, scheduled events, deep options chains), use QuantConnect / Lean CLI.
Is Bagtester more lightweight than the Lean CLI?+
Yes by a wide margin. No Docker, no virtualenv, no local data download. Agent makes an MCP call, we run it. That comes with tradeoffs — you can't run locally, you can't use Lean's broker integrations, you don't get scheduled events. The tradeoff is intentional: we're optimizing for the agent → backtest loop.
What if my agent already has shell access?+
Then Lean CLI works fine for it — but you still own the local environment. Bagtester removes that ownership burden. Pick whichever matches your operational philosophy.
Can I migrate a Lean algorithm to Bagtester?+
Most logic ports. Replace `QCAlgorithm` with `bagtester.Strategy`, swap `OnData(data)` for `on_bar(self, ctx, bar)`, and translate `self.SetHoldings`/`self.MarketOrder` to `ctx.buy/sell/close`. Scheduled events and consolidators don't translate 1:1; you'd need to rebuild them with timestamp checks inside `on_bar`.
Add the MCP to your agent
500 credits/month on the free tier. The setup is one config block.