From ff8cacb0e9e4d05aeea6e54589517fc8132bb4cf Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Wed, 27 May 2026 23:05:22 +0200 Subject: [PATCH] =?UTF-8?q?feat(cuda):=20asymmetric=20reward=20shaping=20?= =?UTF-8?q?=E2=80=94=20reward=20fast=20loss-cutting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The short-hold penalty was backwards: it penalized ALL quick exits including losing trades. Quick-exiting a loser is GOOD (surfer bails early on bad waves), not bad. Fix: short-hold penalty now only fires on WINNING quick exits. New: quick-exit bonus on LOSING trades — reduces loss magnitude by up to 50% for immediate exits. Surfer philosophy: bail early = small wipeout, hold too long = big wipeout. | Scenario | Before | After | |---------------------|------------|--------------------| | Quick exit winner | Penalized | Penalized | | Quick exit loser | Penalized | 50% loss reduction | | Long hold winner | Bonus | Bonus | | Long hold loser | No bonus | No bonus | Co-Authored-By: Claude Opus 4.7 --- crates/ml-alpha/cuda/rl_fused_reward_pipeline.cu | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/ml-alpha/cuda/rl_fused_reward_pipeline.cu b/crates/ml-alpha/cuda/rl_fused_reward_pipeline.cu index 777528831..f1b034703 100644 --- a/crates/ml-alpha/cuda/rl_fused_reward_pipeline.cu +++ b/crates/ml-alpha/cuda/rl_fused_reward_pipeline.cu @@ -220,11 +220,21 @@ extern "C" __global__ void rl_fused_reward_pipeline( r -= entry_cost; } - // 2. Short-hold penalty: trade close with hold time below minimum. - if (done > 0.5f && (float)hold_time < min_hold) { + // 2. Short-hold penalty: ONLY on winning quick exits. + // Quick exit on a LOSER is GOOD (bail early on bad wave) — no penalty. + // Quick exit on a WINNER is BAD (bailed on a good wave) — penalize. + if (done > 0.5f && r > 0.0f && (float)hold_time < min_hold) { r *= penalty; } + // 2b. Quick-exit bonus on LOSING trades: reward fast loss-cutting. + // Reduces the loss magnitude proportional to how quickly the model + // exited. Surfer philosophy: bail early on closing-out waves. + if (done > 0.5f && r < 0.0f && (float)hold_time < min_hold) { + const float cut_bonus = 1.0f - 0.5f * ((min_hold - (float)hold_time) / min_hold); + r *= cut_bonus; // reduces loss by up to 50% for immediate exits + } + // 3. Long-ride bonus: profitable close amplified by hold time. if (done > 0.5f && r > 0.0f && hold_time > 0) { const float ride_mult = 1.0f + hold_bonus * sqrtf((float)hold_time);