From ea219f0b8876ade75432d6c07a28428ec1f0a5b2 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sun, 1 Aug 2021 00:21:56 +0200 Subject: [PATCH] Add guard --- apps/api/src/app/core/portfolio-calculator.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/api/src/app/core/portfolio-calculator.ts b/apps/api/src/app/core/portfolio-calculator.ts index b81231cb6..836c2c06d 100644 --- a/apps/api/src/app/core/portfolio-calculator.ts +++ b/apps/api/src/app/core/portfolio-calculator.ts @@ -389,9 +389,13 @@ export class PortfolioCalculator { let grossPerformancePercentage = new Big(0); let completeInitialValue = new Big(0); for (const currentPosition of positions) { - currentValue = currentValue.add( - new Big(currentPosition.marketPrice).mul(currentPosition.quantity) - ); + if (currentPosition.marketPrice) { + currentValue = currentValue.add( + new Big(currentPosition.marketPrice).mul(currentPosition.quantity) + ); + } else { + hasErrors = true; + } totalInvestment = totalInvestment.add(currentPosition.investment); if (currentPosition.grossPerformance) { grossPerformance = grossPerformance.plus(