From 7f047362cc0647df55aa04ff3b1cfb62a2692fca Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Thu, 5 Aug 2021 07:49:25 +0200 Subject: [PATCH] Bugfix/fix division by zero in calculate overall gross performance (#253) * Fix error with division by zero * Update changelog --- CHANGELOG.md | 6 ++++++ apps/api/src/app/core/portfolio-calculator.ts | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbeb7deb..ab3c60a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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). +## Unreleased + +### Fixed + +- Fixed an issue of a division by zero in the portfolio calculations + ## 1.32.0 - 04.08.2021 ### Added diff --git a/apps/api/src/app/core/portfolio-calculator.ts b/apps/api/src/app/core/portfolio-calculator.ts index 0af578c3..a90d4a05 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 }; }