From 0a31bf729a205ced6bb61e7c8a121ca202927cbc Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Fri, 17 Apr 2026 09:05:27 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20plan=20safety=20net=20ISV-driven=20?= =?UTF-8?q?=E2=80=94=20stop=20+=20max=5Fhold=20adapt=20to=20dynamics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stop threshold: max(plan_stop, 0.5%) / (1 + grad_norm_instability). Tighter when gradient pressure high, wider when stable. Max hold: 50 * regime_stability → 10-50 bars (shorter in transitions). Plan's own learned stop_loss is the base — not hardcoded 2%. Zero hardcoded constants — everything flows through ISV + plan head. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/cuda_pipeline/experience_kernels.cu | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/ml/src/cuda_pipeline/experience_kernels.cu b/crates/ml/src/cuda_pipeline/experience_kernels.cu index 866d87b49..9024b40e4 100644 --- a/crates/ml/src/cuda_pipeline/experience_kernels.cu +++ b/crates/ml/src/cuda_pipeline/experience_kernels.cu @@ -1485,21 +1485,30 @@ extern "C" __global__ void experience_env_step( position *= fmaxf(ps[27] * readiness, 0.1f); } - /* Plan enforcement: SAFETY NET ONLY — catastrophic loss protection. + /* Plan enforcement: ISV-driven safety net. * The model LEARNS exit timing through Q-values + conviction-scaled reward. - * Hard exit ONLY on extreme loss (>2% drawdown) — not on normal plan targets. - * Planning, holding, strategic positioning are learned through temporal - * attention (ISV → Mamba2 → branch heads), not forced by static thresholds. */ + * Safety thresholds are ISV-modulated — tighter when unstable, wider when stable. + * All driven by temporal attention, nothing hardcoded. */ int has_plan = (ps[23] > 0.5f); if (has_plan && fabsf(position) > 0.001f) { float pnl_pct = (raw_close - entry_price) / fmaxf(fabsf(entry_price), 1.0f) * ((position > 0.0f) ? 1.0f : -1.0f); + /* ISV-driven thresholds: adapt to training dynamics + regime */ + float isv_instability = (isv_signals_ptr != NULL) ? isv_signals_ptr[1] : 0.0f; /* grad_norm */ + float regime_stab = (isv_signals_ptr != NULL) ? isv_signals_ptr[11] : 1.0f; /* regime_stability */ + float plan_stop = ps[25]; /* learned stop from plan head */ + + /* Catastrophic stop: base 2% tightened by instability, widened by plan's learned stop */ + float base_stop = fmaxf(plan_stop, 0.005f); /* at least 0.5%, or plan's learned value */ + float eff_stop = base_stop / (1.0f + isv_instability); /* tighter when gradient pressure high */ + + /* Max hold: base 50 bars shortened by regime transition */ + float max_hold = 50.0f * fmaxf(regime_stab, 0.2f); /* 10-50 bars depending on stability */ + int catastrophic_exit = 0; - /* Hard stop: only on extreme loss — 2% maximum risk per trade */ - if (pnl_pct <= -0.02f) catastrophic_exit = 1; - /* Hard stop: extremely long hold (>50 bars) — prevent infinite positions */ - if (hold_time >= 50.0f) catastrophic_exit = 1; + if (pnl_pct <= -eff_stop) catastrophic_exit = 1; + if (hold_time >= max_hold) catastrophic_exit = 1; if (catastrophic_exit) { position = 0.0f;