Files
foxhunt/risk
jgrusewski 89692ac4c1 fix: replace stub code with real logic and honest errors
Coordinator (ml/src/integration/coordinator.rs):
- Delete 9 fake heuristic methods (500+ lines) that pretended to be
  real DQN/TFT/TGGN/LNN/Mamba predictions using sin()/tanh() math
- Make generate_model_specific_prediction() return Err instead of
  fake predictions — prevents trading on fabricated signals
- Make ensemble fault-tolerant: skip failed models instead of
  failing entire ensemble (execute_parallel/execute_sequential)
- Remove double-fallback in execute_single_model error path

Enhanced ML (trading_service):
- get_model_performance(): compute accuracy from real
  inference_count/error_count instead of returning all zeros
- get_feature_importance(): return Status::unavailable instead of
  hardcoded fake values — honest about missing SHAP implementation

Autonomous scaling (trading_agent_service):
- diversification_score: compute real HHI from instrument volume
  distribution instead of hardcoded 0.8
- ml_confidence: keep liquidity heuristic but remove warn!() spam

Position limiter (risk):
- Remove redundant portfolio_id field from CachedPosition — the
  DashMap key already provides account-based isolation
- Remove misleading "stub" comment — was not a stub

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 09:21:21 +01:00
..

risk

Enterprise risk management for HFT.

Kill Switch

AtomicKillSwitch provides immediate trading cessation, coordinated via Redis. Supports local, remote, and Unix socket triggers.

Value at Risk

Four VaR methods plus Expected Shortfall:

  • Historical Simulation
  • Monte Carlo
  • Parametric (variance-covariance)
  • Expected Shortfall (CVaR)

Key Types

Type Purpose
RiskEngine Central risk evaluation and enforcement
AtomicKillSwitch Atomic trading halt with Redis coordination
KellySizer Kelly criterion position sizing
StressTester Extreme market scenario simulation
ComplianceValidator SOX, MiFID II regulatory checks
DrawdownMonitor Peak-to-trough equity tracking
CircuitBreaker Threshold-based trading pauses
CorrelationMonitor Cross-asset correlation tracking

Config Presets

  • development_config() -- relaxed limits for local testing
  • production_config() -- 5ms safety check timeout, strict position limits

Testing

SQLX_OFFLINE=true cargo test -p risk --lib  # ~209 tests