fix: plan safety net ISV-driven — stop + max_hold adapt to dynamics

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) <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-04-17 09:05:27 +02:00
parent 2bc704f966
commit 0a31bf729a

View File

@@ -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;