Require equityProfit; return null when balance invalid
computeDailyTarget now requires equityProfit (amount - accountSize) and returns null when it's undefined/null/NaN. 0 is still a valid value. - Removed totalProfit parameter (was only used as fallback) - Callers handle null by skipping the account (eligibility) or throwing (execution paths) - State API sets dailyTarget to null when no valid balance, avoids incorrect targetHit computation 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
b7430df16e
commit
670ee9fbeb
+10
-6
@@ -80,16 +80,20 @@ export const POINT_VALUES: { [symbol: string]: number } = {
|
||||
export function computeDailyTarget(
|
||||
profitTarget: number,
|
||||
consistency: number,
|
||||
totalProfit: number,
|
||||
dailyPnL: { date: string; pnl: number }[],
|
||||
minDayPnL: number = 0, // 0 = no minimum per day
|
||||
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' } {
|
||||
minDayPnL: number, // 0 = no minimum per day
|
||||
minTradingDays: number, // 0 = no minimum trading days
|
||||
equityProfit: number | null | undefined // amount − accountSize. Null/undefined → skip (return null). 0 is valid.
|
||||
): { amount: number; path: 'first_day' | 'normal_day' | 'reduced_day' } | null {
|
||||
// Don't run if we don't have a real account balance to compute against — 0 is valid.
|
||||
if (typeof equityProfit !== 'number' || !Number.isFinite(equityProfit)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const qualifyingDays = minDayPnL === 0 ? dailyPnL : dailyPnL.filter((d) => d.pnl >= minDayPnL);
|
||||
const daysTraded = qualifyingDays.length;
|
||||
const effectiveMinDay = Math.max(0, minDayPnL);
|
||||
const currentProfit = equityProfit ?? totalProfit;
|
||||
const currentProfit = equityProfit;
|
||||
const remaining = profitTarget - currentProfit;
|
||||
|
||||
// 1. Profit target already met — coast on min-day if mandatory days remain, else nothing to do.
|
||||
|
||||
Reference in New Issue
Block a user