Browse Source

Ignore cash assets in the allocation chart by sector, continent and country

pull/308/head
Thomas 4 years ago
parent
commit
8329d72d6e
  1. 125
      apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts

125
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 { DataService } from '@ghostfolio/client/services/data.service';
import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service';
import { UserService } from '@ghostfolio/client/services/user/user.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 { import {
PortfolioDetails, PortfolioDetails,
PortfolioPosition, PortfolioPosition,
User User
} from '@ghostfolio/common/interfaces'; } from '@ghostfolio/common/interfaces';
import { AssetClass } from '@prisma/client';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
@ -137,70 +138,74 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
}; };
this.positionsArray.push(position); this.positionsArray.push(position);
if (position.countries.length > 0) { if (position.assetClass !== AssetClass.CASH) {
for (const country of position.countries) { // Prepare analysis data by continents, countries and sectors except for cash
const { code, continent, name, weight } = country;
if (position.countries.length > 0) {
if (this.continents[continent]?.value) { for (const country of position.countries) {
this.continents[continent].value += weight * position.value; const { code, continent, name, weight } = country;
} else {
this.continents[continent] = { if (this.continents[continent]?.value) {
name: continent, this.continents[continent].value += weight * position.value;
value: } else {
weight * this.continents[continent] = {
(aPeriod === 'original' name: continent,
? this.portfolioDetails.holdings[symbol].investment value:
: this.portfolioDetails.holdings[symbol].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] = { if (this.countries[code]?.value) {
name, this.countries[code].value += weight * position.value;
value: } else {
weight * this.countries[code] = {
(aPeriod === 'original' name,
? this.portfolioDetails.holdings[symbol].investment value:
: this.portfolioDetails.holdings[symbol].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 += if (position.sectors.length > 0) {
aPeriod === 'original' for (const sector of position.sectors) {
? this.portfolioDetails.holdings[symbol].investment const { name, weight } = sector;
: this.portfolioDetails.holdings[symbol].value;
} if (this.sectors[name]?.value) {
this.sectors[name].value += weight * position.value;
if (position.sectors.length > 0) { } else {
for (const sector of position.sectors) { this.sectors[name] = {
const { name, weight } = sector; name,
value:
if (this.sectors[name]?.value) { weight *
this.sectors[name].value += weight * position.value; (aPeriod === 'original'
} else { ? this.portfolioDetails.holdings[symbol].investment
this.sectors[name] = { : this.portfolioDetails.holdings[symbol].value)
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;
} }
} }
} }

Loading…
Cancel
Save