Browse Source

fix(activities): ignore future account balances when building cash activities

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
pull/7385/head
Arham Amin 1 month ago
parent
commit
902411c4aa
  1. 7
      apps/api/src/app/activities/activities.service.ts

7
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,

Loading…
Cancel
Save