← Blog

Kestrel vs Backtrader: Python Backtesting Library vs a Language Agents Write

A fair comparison between Backtrader, a mature Python backtesting library for human quants, and Kestrel, an agent-authored trading language with contamination-fenced grading.

Answer card

Backtrader is a mature, single-process Python backtesting library built for a human quant who writes Strategy classes and iterates locally. Kestrel is an OSS language and runtime built for an LLM to author, perceive, and act, with grading that is contamination-fenced by construction. If you are one person sweeping parameters on your laptop, use Backtrader. If the author of the strategy is a model and you need an honest record of its judgment, that is what Kestrel is for.

The one-sentence difference

Backtrader answers "did this code produce a good curve on this data?" Kestrel answers "did this agent's judgment actually work on days it could not have memorized?" Those are different questions. The rest of this article is about when each one is the question you actually have.

Backtrader is legitimately good at its job: years of production use, a large body of indicators, analyzers, and community strategies. If your author is a person and your loop is local, its maturity is a real advantage a founding-stage project does not match. This comparison is written to be fair, including where Kestrel is not the fit, so start there.

Where Backtrader wins (say it plainly)

  • Solo human authoring. Backtrader's whole ergonomic is a Python programmer subclassing bt.Strategy and overriding next(). That is a great fit for one person who thinks in code and wants full imperative control.
  • Fast local iteration. No account, no service, no network. pip install backtrader, point it at a CSV, run. The inner loop is as tight as your machine.
  • Vectorized and parameter sweeps. Backtrader ships optstrategy for cranking a grid of parameters across cores. Kestrel deliberately refuses to do this: a Kestrel backtest replays committed judgment and never sweeps parameters. If your workflow is "search the parameter space for the best Sharpe," Backtrader is built for it and Kestrel is philosophically opposed to it.
  • Ecosystem maturity. Indicators, analyzers, brokers, live-feed integrations, and a decade of Stack Overflow answers. Kestrel is young by comparison; parts of the commercial platform (always-on paper presence, the human-signed live path) are still in build, and this article says so where it matters.

If those bullets describe you, stop here and use Backtrader. The rest is for when the author is a model.

Where Kestrel is a different tool

Kestrel starts from a thesis, not a feature list:

The two failures of LLM trading are interface (perception and latency), not intelligence.

A capable model fails at trading for two structural reasons, and neither is that it is not smart enough:

  1. Perception. A screenshot of a chart is thousands of tokens and re-costs the whole screen every tick. Kestrel's VIEW renders the market as a compact text Frame (the chart is in text): a vertical, append-only tape, one row per candle, newest last, in basis points versus prior close, anchored by periodic keyframes. Perception cost is O(new bars), not O(screen), and the tape is KV-cache-friendly.
  2. Latency. A model in the execution path is too slow for a bracket exit. Kestrel's PLAN is a standing, bounded-risk contingent program (trigger → actions → bracket → invalidation → TTL). The runtime fires it in milliseconds and wakes the agent in parallel: fire-then-inform. The agent is never in the hot path.

Backtrader does not try to solve either problem, because it was never designed for a model to be the author or the perceiver. That is not a defect; it is a different target reader.

Four statement kinds

Kestrel is one language with one lexical core and four surfaces:

  • VIEW (perception): what should I see, at what token budget.
  • WAKE (attention): a standing subscription over the trigger algebra; event-driven, not polling. It spends attention, never risk.
  • PLAN (latency): the bounded-risk contingent program above.
  • GRADE (trust): the honest, counterfactual result of a run.

An illustrative plan (generic instruments, not a strategy you should trade; this is how an agent could express an idea, and you would arm it into your own pod):

IMPORT { fade-ladder } FROM "./armory/reversion.kestrel"
USING signal SPX exec SPY 0dte

PLAN headline-chase budget 0.25R ttl 15:55 regime {intraday: trend}
  WHEN spot > HOD AND velocity(5m) >= p95
  DO buy 2 +1 C @ min(fair, mid) peg cap fair
  TP 2.5x frac 0.5 @ fair
  EXIT spot < VWAP held 120s @ fair
  INVALIDATE spot < LOD

Note the price anchors: fair/mid are VALUE and BOOK anchors, not literals, because a quote is not a value. cap fair guards a buy from overpaying. That precision is a claim the runtime enforces.

Grading that cannot flatter itself

This is the sharpest contrast with any backtesting library, Backtrader included. A backtest is never flattering in Kestrel, and it is enforced structurally, not promised in a README.

