Use equity-based profit for profitTarget comparison
Instead of relying on dailyPnL sum (which can miss reports or be out of sync with account balance), use (amount - accountSize) as the actual profit when comparing against profitTarget. Consistency calc still uses dailyPnL totalProfit for realTarget. Also unconditionally floor the min-day reservation at minDayPnL — if equity + (days × minDay) >= target, we coast on min-day. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
1dbaebb7d8
commit
cd0f1e6fac
+10
-10
@@ -84,10 +84,12 @@ export function computeDailyTarget(
|
||||
totalProfit: number,
|
||||
dailyPnL: { date: string; pnl: number }[],
|
||||
minDayPnL: number = 0, // -999 or 0 = no minimum per day
|
||||
minTradingDays: number = 0 // 0 = no minimum trading days
|
||||
minTradingDays: number = 0, // 0 = no minimum trading days
|
||||
equityProfit?: number // amount − accountSize; used for profitTarget comparison. Defaults to totalProfit.
|
||||
): { amount: number; path: 'first_day' | 'normal_day' | 'reduced_day' } {
|
||||
const qualifyingDays = minDayPnL === 0 ? dailyPnL : dailyPnL.filter((d) => d.pnl >= minDayPnL);
|
||||
const daysTraded = qualifyingDays.length;
|
||||
const effectiveProfit = equityProfit ?? totalProfit; // used for profitTarget comparison
|
||||
|
||||
// --- Base target via consistency logic ---
|
||||
let baseAmount: number;
|
||||
@@ -102,14 +104,14 @@ export function computeDailyTarget(
|
||||
// The min-day reservation block below handles any mandatory-day targeting.
|
||||
baseAmount = 0;
|
||||
path = 'reduced_day';
|
||||
} else if (totalProfit >= profitTarget) {
|
||||
} else if (effectiveProfit >= profitTarget) {
|
||||
// Profit target already met — stop solving for consistency, let min-day reservation handle remaining days
|
||||
baseAmount = 0;
|
||||
path = 'reduced_day';
|
||||
} else {
|
||||
const maxDay = Math.max(...qualifyingDays.map((d) => d.pnl));
|
||||
const realTarget = maxDay / consistency;
|
||||
const needed = realTarget - totalProfit;
|
||||
const needed = realTarget - totalProfit; // consistency calc stays on dailyPnL totalProfit
|
||||
|
||||
if (needed > maxDay) {
|
||||
baseAmount = maxDay;
|
||||
@@ -124,7 +126,7 @@ export function computeDailyTarget(
|
||||
const effectiveMinDay = minDayPnL > 0 ? minDayPnL : 0;
|
||||
|
||||
if (effectiveMinDay > 0 && minTradingDays > daysTraded) {
|
||||
const remaining = profitTarget - totalProfit; // intentionally NOT clamped — can be negative
|
||||
const remaining = profitTarget - effectiveProfit; // use equity-based profit to know how close we are to target
|
||||
|
||||
if (remaining <= 0) {
|
||||
// Profit target already met but mandatory trading days not yet satisfied.
|
||||
@@ -137,18 +139,16 @@ export function computeDailyTarget(
|
||||
|
||||
// Cap: don't take more than what's available after reserving future days
|
||||
const cappedByFuture = remaining - futureReserve;
|
||||
// Floor: must make at least minDayPnL today (or whatever is left if less)
|
||||
const floor = Math.min(effectiveMinDay, remaining);
|
||||
|
||||
// Target what's needed to stay on track for profitTarget (cappedByFuture), floored at minDayPnL.
|
||||
// Consistency-based baseAmount is intentionally ignored here — profitTarget takes priority.
|
||||
const amount = Math.max(floor, cappedByFuture);
|
||||
// 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);
|
||||
return { amount: Math.round(amount * 100) / 100, path };
|
||||
}
|
||||
|
||||
// When no consistency constraint and no min-day reservation applied, target the full remaining profit
|
||||
if (baseAmount <= 0 && (consistency === 0 || consistency >= 1)) {
|
||||
baseAmount = Math.max(0, profitTarget - totalProfit);
|
||||
baseAmount = Math.max(0, profitTarget - effectiveProfit);
|
||||
}
|
||||
|
||||
return { amount: Math.round(Math.max(baseAmount, effectiveMinDay) * 100) / 100, path };
|
||||
|
||||
Reference in New Issue
Block a user