jgrusewski 12635bd708 feat(rl): Phase 4.4 — ISV-adaptive V blend controller
Replaces Phase 4.3's hard V_dq → PPO swap with an adaptive blend
driven by an on-device controller. Per the project's no-tuning
philosophy (pearl_controller_anchors_isv_driven, feedback_adaptive_not_tuned):

    V_used[b] = α × V_scalar[b] + (1 − α) × V_dq[b]

where α ∈ [0, 1] is emitted by rl_v_blend_alpha_controller from
the observed V_dq vs V_scalar tracking ratio:

    track_ratio = EMA(|V_dq − V_scalar|) / EMA(|V_scalar|)

    if track_ratio > 1.5 × TARGET:   α ← min(α + 0.01, 1.0)
    if track_ratio < TARGET / 1.5:   α ← max(α - 0.01, 0.0)
    else:                            hold α

Plus dead-signal guard: if EMA(|V_scalar|) < 1e-4, hold α (no V
signal yet to calibrate against).

Bootstrap on sentinel 0: α = 1.0 (Plan A v2 behavior on first step).
EMAs first-observation bootstrap (no Wiener-α blend on first sample).

Two new kernels:
  - rl_v_blend.cu: elementwise blend (~25 LOC). Grid (ceil(B/256),1,1).
  - rl_v_blend_alpha_controller.cu: single-block parallel reduction
    + Schulman-bounded controller (~90 LOC). Grid (1,1,1), block (1024,1,1).

Three new ISV slots (585/586/587):
  - RL_V_BLEND_ALPHA_INDEX        — current α
  - RL_V_TRACK_ERR_EMA_INDEX      — EMA(|V_dq − V_scalar|)
  - RL_V_SCALAR_MAG_EMA_INDEX     — EMA(|V_scalar|), dead-signal floor

IntegratedTrainer wiring (~80 LOC):
  - 2 new buffers v_blended_d, v_blended_tp1_d
  - In step_with_lobsim_gpu_body, after DuelingQHead Adam steps:
    1. Launch controller (reads V_scalar at h_t + V_dq at h_t, emits α)
    2. Launch blend kernel for s_t   → v_blended_d
    3. Launch blend kernel for s_tp1 → v_blended_tp1_d
  - compute_advantage_return now reads v_blended_d / v_blended_tp1_d
    instead of dueling_v_d / dueling_v_tp1_d (Phase 4.3's direct swap)

Both value_head and DuelingQHead still train independently. The blend
just selects which baseline drives PPO advantage per step based on
observed calibration. As V_dq learns to track V_scalar, the controller
gradually shifts α down toward V_dq usage. If V_dq diverges (e.g., late
training entropy spikes producing volatile advantages), controller
raises α back to V_scalar safety.

Phase 4.3 cluster (alpha-rl-qkdm2 @ 25f5ce99b) is still running and
showing dramatic late-training pnl growth (+$20M at step 18132 vs
Plan A v2 peak +$9.3M). Phase 4.4 adds adaptive control on top —
should reduce variance while preserving the architectural benefit.

Validated:
  - cargo build --release clean
  - integrated_trainer_smoke 1 step passes
  - alpha_rl_train --steps 3 --b 128 under compute-sanitizer: 0 errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-30 10:09:32 +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%