From 6c501d00ed382e225fe006105a784cab6c4910ee Mon Sep 17 00:00:00 2001 From: Brandon Li Date: Thu, 10 Sep 2026 16:21:17 -0500 Subject: [PATCH] Report per-account-type days-traded histograms to the master Adds daysHist ({daysTraded: accountCount}) to AccountTypeStats, computed from the same combined-day view the trade path uses and covering every live account including ones mid-trade. Feeds the master's payout calendar; an older master simply ignores the field. Co-Authored-By: Claude Fable 5 --- lib/master-protocol.ts | 4 ++++ lib/reporter.ts | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/master-protocol.ts b/lib/master-protocol.ts index 9b1c6e1..516961d 100644 --- a/lib/master-protocol.ts +++ b/lib/master-protocol.ts @@ -22,6 +22,10 @@ export interface AccountTypeStats { targetHit?: number; partial?: number; loss?: number; + /** Live accounts by trading days completed toward the current target: + * {daysTraded: accountCount}. Feeds the master's payout calendar. + * Optional so an older master simply ignores it. */ + daysHist?: Record; } export interface FirmStats { diff --git a/lib/reporter.ts b/lib/reporter.ts index 6185c06..6dc23f6 100644 --- a/lib/reporter.ts +++ b/lib/reporter.ts @@ -80,6 +80,18 @@ function collectFirmStats() { totalAccounts++; slice.totalAccounts++; + // Same combined-day view as the trade path: for a combining firm, + // "today" spans the holiday stretch. Computed for every live + // account — including ones mid-trade — so the days-traded + // histogram below covers the whole slice. + const combined = cfg ? combineCmeSessions( + cfg.combineCmeHolidays, client.dailyPnL[acc.id] ?? [], currentTradeDateCT(), cash.realizedPnL, + ) : null; + if (combined) { + const hist = (slice.daysHist ??= {}); + hist[combined.daysTraded] = (hist[combined.daysTraded] ?? 0) + 1; + } + if (client.positions[acc.id]) { inTrade++; accountsTraded++; @@ -100,12 +112,7 @@ function collectFirmStats() { } // Check if target was hit today - if (cfg) { - // Same combined-day view as the trade path: for a combining - // firm, "today" spans the holiday stretch. - const combined = combineCmeSessions( - cfg.combineCmeHolidays, client.dailyPnL[acc.id] ?? [], currentTradeDateCT(), cash.realizedPnL, - ); + if (cfg && combined) { const equityProfit = cash.amount - cfg.accountSize; const plan = computeDayPlan( acc.id, combined.tradeDate, cfg.profitTarget, cfg.consistency,