From 91a448750c03b53497fa61599844bc2d32fe6929 Mon Sep 17 00:00:00 2001 From: Brandon Li Date: Mon, 20 Apr 2026 20:22:33 -0500 Subject: [PATCH] Cap consistency branch at maxDay; restore consistency cap in min-day MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When consistency is between 0 and 1 (exclusive) and profitTarget not met, the daily target should cap at maxDay (can't exceed the current max without breaking the consistency ratio). The previous 'needed' calc could return less than maxDay, stalling progress toward profitTarget. Also restored Math.min(baseAmount, cappedByFuture) in the min-day reservation so consistency is enforced when both mandates are active. Traces: - 0 days, $11111 target, 50%: first_day $5555.50, cappedByFuture $10511 -> consistencyCap = min($5555.50, $10511) = $5555.50 ✓ - 3 days, $5946.44 equity, maxDay $2415.20, 50%: baseAmount $2415.20, cappedByFuture $5014.56 -> min = $2415.20 ✓ Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/trading-logic.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/trading-logic.ts b/lib/trading-logic.ts index 280f452..0f4494d 100644 --- a/lib/trading-logic.ts +++ b/lib/trading-logic.ts @@ -109,16 +109,10 @@ export function computeDailyTarget( path = 'reduced_day'; } else { const maxDay = Math.max(...qualifyingDays.map((d) => d.pnl)); - const realTarget = maxDay / consistency; - const needed = realTarget - totalProfit; // consistency calc stays on dailyPnL totalProfit - - if (needed > maxDay) { - baseAmount = maxDay; - path = 'normal_day'; - } else { - baseAmount = Math.max(0, needed); - path = 'reduced_day'; - } + // Consistency-cap the daily target at maxDay (can't exceed maxDay without breaking consistency ratio). + // Let min-day block handle the lower bound and cappedByFuture logic. + baseAmount = maxDay; + path = 'normal_day'; } // --- Min-day reservation (only when minDayPnL is a positive value) --- @@ -139,9 +133,12 @@ export function computeDailyTarget( // Cap: don't take more than what's available after reserving future days const cappedByFuture = remaining - futureReserve; - // Target what's needed to stay on track for profitTarget (cappedByFuture), floored at minDayPnL unconditionally. - // If minDay × remainingDays >= remaining, we can coast on min-day (cappedByFuture < minDay → floor wins). - const amount = Math.max(effectiveMinDay, cappedByFuture); + // Target what's needed to stay on track for profitTarget (cappedByFuture), floored at minDayPnL. + // Cap at baseAmount when the consistency calc produced a positive value — ensures we don't + // exceed maxDay / (maxDay/consistency) constraint. When baseAmount is 0 (0/100% consistency + // or target already met), cappedByFuture drives the target directly. + const consistencyCap = baseAmount > 0 ? Math.min(baseAmount, cappedByFuture) : cappedByFuture; + const amount = Math.max(effectiveMinDay, consistencyCap); return { amount: Math.round(amount * 100) / 100, path }; }