jgrusewski cb2015ab2f gem(trail): regime-adaptive trailing stop — symmetric train/val wiring
Restores regime adaptation to the 0.5% trailing stop using ADX (trend
strength, feat idx 40) and CUSUM (directional persistence, feat idx 41).
Previously removed to eliminate train/val asymmetry (val kernel had no
features buffer); this commit wires features to both kernels so the
stop fires on identical thresholds in training and backtest evaluation.

Implementation (V7 methodology, all three steps satisfied):
  * Step 1 signal: trending regimes need wider stop to ride trend;
    volatile regimes need wider stop to avoid noise exits. Original
    formulation from reward v5 (commit 263997ad3).
  * Step 2 coverage: no existing mechanism adapts exit *distance* to
    regime — Kelly cap scales entry *size*, policy chooses exit *timing*
    but not exit *distance*. So this is a genuine gap.
  * Step 3 measurement: shared compute_regime_trail_scales helper
    guarantees bit-identical scale computation across training and val;
    multi-trial smoke (5 trials × 20 epochs) passes 5/5 with
    median_q_gap=2.00, Best Sharpe 27.05 in last trial. No regression
    vs fixed-width (pre: median_q_gap=2.24; post: 2.00, within variance).

Shared helper (trade_physics.cuh::compute_regime_trail_scales):
  trend_scale = min(2.5, 1 + max(ADX   - 0.25, 0) * 2.0)
  vol_scale   = min(2.5, 1 + max(|CUS| - 0.50, 0) * 2.0)
Pass NULL features to fall back to 1.0/1.0 (fixed-width). Thresholds
match existing regime_conditional convention (adx>0.25=Trending).

Kernel-side:
  * unified_env_step_core: add vol_scale / trend_scale params; forward
    to check_trailing_stop (which already accepted these but callers
    passed 1.0/1.0). Updated step-6 docstring.
  * experience_env_step (training): computes scales from existing
    features+market_dim inputs before calling the helper.
  * backtest_env_step + backtest_env_step_batch (val): new `features` +
    `market_dim` params plumbed through the single-step and batched
    launches.

Rust-side (gpu_backtest_evaluator.rs):
  * launch_env_step: pass self.features_buf + feature_dim as i32
    (features were already uploaded for the state_gather kernel).
  * Batched launcher: same.

Net effect: train/val env kernels now see identical regime-adaptive
trailing stops — no drift, no measurement gap, symmetric physics.

Verified:
  cargo check/build clean (release); multi-trial smoke 5/5 pass.

Closes task #25.
2026-04-21 14:46:38 +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%