cdfaa5e7da339b05f51b94f54961a35822c5395f
Cluster smoke `alpha-rl-9cbpj` diag.jsonl revealed that 64% of non-zero reward events (170 of 266 across 1000 steps) occur on non-done steps — mid-trade PnL deltas from trail-stop adjustments, mark-to-market, or partial fills. The reward_scale controller's mean_abs_pnl_ema was done-gated, so these mid-trade reward magnitudes never contributed to the scale calibration. Concretely: closed-trade |PnL| settled around $832-910, controller calibrated `scale = 1/910 ≈ 0.0011`. Mid-trade swings can reach $2,390 (step 590 raw reward); scaled by 0.0011 they produce reward = -$58.8, which V regression must learn to predict. With the C51 V-head atom support of [−1, +1] the −58.8 target generates MSE ≈ 3,456 (canonical incident, prior smoke). The controller is calibrated for the wrong distribution. ## Fix The `ema_update_on_done` kernel's "dones" parameter is really a generic gate tested as `d >= 0.5f`. Passing `reward_abs_d` as the gate (instead of `dones_d`) gives "gate on |reward| ≥ 0.5" which for any practical dollar magnitude means "gate on non-zero reward event". Zero-reward steps still stay excluded so the EMA isn't biased toward zero on idle hold steps. One-line change at the launch site (the `obs` and gate arguments become the same buffer, `reward_abs_d`). No kernel modification needed — the same kernel serves both done-gated EMAs (e.g. `mean_trade_duration`) and reward-event-gated EMAs (this one) just by choice of which buffer is passed as the gate. ## Expected effect on next smoke The new mean_abs_pnl_ema will track the average |reward| across both close events ($832-910) and mid-trade events ($100-2400). With mid-trade magnitudes typically 2-3× larger than close magnitudes, the new mean will be higher → reward_scale lower → all reward magnitudes (close AND mid-trade) get squeezed into the V-head's atom support more consistently. The step-590 spike (l_v=3,456) should drop to O(1). ## Verified gates (local sm_86) All R-phase tests still green — the change is a single-argument swap at the launch site, no kernel logic touched. Tests pass unchanged because they don't exercise the mid-trade reward path (test harness uses synthetic LobSim with simple cross-and-close mechanics, not the trail-stop / partial-fill mid-trade dynamics that surfaced in the cluster smoke). Co-Authored-By: Claude Opus 4.7 <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%