Repository navigation
Backtest Engine
The simulation runs a Backtrader Cerebro loop with a private portfolio ledger.
A controller receives each bar, builds the synthetic option chain, manages
expiries and assignments, and records the state of the book.
The engine is deterministic: the same data, configuration, and seed produce the same result.
For every date, the engine:
- Computes 30-day realized volatility from log returns.
- Converts it to a synthetic implied volatility with a configurable multiplier.
- Prices calls and puts with Black-Scholes.
- Computes Delta, Gamma, Theta, Vega, and Rho.
- Selects strikes around the configured offset and expiry.
There are no bid-ask spreads or a volatility surface across strikes. This is a teaching model, not an execution model.
| Field | Meaning |
|---|---|
cash |
Settled cash after premiums and fees |
spot_value |
Mark-to-market value of spot holdings |
option_value |
Mark-to-market value of open options |
futures_value |
Basis/futures leg mark |
nav |
Total net asset value |
drawdown |
Current drawdown from peak |
iv |
Synthetic implied volatility |
contracts |
Open option contracts |
benchmark |
Buy-and-hold benchmark index |
The ledger records every trade with kind, strike, and expiry metadata so
the arena can attribute breaches and assignments.
- Total return and CAGR
- Maximum drawdown
- Sharpe and Sortino ratios
- Win rate and profit factor
- Calmar
- Premium collected and fees paid
- Cycle P&L and equity index against buy & hold
Extreme or undefined ratios are clamped or reported as zero rather than producing infinities.
The controller emits:
-
STRIKE_BREACHwhen spot moves beyond a short option strike; -
ASSIGNMENTwhen an expiring short option finishes in the money.
With an AIAgentBridge, events are normalized and retained; if an asyncio loop
is attached, the bridge schedules the coroutine with
asyncio.run_coroutine_threadsafe. See AI Agents.
If Backtrader cannot run, a direct controller loop produces the same ledger and NAV. The UI reports data-source problems as friendly messages rather than technical tracebacks.
- American early exercise is not modelled.
- No bid-ask spread, open interest, or borrow costs.
- The basis leg uses an idealized convergence hedge.
- Dividends, taxes, and exchange contract specifications are simplified.
See Strategies, Data Pipeline, and Testing & CI.
DerivLab · an educational options & futures strategy emulator · docs verified against v1.2.0 on 2026-10-23 · README · Docs feedback · MIT License · Not investment advice.
Start here
- Home
- Getting Started
- Compatibility & Versions
- Feature Tour
- FAQ
- Documentation & ADRs
- Versioning
- Roadmap
Core systems
- Architecture
- Backtest Engine
- Strategy Library
- AI Agents
- AI Model Guide
- LLM Quality & Safety
- Data Pipeline
- Game Mode
Engineering
- Configuration
- Testing & CI
- Deployment
- Security
- Project Structure
- Troubleshooting
- Glossary
- Release Notes