jgrusewski ab378327ec fix(data): vol_normalizer double-normalization removed (post-Bug-1)
The kernel block at experience_kernels.cu:698-704 divided
market_features[0..3] by vol_normalizer at runtime — designed for the
pre-Bug-1 pipeline where features arrived as RAW log returns (~±0.001).

After Bug 1 fix (commit 5a5dd0fed) moved z-normalization to the WRITER
(precompute_features.rs::NormStats::normalize_batch before fxcache write,
plus data_loading.rs DBN-fallback path applying the same op), features
arrive already-z-normalized. The runtime division then created a
1000-13000× DOUBLE NORMALIZATION inflating column 0 of next_states to
raw-price magnitude.

DIAG_AUX_LABEL diagnostic ground truth (production train-multi-seed-bn42w):
  - features_raw_cuda col 0 mean_abs = 0.443  (clean z-norm at SOURCE)
  - aux_nb_label_buf mean_abs        = 5398   (= 0.443 × inv_vol ~ 13245)
  - ratio matches 1 / vol_normalizer for ES 1-min realised vol ~7.5e-5

This bug caused label_scale=5481 in 50-epoch validation (cancelled
train-multi-seed-bn42w) while smoke ran with smaller window producing
smaller inv_vol → label_scale ~25-432. Both wrong, just different
inflation factors.

What changed:
  - experience_kernels.cu:698-704 block deleted; replaced with header
    comment explaining why. Kernel parameter `vol_normalizer` retained
    in signature with `(void)vol_normalizer;` to silence the
    unused-warning — removing the param would cascade through
    gpu_experience_collector.rs config struct + launcher + per-epoch
    Welford in training_loop.rs (60 lines). Bounded scope: leave the
    pipe wired, gut the consumer.
  - DIAG_AUX_LABEL diagnostic removed per its Fix 28 removal gate
    (gpu_dqn_trainer.rs ~12981 diagnostic block ~165 lines + the
    DIAG_AUX_LABEL_SOURCE_PTRS OnceLock static ~22 lines +
    training_loop.rs populate site ~22 lines).
  - Audit doc Fix 29 entry with audit results + open follow-ups.

Bug-1 contract audit (this commit's exhaustive re-check, 18 sites
classified):
  - 1 ⚠→: experience_kernels.cu:698-704 (this fix)
  - 13 : env-step kernel body, mirror universe, feature mask/noise,
    target reads at col 2 raw_close (Fix-27 already correct), DT
    rewards kernel, curriculum/hindsight/portfolio_sim kernel target
    reads, kernel header docs, PS_PREV_CLOSE state-layout slot
  - 4 ⚠ Stale (deferred — separate triage commits):
    * scripted_policy_kernel.cu:59-65 — seed-phase momentum reads
      state[MARKET_START] as raw_close, but post-Bug-1 it is z-normed
      log-return. Affects seed-phase scripted policy quality only.
    * backtest_plan_kernel.cu:77-100 — val plan_isv reads
      features[bar*feat_dim+0] as raw_close. Corrupts val plan_isv
      slots [PNL_VS_TARGET]/[PNL_VS_STOP].
    * metrics.rs:576 — val_data → window_prices reads target[0] as
      close (clones Fix-27 Bug B at host-side; affects val Sharpe).
    * hyperopt/adapters/dqn.rs:2492 — same target[0] pattern in HPO
      val_close_prices.
  - 1  Ambiguous: dqn_utility_kernels.cu:1089-1093 synthetic feature
    overlay; needs downstream-consumer contract verification.

Verification:
  - SQLX_OFFLINE=true cargo check -p ml --offline (47.87s) clean.
  - SQLX_OFFLINE=true cargo build -p ml --release --offline
    --features cuda (1m 30s) clean; cubin recompiled via nvcc.
  - Next L40S production run should show label_scale ~0.8 (matching
    kernel docstring expectation).

Refs: DIAG_AUX_LABEL diagnostic from Fix 28 in dqn-gpu-hot-path-audit.md
(commit 2683d4637) which captured the ground truth that pinned this
bug. Cancelled validation runs train-multi-seed-p5qzw (label_scale=808)
and train-multi-seed-bn42w (label_scale=5481) both blocked on this —
Fix 27 cleared the host-side variant (Welford reading target[0] as
raw_close); this Fix 29 closes the kernel-side variant. Bug 1 chain
(label_scale=5443 from 4-month-old #193) closes here.
feedback_trust_code_not_docs (the kernel comment said `#13 Vol
normalization` for months — accurate-when-written, stale-after-Bug-1).
feedback_no_partial_refactor does not apply because the kernel
parameter is retained as a no-op, deliberately leaving the
launcher/config-struct contract intact while the consumer is gutted.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-02 22:15:51 +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%