85d3ca5c72595bfe3511699cd34739ee063c2b5f
F-series investigations triangulated TWO real bugs that together explained: aux BCE > ln(2) chance baseline, sub-chance dir_acc with balanced labels, and bit-identical training across vastly different POS_WEIGHT_MAX values. BUG #1 (F2) — One-sided book contamination in mid_price_f32: - crates/ml-alpha/src/data/loader.rs::mid_price_f32 blindly averaged bid_px[0] + ask_px[0] without checking validity. MBP-10 snapshots at session boundaries / halts / stale level-0 vacancies have bid_px=0 or ask_px=0; result was mid = real_price/2 (~2750 for ES) or mid = 0 (both sides empty). - generate_outcome_labels_ab:218-220 only guarded is_finite() (NOT > 0). Sister fn generate_labels:75 does check both — asymmetry between parallel generators. - Transitions like mid=0 → mid=5500 produced ΔP=5500, instantly satisfying delta > 2×cost → spuriously triggering y_prof=1. Each contaminated snapshot tainted up to 2K downstream labels (appears as p_t for K positions and as p_kt for K positions). - With ~10-20% one-sided books in real ES, ~35-45% of K=10 labels spuriously positive — exactly matching the observed pos_fraction (0.35, 0.39, 0.46 for long). Fix (broader): mid_price_f32 returns NaN for one-sided/empty books at the source. Cascades to ALL downstream consumers (regime features, snap_features encoder, labels). Defensive guard also added in multi_horizon_labels.rs:218 for direct-test callers bypassing the loader. BUG #2 (F1+F3) — dir_acc metric structural bias: - perception.rs:3647 match condition for flat-true bucket required float-EXACT equality on raw logits (`pred_diff == 0.0`) — essentially unreachable for continuous-valued logits. - On real ES, ~30-50% of samples are flat (neither direction profitable at 2×cost threshold). ALL counted as misses → random baseline depressed to ~0.35 (matching observed 0.32-0.45). BCE can DROP while dir_acc DROPS — decoupled metrics. - aux_lift_dir_acc_threshold=0.85 was structurally UNREACHABLE under this metric regardless of model quality. Fix: skip flat-true samples (`if true_diff == 0 { continue; }`). Converts dir_acc into "given a directional outcome, did we get the direction right?" with proper random baseline 0.5. F3 + F4 confirmed: aux head wiring (8 head Adam optimizers, fwd/bwd kernel arg order, BCE+sigmoid gradient sign, reduce_axis0 reduction) is correct. The synthetic perception_overfit test stays in chance regime because it constructs constant prof_long=1, prof_short=0 → no zero-priced snapshots, no flat-true bucket. Production-data path divergence is the canonical pattern in pearl_canary_input_freshness_launch_order. cargo check --workspace --all-targets: clean. cargo test -p ml-alpha --lib multi_horizon_labels: 15 passed. 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%