Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Feature/harmonize algebraic sign of gross and net performance percent (#776)
Thomas Kaul65f6bcb166f3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f298450078..7acac3be62 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Changed- Renamed `orders` to `activities` in import and export functionality+- Harmonized the algebraic sign of `currentGrossPerformancePercent` and `currentNetPerformancePercent` with `currentGrossPerformance` and `currentNetPerformance`- Improved the pricing page## 1.130.0 - 30.03.2022diff --git a/apps/api/src/app/portfolio/portfolio.service-new.ts b/apps/api/src/app/portfolio/portfolio.service-new.tsindex c01f302428..e3b9e85360 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()}};}