# Kestrel vs Backtrader: Python Backtesting Library vs a Language Agents Write (/blog/kestrel-vs-backtrader)

2026-07-12 · kestrel.markets

## 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, and Kestrel, built for an agent rather than a human notebook, is aimed at a different reader. 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 deliberately narrow by comparison: a language and runtime for an agent, not a decade-old research library, 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):

```kestrel
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:

```kestrel
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

| Dimension | Backtrader | Kestrel / kestrel.markets |
|---|---|---|
| Primary reader | Human Python programmer | LLM agent (authors, perceives, acts) |
| Perception model | You compute indicators in `next()` over arrays | VIEW → text Frame; append-only tape; O(new bars) not O(screen) |
| Agent in the hot path? | N/A (no agent); your code runs in-loop | No; PLAN fires in ms, agent woken in parallel (fire-then-inform) |
| Latency floor | Local process speed; not built for live low-latency | Runtime-fired brackets in ms; agent never gates execution |
| Native interface / MCP | Python library API | HTTP+SSE canonical; TypeScript SDK, CLI, MCP as equal projections |
| Agent-native auth (Envelope) | None (library, no auth model) | Envelope: {scope, budget, ceiling, expiry, revocation}, two-signer *(founding)* |
| Machine payment | None | 402 Offers; agent wallet (MPP / x402) and human claim-and-fund |
| Evaluation honesty | Faithful replay of your code + data; no contamination control | Contamination-fenced: LLM graded only on post-cutoff, date-blinded days; VS ungated / VS null |
| Provenance | Whatever you log yourself | Certified Blotters (deterministic Episode records) + Grades + shareable proof URL |
| Live model (custody) | You wire your own broker; you hold the integration | BYO broker via OAuth; platform never takes custody; live singleton per pod lineage |
| Data licensing | You supply your own data (CSV, feeds) | Databento served as derived works (never raw redistribution) + BYO Alpaca |
| Activation path | `pip install backtrader`, run locally | Proof-before-account *(live)*: trial capability → free catalog → author → sim → certified proof → 402 boundary |
| Pricing | Free / open source | OSS language free; platform is open judge, sell certification; paid boundaries at scarce resources |
| Best for | Solo human, fast local iteration, vectorized parameter sweeps | An agent-authored strategy that needs honest, contamination-fenced grading and a hosted path to live |

*(Anonymous trial sims, certified Grades, shareable proof URLs, and 402 Offers run today; 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 episodes, 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. Anonymous trial sims, certified Grades, shareable proof URLs, and 402 Offers run today; 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.
