cca9dd36ae8a9c1dd527033563a0d80abf3ad89d
Current criterion uses |q_mean| / |prev_q_mean| which explodes near zero crossings (legitimate cold-start has |prev_q_mean| ≈ 0.01-0.1, making any non-tiny current trigger the ratio threshold). smoke-test-n9xzr fired with prev=−0.0795, curr=0.7647, ratio=9.62× despite this being natural cold-start growth, not geometric runaway. Replace with rolling 5-epoch window of q_means. Compute median + MAD (Median Absolute Deviation, a 50%-breakdown estimator robust to single outliers); kill condition becomes |q_mean − median(window)| > 4.0 × max(MAD(window), 0.01) AND the existing adaptive floor. Constants are declared `const` near the kill block: - Q_DRIFT_WINDOW_SIZE=5 (matches smoke fold length, gives MAD a meaningful estimator without averaging across regime shifts) - Q_DRIFT_WARMUP_SAMPLES=3 (skip until ≥ 3 priors — smaller window degenerates to half-range MAD that trips on monotonic trajectories) - Q_DRIFT_DEVIATION_THRESHOLD=4.0 (4 MADs ≈ 2.7σ Gaussian- equivalent; clear outlier without firing on every legitimate dip; literal MAD count rather than σ because q_mean is non- Gaussian during cold-start) - Q_DRIFT_MIN_DEVIATION=0.01 (numerical-stability floor when window is constant) Window resets at fold boundary alongside prev_epoch_q_mean / adaptive_tau (A.1 pattern — cross-fold q-stats are independent training runs, mixing them would inflate MAD or shift the median). Predicted impact on smoke-test-n9xzr: - Plan C smoke fold 0 ep2: window has only 2 priors, warmup gate not yet satisfied → kill stays silent (was firing on ratio=9.62×) - Genuine geometric runaway (q_mean → 62.5 from baseline 0.5 over 4 epochs): ep3 deviation = |62.5 − 2.5|/MAD=2.0 = 30 > 4 AND |62.5| > floor=3×12=36 → kill fires correctly Both conditions ANDed (floor + deviation), preserving the production-safety semantics of the original criterion. The floor check is unchanged; only the divergence detector is replaced. Per feedback_no_quickfixes.md: this is a principled robust- statistics replacement, not a threshold relaxation. Per feedback_no_partial_refactor.md: window field, constants, criterion site, and fold-boundary reset land in lockstep — the kill criterion's contract is internally consistent across trainer/mod.rs, constructor.rs, and training_loop.rs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Foxhunt
Production HFT trading system in Rust.
Architecture
The workspace contains 32 crates organized as follows:
Core Libraries (16)
| Crate | Purpose |
|---|---|
trading_engine |
Order processing, FIX 4.4, IB TWS, SIMD, RDTSC timing |
risk |
VaR, Kelly, circuit breakers, kill switches, compliance |
risk-data |
Risk data types and shared structures |
trading-data |
Trading data types |
ml |
DQN Rainbow, PPO, TFT, Mamba2, ensemble inference |
ml-data |
ML data types and feature definitions |
data |
Market data ingestion and storage |
backtesting |
Replay engine, strategy tester |
adaptive-strategy |
Ensemble execution, microstructure analysis |
common |
Shared types, resilience, error handling |
storage |
S3 and local model storage |
model_loader |
Model serialization and loading |
market-data |
Market data feed handlers |
database |
PostgreSQL access layer (SQLx) |
config |
Configuration management |
tli |
CLI commands and tooling |
Services (8)
| Service | Purpose |
|---|---|
backtesting_service |
gRPC backtesting service |
broker_gateway_service |
FIX routing, broker connectivity |
trading_service |
Core trading operations |
ml_training_service |
Model training orchestration |
data_acquisition_service |
Market data acquisition |
trading_agent_service |
Autonomous trading agents |
api_gateway |
gRPC API gateway with auth |
web-gateway |
Axum REST + WebSocket gateway |
Frontend
web-dashboard/ -- React 19 + TypeScript + Vite + TradingView charts.
Building
# Check compilation (no PostgreSQL required)
SQLX_OFFLINE=true cargo check --workspace
# Run tests for a specific crate
SQLX_OFFLINE=true cargo test -p <crate> --lib
# Clippy
SQLX_OFFLINE=true cargo clippy --workspace
ML Models
Four production model architectures on Candle v0.9.1 with CUDA:
- DQN Rainbow -- Deep Q-Network with prioritized replay, dueling heads, noisy nets
- PPO -- Proximal Policy Optimization with GAE and LSTM policies
- TFT -- Temporal Fusion Transformer for multi-horizon forecasting
- Mamba2 -- State space model for sequence prediction
Each model has a standalone trainer and a UnifiedTrainable adapter for the hyperopt pipeline.
Infrastructure
- Git: Gitea at
git.fxhnt.ai(Tailscale-only), Scaleway DEV1-S - Observability: OpenTelemetry OTLP (env
OTEL_EXPORTER_OTLP_ENDPOINT) - Database: PostgreSQL with SQLx offline mode for CI
License
Proprietary. All rights reserved.
Description
Languages
Rust
88.2%
Cuda
7.7%
Python
1.3%
Shell
1.1%
PLpgSQL
0.8%
Other
0.8%