From 413076141c655f1545f59159818c9704fd4df556 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Thu, 3 Oct 2024 20:18:26 +0200 Subject: [PATCH] Bugfix/fix calculation of allocations by market (#3853) * Fix calculation of allocations by market (unknown) * Update changelog --- CHANGELOG.md | 4 +++ .../src/app/portfolio/portfolio.service.ts | 30 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb824f43b..9ba9ee7a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Optimized the portfolio calculations with smarter date interval selection - Improved the language localization for German (`de`) +### Fixed + +- Fixed an issue in the calculation of allocations by market (_Unknown_) + ## 2.111.0 - 2024-09-28 ### Added diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index c2c867f61..fc06545a5 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -470,8 +470,7 @@ export class PortfolioService { if (withMarkets) { ({ markets, marketsAdvanced } = this.getMarkets({ - assetProfile, - valueInBaseCurrency + assetProfile })); } @@ -1433,11 +1432,9 @@ export class PortfolioService { } private getMarkets({ - assetProfile, - valueInBaseCurrency + assetProfile }: { assetProfile: EnhancedSymbolProfile; - valueInBaseCurrency: Big; }) { const markets = { [UNKNOWN_KEY]: 0, @@ -1499,16 +1496,23 @@ export class PortfolioService { .toNumber(); } } - } else { - markets[UNKNOWN_KEY] = new Big(markets[UNKNOWN_KEY]) - .plus(valueInBaseCurrency) - .toNumber(); - - marketsAdvanced[UNKNOWN_KEY] = new Big(marketsAdvanced[UNKNOWN_KEY]) - .plus(valueInBaseCurrency) - .toNumber(); } + markets[UNKNOWN_KEY] = new Big(1) + .minus(markets.developedMarkets) + .minus(markets.emergingMarkets) + .minus(markets.otherMarkets) + .toNumber(); + + marketsAdvanced[UNKNOWN_KEY] = new Big(1) + .minus(marketsAdvanced.asiaPacific) + .minus(marketsAdvanced.emergingMarkets) + .minus(marketsAdvanced.europe) + .minus(marketsAdvanced.japan) + .minus(marketsAdvanced.northAmerica) + .minus(marketsAdvanced.otherMarkets) + .toNumber(); + return { markets, marketsAdvanced }; }