/** * Compute the next trading day's profit target for an account. * * Path 1 – No positive trading days yet: * target = profitTarget × consistency * * Path 2 – At least one positive day exists: * maxDay = highest single-day P&L so far * realTarget = maxDay / consistency (the total profit at which maxDay ≤ consistency% of total) * needed = realTarget − totalProfit * * if needed > maxDay → target maxDay (still a long way from the real target; trade a normal day) * else → target needed (close to the real target; aim for exactly what's left) */ export function computeDailyTarget( profitTarget: number, consistency: number, totalProfit: number, dailyPnL: { date: string; pnl: number }[] ): { amount: number; path: 'first_day' | 'normal_day' | 'reduced_day' } { const positiveDays = dailyPnL.filter((d) => d.pnl > 0); if (positiveDays.length === 0) { return { amount: Math.round(profitTarget * consistency * 100) / 100, path: 'first_day', }; } const maxDay = Math.max(...positiveDays.map((d) => d.pnl)); const realTarget = maxDay / consistency; const needed = realTarget - totalProfit; if (needed > maxDay) { return { amount: Math.round(maxDay * 100) / 100, path: 'normal_day' }; } return { amount: Math.round(Math.max(0, needed) * 100) / 100, path: 'reduced_day' }; }