diff --git a/apps/api/src/app/portfolio/portfolio.service-new.ts b/apps/api/src/app/portfolio/portfolio.service-new.ts index 2ea49de8f..f74cd2719 100644 --- a/apps/api/src/app/portfolio/portfolio.service-new.ts +++ b/apps/api/src/app/portfolio/portfolio.service-new.ts @@ -71,6 +71,9 @@ import { import { PortfolioCalculatorNew } from './portfolio-calculator-new'; import { RulesService } from './rules.service'; +const developedMarkets = require('../../assets/countries/developed-markets.json'); +const emergingMarkets = require('../../assets/countries/emerging-markets.json'); + @Injectable() export class PortfolioServiceNew { public constructor( @@ -380,7 +383,31 @@ export class PortfolioServiceNew { const value = item.quantity.mul(item.marketPrice); const symbolProfile = symbolProfileMap[item.symbol]; const dataProviderResponse = dataProviderResponses[item.symbol]; + + const markets = { + DEVELOPED_MARKETS: 0, + EMERGING_MARKETS: 0, + OTHER_MARKETS: 0 + }; + + for (const country of symbolProfile.countries) { + if (developedMarkets.includes(country.code)) { + markets.DEVELOPED_MARKETS = new Big(markets.DEVELOPED_MARKETS) + .plus(country.weight) + .toNumber(); + } else if (emergingMarkets.includes(country.code)) { + markets.EMERGING_MARKETS = new Big(markets.EMERGING_MARKETS) + .plus(country.weight) + .toNumber(); + } else { + markets.OTHER_MARKETS = new Big(markets.OTHER_MARKETS) + .plus(country.weight) + .toNumber(); + } + } + holdings[item.symbol] = { + markets, allocationCurrent: value.div(totalValue).toNumber(), allocationInvestment: item.investment.div(totalInvestment).toNumber(), assetClass: symbolProfile.assetClass, diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts index 2ca5f6930..7e4238e1c 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts @@ -42,6 +42,9 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { public deviceType: string; public hasImpersonationId: boolean; public hasPermissionToCreateOrder: boolean; + public markets: { + [market: string]: { name: string; value: number }; + }; public period = 'current'; public periodOptions: ToggleOption[] = [ { label: 'Initial', value: 'original' }, @@ -160,6 +163,20 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { value: 0 } }; + this.markets = { + DEVELOPED_MARKETS: { + name: 'DEVELOPED_MARKETS', + value: 0 + }, + EMERGING_MARKETS: { + name: 'EMERGING_MARKETS', + value: 0 + }, + OTHER_MARKETS: { + name: 'OTHER_MARKETS', + value: 0 + } + }; this.positions = {}; this.positionsArray = []; this.sectors = { @@ -219,6 +236,13 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { // Prepare analysis data by continents, countries and sectors except for cash if (position.countries.length > 0) { + this.markets['DEVELOPED_MARKETS'].value += + position.markets['DEVELOPED_MARKETS'] * position.value; + this.markets['EMERGING_MARKETS'].value += + position.markets['EMERGING_MARKETS'] * position.value; + this.markets['OTHER_MARKETS'].value += + position.markets['OTHER_MARKETS'] * position.value; + for (const country of position.countries) { const { code, continent, name, weight } = country; @@ -294,6 +318,18 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { }; } } + + const marketsTotal = + this.markets['DEVELOPED_MARKETS'].value + + this.markets['EMERGING_MARKETS'].value + + this.markets['OTHER_MARKETS'].value; + + this.markets['DEVELOPED_MARKETS'].value = + this.markets['DEVELOPED_MARKETS'].value / marketsTotal; + this.markets['EMERGING_MARKETS'].value = + this.markets['EMERGING_MARKETS'].value / marketsTotal; + this.markets['OTHER_MARKETS'].value = + this.markets['OTHER_MARKETS'].value / marketsTotal; } public onChangePeriod(aValue: string) { diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.html b/apps/client/src/app/pages/portfolio/allocations/allocations-page.html index 276de32ce..589ec4b2d 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.html +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.html @@ -172,6 +172,42 @@ +