From c589adec913c7f48779014749ed324cdc98e1916 Mon Sep 17 00:00:00 2001 From: Brandon Li Date: Sun, 26 Apr 2026 02:54:03 -0500 Subject: [PATCH] =?UTF-8?q?Cap=20consistency=20at=20profitTarget=20=C3=97?= =?UTF-8?q?=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Caps consistencyCap at the largest day the consistency rule would have allowed (profitTarget × consistency). Prevents previous overshoots or losses from expanding future targets beyond what consistency permits. Day 1: min(remaining × consistency, profitTarget × consistency) Day 2+: min(maxDay, profitTarget × consistency) Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/trading-logic.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/trading-logic.ts b/lib/trading-logic.ts index 14fe8b2..d3f14c1 100644 --- a/lib/trading-logic.ts +++ b/lib/trading-logic.ts @@ -125,19 +125,24 @@ export function computeDailyTarget( // - 0% or 100%: no constraint // - Day 1 of cycle: max allowed = remaining × consistency // - Day 2+ of cycle: max allowed = maxDay (keeps consistency ratio stable) + // Always capped at profitTarget × consistency — the largest day the consistency + // rule would have allowed. Prevents a previous overshoot/loss from compounding. let consistencyCap: number; let path: 'first_day' | 'normal_day' | 'reduced_day'; if (consistency === 0 || consistency >= 1) { consistencyCap = Infinity; path = daysTraded === 0 ? 'first_day' : 'reduced_day'; - } else if (daysTraded === 0) { - consistencyCap = remaining * consistency; - path = 'first_day'; } else { - const maxDay = Math.max(...qualifyingDays.map((d) => d.pnl)); - consistencyCap = maxDay; - path = 'normal_day'; + const maxConsistencyDay = profitTarget * consistency; + if (daysTraded === 0) { + consistencyCap = Math.min(remaining * consistency, maxConsistencyDay); + path = 'first_day'; + } else { + const maxDay = Math.max(...qualifyingDays.map((d) => d.pnl)); + consistencyCap = Math.min(maxDay, maxConsistencyDay); + path = 'normal_day'; + } } // 4. Combine caps and apply min-day floor when mandatory days remain.