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:
Brandon Li
2026-04-21 20:00:52 -05:00
co-authored by Claude Opus 4.6
parent b7430df16e
commit 670ee9fbeb
4 changed files with 31 additions and 22 deletions
+5 -5
View File
@@ -50,11 +50,11 @@ function collectFirmStats() {
const cfg = getAccountConfig(acc.name, f.accounts);
if (cfg) {
const dailyPnL = client.dailyPnL[acc.id] ?? [];
const totalProfit = dailyPnL.reduce((sum: number, d: { pnl: number }) => sum + d.pnl, 0);
const target = computeDailyTarget(cfg.profit_target, cfg.consistency, totalProfit, dailyPnL, cfg.min_day_pnl, cfg.min_trading_days);
const targetHit =
(target.amount === 0 && Math.abs(cash.realizedPnL) > 0 && (client.daysTraded[acc.id] ?? 0) <= cfg.min_trading_days) ||
(cash.realizedPnL >= target.amount);
const equityProfit = cash.amount - cfg.account_size;
const target = computeDailyTarget(cfg.profit_target, cfg.consistency, dailyPnL, cfg.min_day_pnl, cfg.min_trading_days, equityProfit);
const targetHit = !target ? false :
((target.amount === 0 && Math.abs(cash.realizedPnL) > 0 && (client.daysTraded[acc.id] ?? 0) <= cfg.min_trading_days) ||
(cash.realizedPnL >= target.amount));
if (targetHit || cash.realizedPnL !== 0) {
accountsTraded++;