jgrusewski 40e737a181 docs(sp14): spec v3 — K=4 direction + ISV-adaptive β rate limiter
Two further user-flagged corrections from second-critical review:

1. Direction Q-head emits K=4 actions, NOT K=3.
   Authoritative source: state_layout.cuh:123-126
     #define DIR_SHORT 0   // open/maintain short
     #define DIR_HOLD  1   // keep current position (no-op)
     #define DIR_LONG  2   // open/maintain long
     #define DIR_FLAT  3   // close all to zero
   The "default: 3 — Short/Flat/Long" comment at gpu_dqn_trainer.rs:2438
   is stale pre-SP13. Production callsites all set branch_0_size: 4.
   SP13 added DIR_HOLD as a separate fourth direction action (Hold-pricing).
   The config default comment was never updated when DIR_HOLD landed.
   This is exactly the feedback_trust_code_not_docs failure mode — a
   single stale comment would have silently corrupted the q_disagreement
   signal (Hold/Flat being indices 1/3 instead of just Flat=1).

   Updates:
   - B.1 action-space context: 4 actions with Hold AND Flat both
     non-committal (Hold = keep position, Flat = exit to zero)
   - B.2.3 q_disagreement mapping: K=4↔K=2 with both Hold and Flat
     masked from disagreement signal (no new directional commitment
     to evaluate); only Short and Long picks contribute to disagreement
   - Edge case handling for all-Hold/all-Flat batches

2. Adaptive β rate limiter (was structural β=0.9).
   Per feedback_isv_for_adaptive_bounds, β should be signal-driven
   not hardcoded. v3 derives β from variance of α_grad_raw, mirroring
   the k_aux/k_q variance-driven steepness pattern in B.2.5.

   Formula:
     β = clip(β_base + variance_alpha_raw / variance_ref_alpha,
             [β_base, β_max])
     β_base = 0.5 (light smoothing baseline; ~2-step half-life)
     β_max  = 0.95 (heavy smoothing; ~20-step half-life)

   Stable α_grad_raw → β = β_base (preserves directional intent)
   Volatile α_grad_raw → β → β_max (dampens jitter)

   Adds 2 ISV slots:
     ALPHA_GRAD_RAW_VARIANCE_EMA_INDEX (Welford variance)
     BETA_RATE_LIMITER_ADAPTIVE_INDEX (current β value)

ISV slot count: 11 → 13 (net +2 for variance + adaptive β).
LOC estimate: ~1150 → ~1180 (negligible delta; 3 Welford
variances now in alpha_grad_compute_kernel instead of 2).

HEALTH_DIAG pearl_egf_diag emit updated to expose all three
adaptive scalars (α, β, k_aux/k_q) plus all three driving
variances (var_alpha, var_aux, var_q) for full observability.

Verified against current code at HEAD d243a6f08:
  - state_layout.cuh:123-126 (DIR_* enum truth source)
  - gpu_dqn_trainer.rs:2438 (stale K=3 comment confirmed)
  - branch_0_size: 4 in 5 production callsites
    (smoke_tests, gpu_iqn_head, gpu_backtest_evaluator)
  - DIR_HOLD usage in experience_kernels.cu:1298 + 14 other sites

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