41858c31df13cdca05b31d3c27d70c92837e2e35
Two root causes of the catastrophic train/val divergence identified via the
TD-propagation diagnostic (20-epoch smoke, RTX 3050 Ti):
1) Per-epoch adaptive-tau logic had sign inverted. When Q-value drift was
detected (q_growth > 0.005 between epochs), the code DOUBLED `tau` —
making the target network track the online network MORE aggressively,
which amplifies bootstrap runaway. For a soft-update DQN, drift should
DECREASE tau (slow the target) to stabilize. The override also
mutated `config.tau` (the base of the per-step cosine schedule), so
each "adjustment" compounded across epochs.
Observed signature (pre-fix): trade counts oscillated on alternating
epochs (odd: 110–187 trades at 41–51% win rate; even: 335–418 trades
at 3–27% win rate). Multiple "Q-value drift detected" warnings per
run.
Fix: remove the per-epoch override entirely. Tau is now fully
controlled by the per-step cosine schedule in fused_training.rs
combined with `apply_health_coupled_tau_floor` — deterministic and
stable. `prev_epoch_q_mean` is still tracked for future diagnostics
but does not feed any control loop.
Result (post-fix, same test): ZERO "Q-value drift" warnings, no
epoch-alternating trade-count pattern, final `sharpe_ema` trending UP
(3.31 → 8.12 across captured checkpoints). Oscillation eliminated.
2) Training kernel applied CUSUM-derived `spread_scale ∈ [0.5, 2.0]×` on
top of the sqrt-impact model in `compute_tx_cost`. The backtest
(validation) kernel passes `spread_scale = -1.0f` (static sqrt model,
no override). This made the training env see a time-varying spread
that validation did not — a direct train/val asymmetry.
CUSUM is already observable at `features[41]` — the network can
learn any regime-dependent behavior it needs without the env
double-counting. Removed the override; training now passes
`spread_scale = -1.0f` like the backtest.
What this does NOT fix (deferred — needs unified env kernel, Phase 3):
- Saboteur asymmetry (intentional domain randomization in training
only; design calls for an `exploration_scale` scalar in a unified
kernel).
- Plan-params conviction scaling of position size in training
(`experience_kernels.cu:1469`) absent in validation.
- Reward composition differences for any remaining shaping terms.
Files touched:
- crates/ml/src/trainers/dqn/trainer/training_loop.rs (-20 lines net)
- crates/ml/src/cuda_pipeline/experience_kernels.cu (-11 lines net)
Verified: SQLX_OFFLINE=true cargo check -p ml --lib --tests passes.
TD-propagation smoke test runs cleanly end-to-end (32s).
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%