From 90103582a7bef21af018b47630aa6c394da285c1 Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Fri, 15 Nov 2024 00:22:36 +0100 Subject: [PATCH] Calculate and include parent holdings allocation per holding (ETF) --- .../allocations/allocations-page.component.ts | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 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 e647c54fb..d489e38eb 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 @@ -7,7 +7,7 @@ import { MAX_TOP_HOLDINGS, UNKNOWN_KEY } from '@ghostfolio/common/config'; import { prettifySymbol } from '@ghostfolio/common/helper'; import { AssetProfileIdentifier, - Holding, + HoldingWithParents, PortfolioDetails, PortfolioPosition, User @@ -86,7 +86,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { value: number; }; }; - public topHoldings: Holding[]; + public topHoldings: HoldingWithParents[]; public topHoldingsMap: { [name: string]: { name: string; value: number }; }; @@ -490,7 +490,31 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { name, allocationInPercentage: this.totalValueInEtf > 0 ? value / this.totalValueInEtf : 0, - valueInBaseCurrency: value + valueInBaseCurrency: value, + parents: Object.entries(this.portfolioDetails.holdings) + .map(([symbol, holding]) => { + if (holding.holdings) { + const parentHoldings = holding.holdings; + for (const index in parentHoldings) { + if (name === parentHoldings[index].name) { + return { + name: symbol, + allocationInPercentage: + (parentHoldings[index].valueInBaseCurrency / value) * + 100, + valueInBaseCurrency: + parentHoldings[index].valueInBaseCurrency + }; + } + } + } + + return null; + }) + .filter((item) => null !== item) + .sort((a, b) => { + return b.allocationInPercentage - a.allocationInPercentage; + }) }; }) .sort((a, b) => {