From 789af47a78df0ee75bedf39ac15409d5ebad9582 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Thu, 31 Mar 2022 19:58:07 +0200 Subject: [PATCH] Harmonize algebraic sign --- .../app/portfolio/portfolio.service-new.ts | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.service-new.ts b/apps/api/src/app/portfolio/portfolio.service-new.ts index c01f30242..e3b9e8536 100644 --- a/apps/api/src/app/portfolio/portfolio.service-new.ts +++ b/apps/api/src/app/portfolio/portfolio.service-new.ts @@ -810,23 +810,33 @@ export class PortfolioServiceNew { const hasErrors = currentPositions.hasErrors; const currentValue = currentPositions.currentValue.toNumber(); - const currentGrossPerformance = - currentPositions.grossPerformance.toNumber(); - const currentGrossPerformancePercent = - currentPositions.grossPerformancePercentage.toNumber(); - const currentNetPerformance = currentPositions.netPerformance.toNumber(); - const currentNetPerformancePercent = - currentPositions.netPerformancePercentage.toNumber(); + const currentGrossPerformance = currentPositions.grossPerformance; + let currentGrossPerformancePercent = + currentPositions.grossPerformancePercentage; + const currentNetPerformance = currentPositions.netPerformance; + let currentNetPerformancePercent = + currentPositions.netPerformancePercentage; + + if (currentGrossPerformance.mul(currentGrossPerformancePercent).lt(0)) { + // If algebraic sign is different, harmonize it + currentGrossPerformancePercent = currentGrossPerformancePercent.mul(-1); + } + + if (currentNetPerformance.mul(currentNetPerformancePercent).lt(0)) { + // If algebraic sign is different, harmonize it + currentNetPerformancePercent = currentNetPerformancePercent.mul(-1); + } return { errors: currentPositions.errors, hasErrors: currentPositions.hasErrors || hasErrors, performance: { - currentGrossPerformance, - currentGrossPerformancePercent, - currentNetPerformance, - currentNetPerformancePercent, - currentValue + currentValue, + currentGrossPerformance: currentGrossPerformance.toNumber(), + currentGrossPerformancePercent: + currentGrossPerformancePercent.toNumber(), + currentNetPerformance: currentNetPerformance.toNumber(), + currentNetPerformancePercent: currentNetPerformancePercent.toNumber() } }; }