jgrusewski 17cfbb2503 fix(sp12): per-trade event-driven reward composition
Three architectural changes in one atomic commit per spec ecab584c3:

1. Asymmetric bounded cap (REWARD_NEG_CAP=-10, REWARD_POS_CAP=+5):
   restores prospect-theory loss aversion (2:1 ratio) erased by SP11
   symmetric cap. Per pearl_audit_unboundedness_for_implicit_asymmetry.

2. Min-hold soft penalty with temperature curriculum:
   patience requirement on voluntary exits via deficit/(deficit+T) soft
   factor. Temperature anneals 50->5 across ~100 epochs (curriculum,
   half-life 20 epochs). Trail-fire exits exempted (preserves stop-loss
   design). Penalty flows through r_popart so SP11 controller weighs it
   consistently with other voluntary-exit terms.

3. Zero per-bar shaping (Change 3):
   r_micro = 0 entirely on positioned-non-event bars (per-bar shaping is
   anti-pattern; Q-learning handles credit assignment via TD).
   Per-bar Flat opp_cost zeroed (was the symmetric counterpart to micro).
   r_opp_cost preserved as lump-sum at exit:
     r_opp_cost = -shaping_scale * holding_cost_rate * |position| * hold_time
   on segment_complete (both voluntary and trail-fire). Preserves
   carrying-cost economic concept without per-bar density bias.
   Per pearl_event_driven_reward_density_alignment.

Empirical motivation: train-multi-seed-pmbwn 50-epoch on 6a259942e
showed sharpe-gaming (PnL -30% over 8 epochs while sharpe held at 80).
Three causes: lost loss aversion (Change 1), per-bar gradient (Change
3), no commitment (Change 2). Unified per-trade event-driven design
fixes all three together.

Constants live in state_layout.cuh as Invariant-1 numerical anchors
(REWARD_POS_CAP, REWARD_NEG_CAP, MIN_HOLD_TARGET, MIN_HOLD_PENALTY_MAX,
MIN_HOLD_TEMPERATURE_{START,END,DECAY}). Min-hold temperature is
recomputed in Rust per epoch via min_hold_temperature_for_epoch in
training_loop.rs and passed as a launch scalar. New HEALTH_DIAG line
sp12_event_reward emits the constants per epoch alongside sp11_reward.

Phase 1 = constants only. Phase 2 (ISV adaptive bounds per
feedback_isv_for_adaptive_bounds) deferred until validation results
indicate adaptive need.

LOC: ~344 added (includes spec-required documentation comments)
across experience_kernels.cu, state_layout.cuh,
gpu_experience_collector.rs, training_loop.rs, dqn-wire-up-audit.md.

Build: SQLX_OFFLINE=true cargo check -p ml --lib clean.
Tests: SQLX_OFFLINE=true cargo test -p ml --lib — 938 passed,
13 failed (same 13 failures pre-existing on HEAD ecab584c3, none
related to SP12 changes).

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