From 3971f010b20dd76f0b1af274388677dc8fa47846 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 19 Sep 2026 18:22:12 +0200 Subject: [PATCH] Fix net performance percentage of date ranges --- .../calculator/portfolio-calculator.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts index bbbb4fd872..2be9cfe106 100644 --- a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts @@ -822,8 +822,10 @@ export abstract class PortfolioCalculator { netPerformanceWithCurrencyEffectAtStartDate; if (historicalDataItem.totalInvestmentValueWithCurrencyEffect > 0) { - // The invested capital in the date range is the value at its start - // date: the investment plus the gross performance up to that date + // Add the gross performance at the start date of the range to the + // investment of each day. Thus the range starts with the value of + // its first day, and subsequent buy and sell activities stay + // included. timeWeightedInvestmentValuesWithCurrencyEffect.push( historicalDataItem.totalInvestmentValueWithCurrencyEffect + grossPerformanceWithCurrencyEffectAtStartDate @@ -838,19 +840,18 @@ export abstract class PortfolioCalculator { chart.push({ ...historicalDataItem, - netPerformance: - historicalDataItem.netPerformance - netPerformanceAtStartDate, + netPerformance: netPerformanceSinceStartDate, netPerformanceWithCurrencyEffect: netPerformanceWithCurrencyEffectSinceStartDate, netPerformanceInPercentage: - timeWeightedInvestmentValue === 0 - ? 0 - : netPerformanceSinceStartDate / timeWeightedInvestmentValue, + timeWeightedInvestmentValue > 0 + ? netPerformanceSinceStartDate / timeWeightedInvestmentValue + : 0, netPerformanceInPercentageWithCurrencyEffect: - timeWeightedInvestmentValue === 0 - ? 0 - : netPerformanceWithCurrencyEffectSinceStartDate / + timeWeightedInvestmentValue > 0 + ? netPerformanceWithCurrencyEffectSinceStartDate / timeWeightedInvestmentValue + : 0 }); } }