Repository navigation
AI Agents
The AI Arena turns the simulator into an adversarial institutional sandbox. Three autonomous desks trade the same historical scenario as the user, then AlphaVanguard AI reviews the cycle and NewsWire prints the tape.
The layer is optional: with no API key, deterministic local models run every role. With a key, the narrative and optionally the decisions come from a configured LLM, and the UI always displays the actual model names.
sequenceDiagram
autonumber
actor User
participant Arena as AI Arena
participant Ctx as Pre-scenario context
participant Desk as Three desks
participant BT as Backtrader + synthetic chain
participant Trig as Trigger extractor
participant AI as Critic + NewsWire
User->>Arena: Choose asset, scenario, mandate
Arena->>Ctx: Bars before scenario start
Ctx->>Desk: HV, percentile, trend, drawdown
Desk->>BT: Three mandates
BT->>Trig: NAV, breaches, assignments
Trig->>AI: Portfolio metrics + trigger timeline
AI-->>Arena: 3-section report + 4 headlines
Arena-->>User: Leaderboard, verdict, model stack
In plain English: you choose the tape; the desks see only the weather before the first bar; all four books trade through the same engine; the critic receives the resulting metrics and the actual breaches/assignments, not a generic prompt.
| Desk | Persona | Default policy |
|---|---|---|
| AlphaVanguard AI | Institutional relative-value PM | Sell premium with the trend in high-vol regimes; rotate to basis when trend and volatility conflict; use condors when volatility is cheap. |
| VoltHawk AI | Volatility arbitrage | Buy straddles in high-vol / fast-trend regimes; sell iron condors when volatility is compressed and range-bound. |
| BasisDyne AI | Carry and basis | Harvest synthetic futures basis across the curve and keep directional risk close to zero. |
The policies are deterministic and auditable. LLM-directed mandates are an opt-in extra, validated and clamped field by field.
build_market_context computes:
- HV30 and HV percentile over the trailing regime
- 20-day and 60-day trend
- 120-day drawdown
- volatility ratio
- capital and scenario metadata
using only bars before the scenario start. The context is passed to every desk; the future is not visible.
- User chooses an asset, scenario, and manual mandate.
- All four desks receive the same capital and market assumptions.
- Policies or one LLM JSON call choose strategy, tenor, strike offset, wing width, and basis premium.
- Four backtests run through the same Backtrader engine.
-
STRIKE_BREACHandASSIGNMENTevents feed the trigger layer. - A composite score (return, drawdown, Sharpe, premium efficiency) ranks the desks.
- AlphaVanguard writes the report; NewsWire writes four items.
- The result is stored in session state for a stable verdict, leaderboard, chart, and model-stack view.
from derivlab.agents.bridge import AIAgentBridge
bridge = AIAgentBridge(event_loop=loop) # loop optional
run_backtest("AAPL", frame, config, event_bridge=bridge)AIAgentBridge.emit normalizes the event and retains it. When an asyncio loop is
attached, it schedules process_market_shock with
asyncio.run_coroutine_threadsafe, matching the SRS integration pattern.
AlphaVanguard must return clean Markdown with exactly these sections:
### 📊 Performance Summary & Comparative Analysis
### 🔍 Tactical Critique of User's Performance
### 💡 Elite Quant RecommendationThe validator checks the headings; invalid output falls back to the deterministic local critic. The model sees the user portfolio, the AI rival portfolio, the leaderboard, and the critical triggers.
NewsWire returns a JSON array of 3–5 items:
[
{
"tag": "STRIKE SHOCK",
"headline": "Short calls breached as volatility repriced",
"detail": "…",
"severity": "high"
}
]Items are bounded and severity is normalized. Invalid JSON falls back to four local cyberpunk headlines.
| Role | Default local model | Live model |
|---|---|---|
| Autonomous decisions | derivlab-local-quant-core-v1 |
Configured decision model or local policy |
| AlphaVanguard critic | derivlab-local-critic-v1 |
Configured critic model |
| NewsWire | derivlab-local-newswire-v1 |
Configured news model |
The sidebar, rival cards, leaderboard, report header, and Model stack tab show the active names, provider, source, latency, and fallback reason.
- API keys are never rendered or logged.
- LLM output is untrusted Markdown; no raw HTML is rendered.
- JSON is extracted tolerantly from code fences or chatty prose.
- HTTP errors, timeouts, malformed JSON, and missing sections fall back locally.
- The arena never raises an LLM failure into the Streamlit UI.
- AI Model Guide — tested models and recommendations
- Architecture — system context
- Testing & CI — agent test coverage
See LLM Quality & Safety for the acceptance pipeline, validators, clamps, fallback behavior, provenance, automated tests, and residual factual risk.
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