diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c8e7f135..7811aad52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Extended the allocations by market chart on the allocations page by unavailable data + ### Fixed - Considered liabilities in the total account value calculation diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index ba77354b2..564056d1c 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -540,11 +540,13 @@ export class PortfolioService { const dataProviderResponse = dataProviderResponses[item.symbol]; const markets: PortfolioPosition['markets'] = { + [UNKNOWN_KEY]: 0, developedMarkets: 0, emergingMarkets: 0, otherMarkets: 0 }; const marketsAdvanced: PortfolioPosition['marketsAdvanced'] = { + [UNKNOWN_KEY]: 0, asiaPacific: 0, emergingMarkets: 0, europe: 0, @@ -553,48 +555,58 @@ export class PortfolioService { otherMarkets: 0 }; - for (const country of symbolProfile.countries) { - if (developedMarkets.includes(country.code)) { - markets.developedMarkets = new Big(markets.developedMarkets) - .plus(country.weight) - .toNumber(); - } else if (emergingMarkets.includes(country.code)) { - markets.emergingMarkets = new Big(markets.emergingMarkets) - .plus(country.weight) - .toNumber(); - } else { - markets.otherMarkets = new Big(markets.otherMarkets) - .plus(country.weight) - .toNumber(); - } + if (symbolProfile.countries.length > 0) { + for (const country of symbolProfile.countries) { + if (developedMarkets.includes(country.code)) { + markets.developedMarkets = new Big(markets.developedMarkets) + .plus(country.weight) + .toNumber(); + } else if (emergingMarkets.includes(country.code)) { + markets.emergingMarkets = new Big(markets.emergingMarkets) + .plus(country.weight) + .toNumber(); + } else { + markets.otherMarkets = new Big(markets.otherMarkets) + .plus(country.weight) + .toNumber(); + } - if (country.code === 'JP') { - marketsAdvanced.japan = new Big(marketsAdvanced.japan) - .plus(country.weight) - .toNumber(); - } else if (country.code === 'CA' || country.code === 'US') { - marketsAdvanced.northAmerica = new Big(marketsAdvanced.northAmerica) - .plus(country.weight) - .toNumber(); - } else if (asiaPacificMarkets.includes(country.code)) { - marketsAdvanced.asiaPacific = new Big(marketsAdvanced.asiaPacific) - .plus(country.weight) - .toNumber(); - } else if (emergingMarkets.includes(country.code)) { - marketsAdvanced.emergingMarkets = new Big( - marketsAdvanced.emergingMarkets - ) - .plus(country.weight) - .toNumber(); - } else if (europeMarkets.includes(country.code)) { - marketsAdvanced.europe = new Big(marketsAdvanced.europe) - .plus(country.weight) - .toNumber(); - } else { - marketsAdvanced.otherMarkets = new Big(marketsAdvanced.otherMarkets) - .plus(country.weight) - .toNumber(); + if (country.code === 'JP') { + marketsAdvanced.japan = new Big(marketsAdvanced.japan) + .plus(country.weight) + .toNumber(); + } else if (country.code === 'CA' || country.code === 'US') { + marketsAdvanced.northAmerica = new Big(marketsAdvanced.northAmerica) + .plus(country.weight) + .toNumber(); + } else if (asiaPacificMarkets.includes(country.code)) { + marketsAdvanced.asiaPacific = new Big(marketsAdvanced.asiaPacific) + .plus(country.weight) + .toNumber(); + } else if (emergingMarkets.includes(country.code)) { + marketsAdvanced.emergingMarkets = new Big( + marketsAdvanced.emergingMarkets + ) + .plus(country.weight) + .toNumber(); + } else if (europeMarkets.includes(country.code)) { + marketsAdvanced.europe = new Big(marketsAdvanced.europe) + .plus(country.weight) + .toNumber(); + } else { + marketsAdvanced.otherMarkets = new Big(marketsAdvanced.otherMarkets) + .plus(country.weight) + .toNumber(); + } } + } else { + markets[UNKNOWN_KEY] = new Big(markets[UNKNOWN_KEY]) + .plus(value) + .toNumber(); + + marketsAdvanced[UNKNOWN_KEY] = new Big(marketsAdvanced[UNKNOWN_KEY]) + .plus(value) + .toNumber(); } holdings[item.symbol] = { 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 7266032a5..00f7f112d 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 @@ -86,7 +86,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { value: number; }; }; - + public UNKNOWN_KEY = UNKNOWN_KEY; public user: User; public worldMapChartFormat: string; @@ -229,20 +229,29 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { } }; this.markets = { + [UNKNOWN_KEY]: { + name: UNKNOWN_KEY, + value: 0 + }, developedMarkets: { name: 'developedMarkets', - value: undefined + value: 0 }, emergingMarkets: { name: 'emergingMarkets', - value: undefined + value: 0 }, otherMarkets: { name: 'otherMarkets', - value: undefined + value: 0 } }; this.marketsAdvanced = { + [UNKNOWN_KEY]: { + id: UNKNOWN_KEY, + name: UNKNOWN_KEY, + value: 0 + }, asiaPacific: { id: 'asiaPacific', name: translate('Asia-Pacific'), @@ -346,16 +355,6 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { // Prepare analysis data by continents, countries and sectors except for cash if (position.countries.length > 0) { - if (!this.markets.developedMarkets.value) { - this.markets.developedMarkets.value = 0; - } - if (!this.markets.emergingMarkets.value) { - this.markets.emergingMarkets.value = 0; - } - if (!this.markets.otherMarkets.value) { - this.markets.otherMarkets.value = 0; - } - this.markets.developedMarkets.value += position.markets.developedMarkets * (isNumber(position.valueInBaseCurrency) @@ -447,6 +446,18 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { ) ? this.portfolioDetails.holdings[symbol].valueInBaseCurrency : this.portfolioDetails.holdings[symbol].valueInPercentage; + + this.markets[UNKNOWN_KEY].value += isNumber( + position.valueInBaseCurrency + ) + ? this.portfolioDetails.holdings[symbol].valueInBaseCurrency + : this.portfolioDetails.holdings[symbol].valueInPercentage; + + this.marketsAdvanced[UNKNOWN_KEY].value += isNumber( + position.valueInBaseCurrency + ) + ? this.portfolioDetails.holdings[symbol].valueInBaseCurrency + : this.portfolioDetails.holdings[symbol].valueInPercentage; } if (position.sectors.length > 0) { @@ -511,7 +522,8 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { const marketsTotal = this.markets.developedMarkets.value + this.markets.emergingMarkets.value + - this.markets.otherMarkets.value; + this.markets.otherMarkets.value + + this.markets[UNKNOWN_KEY].value; this.markets.developedMarkets.value = this.markets.developedMarkets.value / marketsTotal; @@ -519,6 +531,8 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { this.markets.emergingMarkets.value / marketsTotal; this.markets.otherMarkets.value = this.markets.otherMarkets.value / marketsTotal; + this.markets[UNKNOWN_KEY].value = + this.markets[UNKNOWN_KEY].value / marketsTotal; } public onAccountChartClicked({ symbol }: UniqueAsset) { 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 90a5dd3c9..50c4d8da3 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.html +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.html @@ -215,7 +215,7 @@ >