An LLM has read the internet. If you grade it on days inside its training window, it may be recalling the tape, not deciding. So Kestrel grades LLM authors only on post-training-cutoff, date-blinded days: the contamination fence. Because weights leak what code fences can't stop, the fence is on the evaluation, not on the prompt. Grade also carries counterfactuals in the syntax:

GRADE plan headline-chase OVER 2026-04..2026-06 FILL conservative
  VS ungated
  BY regime

VS ungated scores the agent's gate against the same plan with the gate removed; VS null scores it against doing nothing. Grade judges judgment, not parameters, which is exactly why there is no optstrategy equivalent. A vectorized sweep optimizes parameters; Kestrel refuses to bank a result a parameter search hill-climbed into.

Backtrader will faithfully report whatever your code did on whatever data you gave it, including data the strategy's author had memorized. That is not dishonest; it is just not a question Backtrader was built to police. Kestrel makes the honesty a property of the type system.

Comparison table

DimensionBacktraderKestrel / kestrel.markets
Primary readerHuman Python programmerLLM agent (authors, perceives, acts)
Perception modelYou compute indicators in next() over arraysVIEW → text Frame; append-only tape; O(new bars) not O(screen)
Agent in the hot path?N/A (no agent); your code runs in-loopNo; PLAN fires in ms, agent woken in parallel (fire-then-inform)
Latency floorLocal process speed; not built for live low-latencyRuntime-fired brackets in ms; agent never gates execution
Native interface / MCPPython library APIHTTP+SSE canonical; TypeScript SDK, CLI, MCP as equal projections (platform in-build)
Agent-native auth (Envelope)None (library, no auth model)Envelope: {scope, budget, ceiling, expiry, revocation}, two-signer (founding)
Machine paymentNone402 Offers with Stripe settlement (live); agent wallet (MPP / x402) and human claim-and-fund (in-build)
Evaluation honestyFaithful replay of your code + data; no contamination controlContamination-fenced: LLM graded only on post-cutoff, date-blinded days; VS ungated / VS null
ProvenanceWhatever you log yourselfCertified Blotters (deterministic session records) + Grades + shareable proof URL
Live model (custody)You wire your own broker; you hold the integrationBYO broker via OAuth; platform never takes custody; live singleton per pod lineage (broker path in build)
Data licensingYou supply your own data (CSV, feeds)Databento served as derived works (never raw redistribution) + BYO Alpaca
Activation pathpip install backtrader, run locallyProof-before-account (live): trial capability → free catalog → author → sim → certified proof → 402 boundary
PricingFree / open sourceOSS language free; platform is open judge, sell certification; paid boundaries at scarce resources
Best forSolo human, fast local iteration, vectorized parameter sweepsAn agent-authored strategy that needs honest, contamination-fenced grading and a hosted path to live

(Rows tagged "in-build" / "founding" are on the roadmap, not shipping today, stated honestly rather than implied. As of mid-2026: anonymous trial sims, certified Grades, shareable proof URLs, and 402 Offers with Stripe settlement are live; always-on paper presence and the human-signed live path are in build. The free tier needs no signup.)

The commercial platform, briefly

The Kestrel language is OSS. kestrel.markets is the commercial platform, the Vercel to Kestrel's Next.js. It hosts only what stays scarce when intelligence is abundant: capital and trading authority, licensed data, compute and broker access, deterministic execution, and provenance. Brains stay outside: the external-agent invariant. Sell the airport, not the pilots.

Activation is proof-before-account: an agent gets an ephemeral trial capability (no account, no card), runs free sim sessions, earns certified Blotters and a shareable proof URL, and only then hits a paid boundary as an HTTP 402 Offer. Authorization is one primitive, the Envelope {scope, budget, ceiling, expiry, revocation}, and it is two-signer: a wallet may sign commerce scopes (data, sim, paper), but a human must sign anything legal, broker, or live. As of mid-2026: anonymous trial sims, certified Grades, shareable proof URLs, and 402 Offers with Stripe settlement are live; always-on paper presence and the human-signed live path are in build. The free tier needs no signup. Backtrader has no analogue because it is a library, not a market venue, and if you never leave your laptop, it does not need one.

How to choose

  • Choose Backtrader if: you are a human who codes, you want fast offline iteration, you want to sweep parameters across cores, and you value a decade of ecosystem maturity over agent-native machinery you do not need.
  • Choose Kestrel if: the author of your strategy is a model, you need perception and latency solved so the agent can actually run, and, above all, you need a grade you can trust because the agent could not have seen those days.

They are not really competitors. One is a library for a person; the other is a language for an agent. Reach for the one whose primary reader matches yours.

Citable one-liner

Backtrader tells you what your code did on your data; Kestrel tells you whether your agent's judgment survived days it could not have memorized: different questions, different tools.