Files
foxhunt/crates
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
..