From 902411c4aa148eb16f59801661b372cc6607274e Mon Sep 17 00:00:00 2001 From: Arham Amin <132888838+arhxam@users.noreply.github.com> Date: Mon, 20 Jul 2026 06:48:26 +0530 Subject: [PATCH] fix(activities): ignore future account balances when building cash activities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getCashActivities() walks every account balance and books a synthetic BUY or SELL for each delta. Balances dated in the future were included, so a balance entered ahead of time booked a deposit or withdrawal that has not happened yet. The calculator clamps future activity dates to today rather than dropping them, so the phantom activity landed inside the calculation window and skewed the cash position — an extra activity, and an investment and average price pulled towards the future balance. Refs ghostfolio/ghostfolio#6185 --- apps/api/src/app/activities/activities.service.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/api/src/app/activities/activities.service.ts b/apps/api/src/app/activities/activities.service.ts index df616a5dde..9a380c0e9f 100644 --- a/apps/api/src/app/activities/activities.service.ts +++ b/apps/api/src/app/activities/activities.service.ts @@ -468,6 +468,13 @@ export class ActivitiesService { let currentBalanceInBaseCurrency = 0; for (const balanceItem of balances) { + if (isAfter(new Date(balanceItem.date), endOfToday())) { + // Skip account balances dated in the future. Synthesizing an activity + // from one books a deposit or withdrawal that has not happened yet, + // which distorts the investment and performance of the cash position. + continue; + } + const syntheticActivityTemplate: Activity = { userId, accountId: account.id,