Skip to content

AI Agents

Sergey Gerasimov edited this page Oct 23, 2026 · 3 revisions

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.

One cycle, end to end

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
Loading

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.


The rival desks

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.


No look-ahead

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.


Arena cycle

  1. User chooses an asset, scenario, and manual mandate.
  2. All four desks receive the same capital and market assumptions.
  3. Policies or one LLM JSON call choose strategy, tenor, strike offset, wing width, and basis premium.
  4. Four backtests run through the same Backtrader engine.
  5. STRIKE_BREACH and ASSIGNMENT events feed the trigger layer.
  6. A composite score (return, drawdown, Sharpe, premium efficiency) ranks the desks.
  7. AlphaVanguard writes the report; NewsWire writes four items.
  8. The result is stored in session state for a stable verdict, leaderboard, chart, and model-stack view.

Backtrader → async bridge

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.


Report contract

AlphaVanguard must return clean Markdown with exactly these sections:

### 📊 Performance Summary & Comparative Analysis
### 🔍 Tactical Critique of User's Performance
### 💡 Elite Quant Recommendation

The 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.


News contract

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.


Model roles

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.


Safety

  • 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.

Next


Quality and reliability

See LLM Quality & Safety for the acceptance pipeline, validators, clamps, fallback behavior, provenance, automated tests, and residual factual risk.

Clone this wiki locally