jgrusewski acde2e8932 fix(rl): R7c-data — true h_{t+1}/V(s_{t+1}) closes Bellman approximation
Closes the long-standing "h_t as proxy for s_{t+1}'s encoder
representation" approximation introduced in Phase E.2's Bellman target
build (canonical comment at the call site: "A future enhancement
(Phase E.3 LobSim integration) will pass next_h_t separately"). The
approximation also leaked into compute_advantage_return's V(s_{t+1})
input — R7b's `v_tp1_d_ref = &v_pred_d` alias — and into R4's
argmax_expected_q kernel call, which had been computing the
Double-DQN argmax on online Q at h_t since R4 first wired it.

Three downstream consumers now read TRUE h_{t+1}:

  * `value_head.forward(&self.h_tp1_d) → v_pred_tp1_d`, fed to
    `compute_advantage_return` as the canonical TD target V(s_{t+1}).
    Was an alias of v_pred_d (V(s_t)) — bootstrap was wrong by one
    time index.
  * `dqn_head.forward(&self.h_tp1_d) → q_logits_tp1_d`, fed to
    `argmax_expected_q` for `next_actions_d` (Double-DQN online-Q
    argmax on h_{t+1}, not h_t).
  * `dqn_head.forward_target(&self.h_tp1_d)` inside step_synthetic's
    Bellman target build. Replaces the h_t-as-proxy comment with the
    R7c data-correctness lift inline-doc.

Wiring mechanics:

  * New trainer field `h_tp1_d: CudaSlice<f32>` (`[B × HIDDEN_DIM]`).
    Zero-initialised; populated each step by step_with_lobsim.
  * `step_with_lobsim` signature gains a `next_snapshots:
    &[Mbp10RawInput]` parameter (caller — R8's CLI binary — uses
    `MultiHorizonLoader::next_sequence_pair` from R2 to load adjacent
    `(s_t, s_{t+1})` windows from real MBP-10 data).
  * Encoder is now called TWICE in step_with_lobsim:
    1. `forward_encoder(next_snapshots)` first → DtoD copy
       `perception.h_t_d → self.h_tp1_d` immediately (before any
       consumer reads the slot).
    2. `forward_encoder(snapshots)` second → leaves perception's
       internal forward state (`h_new_per_k_d`, CfC `h_state_d`)
       primed for step_synthetic's encoder backward (which still
       redundantly re-runs `forward_encoder(snapshots)` per the
       pre-existing pattern — separate compute-redundancy fuse for
       Phase R-future).
  * Three encoder forwards total per step (down from R7b's 2: one
    in step_with_lobsim, one in step_synthetic — R7c adds the
    second-snapshot forward in step_with_lobsim). The CfC encoder is
    deterministic given its input window (per the canonical
    step_with_lobsim header comment), so calling forward_encoder
    twice on different inputs in a row yields independent h_t and
    h_{t+1} via the trainer's own DtoD copy.

Test impact:

  * `integrated_trainer_smoke.rs` passes a `next_snapshots` second
    window (synthesised as a +1-tick shift of the snapshot window
    — production callers will use R2's `next_sequence_pair` on real
    MBP-10 data). Smoke continues to assert finite losses across the
    five heads.

Scope split note: this commit handles ONLY the data-correctness
half of plan A9 (rebuild plan's "PER buffer + true V(s_{t+1})
Bellman target" R7 scope). The off-policy DQN-via-PER half lands
in the next commit (R7d): Replay-buffer push, sample,
stop-grad-on-encoder Q redirect, and per-sample |TD| → update_priorities.
Split is per `pearl_no_deferrals_for_complementary_fixes`'s
sequencing-with-architectural-justification carve-out: R7d's PER
push requires the correct h_{t+1} this commit provides, so it MUST
sequence after — and the data-correctness fix is independently
useful (the on-policy DQN path now produces correct Bellman
targets even without the off-policy replay).

Local sm_86 smoke: `cargo test -p ml-alpha --test
integrated_trainer_smoke -- --ignored --nocapture` is the gate.
Cluster smoke deferred to R9.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-23 12:42:04 +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%