From 8329d72d6e7ae04ab21adba365721ff6a78b1c50 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sat, 21 Aug 2021 11:26:55 +0200 Subject: [PATCH] Ignore cash assets in the allocation chart by sector, continent and country --- .../allocations/allocations-page.component.ts | 125 +++++++++--------- 1 file changed, 65 insertions(+), 60 deletions(-) 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 9d0ffbf22..cec11e5de 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 @@ -3,12 +3,13 @@ import { ToggleOption } from '@ghostfolio/client/components/toggle/interfaces/to import { DataService } from '@ghostfolio/client/services/data.service'; import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; import { UserService } from '@ghostfolio/client/services/user/user.service'; -import { UNKNOWN_KEY } from '@ghostfolio/common/config'; +import { ghostfolioCashSymbol, UNKNOWN_KEY } from '@ghostfolio/common/config'; import { PortfolioDetails, PortfolioPosition, User } from '@ghostfolio/common/interfaces'; +import { AssetClass } from '@prisma/client'; import { DeviceDetectorService } from 'ngx-device-detector'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -137,70 +138,74 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { }; this.positionsArray.push(position); - if (position.countries.length > 0) { - for (const country of position.countries) { - const { code, continent, name, weight } = country; - - if (this.continents[continent]?.value) { - this.continents[continent].value += weight * position.value; - } else { - this.continents[continent] = { - name: continent, - value: - weight * - (aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value) - }; - } - - if (this.countries[code]?.value) { - this.countries[code].value += weight * position.value; - } else { - this.countries[code] = { - name, - value: - weight * - (aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value) - }; + if (position.assetClass !== AssetClass.CASH) { + // Prepare analysis data by continents, countries and sectors except for cash + + if (position.countries.length > 0) { + for (const country of position.countries) { + const { code, continent, name, weight } = country; + + if (this.continents[continent]?.value) { + this.continents[continent].value += weight * position.value; + } else { + this.continents[continent] = { + name: continent, + value: + weight * + (aPeriod === 'original' + ? this.portfolioDetails.holdings[symbol].investment + : this.portfolioDetails.holdings[symbol].value) + }; + } + + if (this.countries[code]?.value) { + this.countries[code].value += weight * position.value; + } else { + this.countries[code] = { + name, + value: + weight * + (aPeriod === 'original' + ? this.portfolioDetails.holdings[symbol].investment + : this.portfolioDetails.holdings[symbol].value) + }; + } } + } else { + this.continents[UNKNOWN_KEY].value += + aPeriod === 'original' + ? this.portfolioDetails.holdings[symbol].investment + : this.portfolioDetails.holdings[symbol].value; + + this.countries[UNKNOWN_KEY].value += + aPeriod === 'original' + ? this.portfolioDetails.holdings[symbol].investment + : this.portfolioDetails.holdings[symbol].value; } - } else { - this.continents[UNKNOWN_KEY].value += - aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value; - this.countries[UNKNOWN_KEY].value += - aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value; - } - - if (position.sectors.length > 0) { - for (const sector of position.sectors) { - const { name, weight } = sector; - - if (this.sectors[name]?.value) { - this.sectors[name].value += weight * position.value; - } else { - this.sectors[name] = { - name, - value: - weight * - (aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value) - }; + if (position.sectors.length > 0) { + for (const sector of position.sectors) { + const { name, weight } = sector; + + if (this.sectors[name]?.value) { + this.sectors[name].value += weight * position.value; + } else { + this.sectors[name] = { + name, + value: + weight * + (aPeriod === 'original' + ? this.portfolioDetails.holdings[symbol].investment + : this.portfolioDetails.holdings[symbol].value) + }; + } } + } else { + this.sectors[UNKNOWN_KEY].value += + aPeriod === 'original' + ? this.portfolioDetails.holdings[symbol].investment + : this.portfolioDetails.holdings[symbol].value; } - } else { - this.sectors[UNKNOWN_KEY].value += - aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value; } } }