From 589357264812a335489ddb8b0d34e246eb6d426a Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Wed, 4 Aug 2021 21:11:47 +0200 Subject: [PATCH] Fix error with division by zero --- apps/api/src/app/core/portfolio-calculator.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/api/src/app/core/portfolio-calculator.ts b/apps/api/src/app/core/portfolio-calculator.ts index 0af578c30..a90d4a057 100644 --- a/apps/api/src/app/core/portfolio-calculator.ts +++ b/apps/api/src/app/core/portfolio-calculator.ts @@ -418,13 +418,18 @@ export class PortfolioCalculator { hasErrors = true; } } + + if (!completeInitialValue.eq(0)) { + grossPerformancePercentage = + grossPerformancePercentage.div(completeInitialValue); + } + return { currentValue, grossPerformance, + grossPerformancePercentage, hasErrors, - totalInvestment, - grossPerformancePercentage: - grossPerformancePercentage.div(completeInitialValue) + totalInvestment }; }