Risk Management Systems
8-stage sequential risk chain — each stage is independently veto-capable. A stage failure logs the kill_reason and stops propagation to execution. No stage has visibility into whether others have already vetoed.
Risk Chain — Sequential Pipeline
Post-signal risk pipeline — each node is an independent gate
The 8 Risk Stages
microstructure_agent.pyVETO-CAPABLELevel 2 order book analysis via Databento. Computes Order Book Imbalance (OBI) and detects sell / buy walls. Applied before any ML or LLM processing — the cheapest possible early exit.
risk_calculator.pyVETO-CAPABLEConditional Value at Risk (Expected Shortfall) via historical simulation. Confidence level: 95%. Lookback: rolling window from TimescaleDB. Max per-asset position: 5% of total portfolio NAV.
portfolio_optimizer.pyVETO-CAPABLEKelly Criterion allocator with half-Kelly conservative production setting. Enforces 4 sequential constraints: correlation, volatility targeting, sector limits, ATR-based stops.
chaos_simulator.pyADVISORYMonte Carlo jump-diffusion simulation. Generates Normal, Flash Crash, and Gap-Down path types. Output (ChaosReport) is embedded in AgentState and attached to every deal memo. Does not independently veto — an elevated ruined_rate can trigger red_team veto.
stress_test.pyADVISORYReplays four historical crisis paths against the proposed position. Output is advisory — informs the deal memo and chaos_report. Does not independently veto.
tail_hedge.pyADVISORYBlack-Scholes option pricing for 3 hedging strategies. Recommendations are advisory — reviewed by CIO or risk manager before any hedge order is placed. Does not directly veto or execute.
red_team.pyVETO-CAPABLEAdversarial GPT-3.5-turbo call. Receives full AgentState and is explicitly instructed to find every reason the trade should NOT be taken. Returns veto=bool, kill_reason, risk_flags[].
sanity_guard.pyVETO-CAPABLEHallucination detection and hard price reality check. If |LLM-referenced price − live price| / live price > 5%, immediate veto='price_hallucination'. Also validates order size vs. current market liquidity.
Kelly Criterion — Position Sizing
Formula
AllocationResult
Portfolio Optimizer — 4 Constraints
| Constraint | Logic |
|---|---|
| Correlation check | Reject if proposed trade correlation with any open position > 0.75 (avoids concentration) |
| Volatility targeting | Inverse volatility sizing — higher volatility means smaller position size |
| Sector limits | SectorValidatorOrchestrator enforces sector concentration limits |
| ATR-based stops | Position sized so stop-loss distance ≈ risk budget. Stop price = ATR-derived. |
StressTester — Historical Crisis Replays
| Scenario | Period | Nature |
|---|---|---|
| 2008 Financial Crisis | Sep–Nov 2008 | Calibrated equity crash path |
| COVID-19 Crash | Feb–Mar 2020 | Sharp V-shape drawdown |
| Black Monday 1987 | 19 Oct 1987 | Single-day 22% crash |
| Flash Crash 2010 | 6 May 2010 | Intraday liquidity-driven spike/recovery |
Portfolio-Level Circuit Breakers
| Trigger | Action | Reset |
|---|---|---|
| Daily PnL drawdown > 5% | Halt all new signal processing | Manual only — CIO/Risk Manager via API |
| 3+ execution failures in 5 minutes | Halt all new signal processing | Auto-reset after cool-down period |
| Latency threshold exceeded | Halt all new signal processing | Auto-reset |
| Manual command | Halt all new signal processing | Manual release only |