Repository navigation
Architecture
Sergey Gerasimov edited this page Oct 22, 2026
·
1 revision
DerivLab is a local-first Streamlit application with a deterministic simulation core and an optional LLM orchestration layer.
flowchart LR
UI["Streamlit UI"] --> DS["Data service<br/>cache · seed · yfinance"]
UI --> BT["Backtest controller"]
BT --> BTB["Backtrader engine"]
BT --> LEDGER["Private portfolio ledger"]
BT --> METRICS["Metrics<br/>NAV · DD · Sharpe · Sortino"]
BT --> BRIDGE["AIAgentBridge<br/>breach · assignment"]
DS --> SYNTH["Synthetic option chain<br/>Black-Scholes · Greeks"]
SYNTH --> BT
UI --> ARENA["AI Arena orchestrator"]
ARENA --> BT
BRIDGE --> ARENA
ARENA --> LLM["Optional LLM layer<br/>OpenAI-compatible / Anthropic"]
ARENA --> REPORT["AlphaVanguard report"]
ARENA --> NEWS["NewsWire"]
REPORT --> UI
NEWS --> UI
| Component | Responsibility |
|---|---|
derivlab/ui.py |
Six screens, navigation, session state, live game fragment |
derivlab/backtest_engine.py |
Backtrader wrapper, controller, ledger, NAV, events |
derivlab/strategies.py |
Strategy configuration, position plans, synthetic option legs, Greeks |
derivlab/data_fetcher.py |
yfinance downloads, Parquet cache, bundled seed, synthetic fallback |
derivlab/game_mode.py |
Scenario slicing, alerts, action state machine, scoring |
derivlab/metrics.py |
Return, CAGR, drawdown, Sharpe, Sortino, win rate, profit factor |
derivlab/charts.py |
Plotly payoff, equity, drawdown, live path, arena race |
derivlab/theme.py |
Cyberpunk theme, layout primitives, cards, translation guard |
derivlab/agents/ |
Personas, arena, LLM client, bridge, reports, news, parsing |
tests/ |
Offline pytest, Streamlit AppTest, policy/LLM/bridge/arena tests |
- Offline first. The seed and deterministic fallback make every screen useful without a network or API key.
- One accounting truth. The user, the AI desks, and the game all use the same simulation engine and ledger.
- No look-ahead. AI decisions use only bars before the scenario start.
- Additive AI. An LLM failure never breaks a screen; local output takes over.
- Stable frontend. Fixed Plotly identities and no full reruns inside live fragments protect the React tree.
-
run_backtestslices history to the requested lookback. - The controller builds a synthetic option chain and opens a position.
- Backtrader calls
next()every bar; the controller marks the book, checks expiry, triggers alerts, and records NAV. - Short strike breaches and assignments are emitted to
AIAgentBridge. - At the end, metrics and trades are assembled into a
BacktestResult. - The AI Arena ranks four results, extracts triggers, builds a JSON payload, and optionally calls the LLM.
- One Streamlit process
- One Parquet cache volume
- No database
- No broker connection
- Optional outbound HTTPS to Yahoo Finance and the configured LLM provider
See Backtest Engine, AI Agents, and Deployment.
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