From fccac5640dc77dab33186100b45476344466c728 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 26 Oct 2024 09:42:33 +0200 Subject: [PATCH] Bugfix/fix calculation of allocation cluster risk x ray rules (#3988) * Fix calculation of allocation cluster risk X-ray rules * Update changelog --- CHANGELOG.md | 2 ++ .../src/app/portfolio/portfolio.service.ts | 28 +++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc021cf1..7f39882a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed an issue with the X-axis scale of the dividend timeline on the analysis page - Fixed an issue with the X-axis scale of the investment timeline on the analysis page - Fixed an issue with the X-axis scale of the portfolio evolution chart on the analysis page +- Fixed an issue in the calculation of the static portfolio analysis rule: Allocation Cluster Risk (Developed Markets) +- Fixed an issue in the calculation of the static portfolio analysis rule: Allocation Cluster Risk (Emerging Markets) ## 2.118.0 - 2024-10-23 diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index ea366304a..28df6398d 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -1169,6 +1169,12 @@ export class PortfolioService { withSummary: true }); + const marketsTotalInBaseCurrency = getSum( + Object.values(markets).map(({ valueInBaseCurrency }) => { + return new Big(valueInBaseCurrency); + }) + ).toNumber(); + return { rules: { accountClusterRisk: @@ -1193,12 +1199,12 @@ export class PortfolioService { [ new AllocationClusterRiskDevelopedMarkets( this.exchangeRateDataService, - summary.currentValueInBaseCurrency, + marketsTotalInBaseCurrency, markets.developedMarkets.valueInBaseCurrency ), new AllocationClusterRiskEmergingMarkets( this.exchangeRateDataService, - summary.currentValueInBaseCurrency, + marketsTotalInBaseCurrency, markets.emergingMarkets.valueInBaseCurrency ) ], @@ -1358,20 +1364,20 @@ export class PortfolioService { } } - const marketsTotal = - markets.developedMarkets.valueInBaseCurrency + - markets.emergingMarkets.valueInBaseCurrency + - markets.otherMarkets.valueInBaseCurrency + - markets[UNKNOWN_KEY].valueInBaseCurrency; + const marketsTotalInBaseCurrency = getSum( + Object.values(markets).map(({ valueInBaseCurrency }) => { + return new Big(valueInBaseCurrency); + }) + ).toNumber(); markets.developedMarkets.valueInPercentage = - markets.developedMarkets.valueInBaseCurrency / marketsTotal; + markets.developedMarkets.valueInBaseCurrency / marketsTotalInBaseCurrency; markets.emergingMarkets.valueInPercentage = - markets.emergingMarkets.valueInBaseCurrency / marketsTotal; + markets.emergingMarkets.valueInBaseCurrency / marketsTotalInBaseCurrency; markets.otherMarkets.valueInPercentage = - markets.otherMarkets.valueInBaseCurrency / marketsTotal; + markets.otherMarkets.valueInBaseCurrency / marketsTotalInBaseCurrency; markets[UNKNOWN_KEY].valueInPercentage = - markets[UNKNOWN_KEY].valueInBaseCurrency / marketsTotal; + markets[UNKNOWN_KEY].valueInBaseCurrency / marketsTotalInBaseCurrency; const marketsAdvancedTotal = marketsAdvanced.asiaPacific.valueInBaseCurrency +