From bd26b9b62d4ebd25f2980bce577f97f15fca1e5f Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 24 Aug 2024 19:37:20 +0200 Subject: [PATCH] Fix division by zero --- .../app/portfolio/calculator/portfolio-calculator.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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)