From a8e0bb5a215f22de37e8a115e65c4ac2350f16fb Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 25 Aug 2024 09:02:14 +0200 Subject: [PATCH] Bugfix/fix division by zero in performance calculation (#3695) * Fix division by zero * Update changelog --- CHANGELOG.md | 2 +- .../app/portfolio/calculator/portfolio-calculator.ts | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd0e859a6..700fdfe97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## 2.106.0-alpha.1 - 2024-08-24 +## Unreleased ### Changed diff --git a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts index dd9bcdebb..74d1bd458 100644 --- a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts @@ -713,10 +713,14 @@ export abstract class PortfolioCalculator { netPerformanceWithCurrencyEffect: netPerformanceWithCurrencyEffectSinceStartDate, netPerformanceInPercentage: - netPerformanceSinceStartDate / timeWeightedInvestmentValue, + timeWeightedInvestmentValue === 0 + ? 0 + : netPerformanceSinceStartDate / timeWeightedInvestmentValue, netPerformanceInPercentageWithCurrencyEffect: - netPerformanceWithCurrencyEffectSinceStartDate / - timeWeightedInvestmentValue, + timeWeightedInvestmentValue === 0 + ? 0 + : netPerformanceWithCurrencyEffectSinceStartDate / + timeWeightedInvestmentValue, // TODO: Add net worth with valuables // netWorth: totalCurrentValueWithCurrencyEffect // .plus(totalAccountBalanceWithCurrencyEffect)