jgrusewski 17e453a1d5 fix(ml-alpha): gate rl_popart_v_correct by slot 793 (Phase 3B-Y companion fix)
Phase 3B-Y gated PopArt reward normalization (slot 793 = 0) but
left the V-correction kernel running unconditionally. Mid-cluster
diagnostic (alpha-rl-k9lz9 step 77, ~80 min into Phase 3C):
catastrophic pnl bleed (-$6.3M cum) driven by V-head unit mismatch.

## Mechanism

* `rl_popart_normalize` running mean/sigma stats keep updating even
  when the rewards-write path is gated (so re-enabling produces
  sensible values mid-session). With rewards in raw pnl-units,
  sigma grew to ~2,666 in 77 cluster steps.
* `rl_popart_v_correct` unconditionally applies
  v_pred = (sigma_old/sigma_new)·v_pred + (mean_old-mean_new)/sigma_new
  every step — scaling V outputs against a running statistic that
  no longer matches the V regression target.
* Net effect: V predictions scaled toward zero while V regression
  target was raw pnl-units → broken V → broken Bellman Q-target →
  broken π via Q-distill → catastrophic policy.

## Fix

Add a short-circuit at the top of rl_popart_v_correct:
```c
if (isv[RL_POPART_NORMALIZE_ENABLED_INDEX] <= 0.5f) return;
```

When normalization is off (slot 793 = 0), V is being trained
against raw returns and needs no correction. The popart calibration
machinery is bypassed end-to-end.

## Verification

* Build clean (1m46s incremental).
* FOXHUNT_USE_MULTI_HEAD_POLICY=0/1 ./scripts/determinism-check.sh
  --quick: both exit 0 (200 rows match, rel-tol=1e-05).

## Discovery sequence

* Phase 2A-E cluster ran for 2h53m with shaped_reward=+$201M /
  pnl=-$330M (Phase 5 shaping anti-aligned)
* Phase 3B+Y disabled Phase 5 shaping + PopArt normalize + hindsight
* Phase 3C cluster (b=1024) at step 77 showed pnl=-$6.3M already
* Diagnosis: V-correction running against stale sigma created unit
  mismatch that broke V regression chain
* This fix is the natural companion to Phase 3B-Y's gate

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-03 22:06:55 +02:00

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
No description provided
Readme 849 MiB
Languages
Rust 88.2%
Cuda 7.7%
Python 1.3%
Shell 1.1%
PLpgSQL 0.8%
Other 0.8%