Browse Source

Improve unknown bucket grouping

pull/7011/head
Thomas Kaul 3 months ago
parent
commit
00d47e539a
  1. 10
      apps/api/src/app/portfolio/portfolio.service.ts
  2. 26
      apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts

10
apps/api/src/app/portfolio/portfolio.service.ts

@ -1453,7 +1453,6 @@ export class PortfolioService {
for (const [, position] of Object.entries(holdings)) {
const value = position.valueInBaseCurrency;
if (position.assetProfile.assetClass !== AssetClass.LIQUIDITY) {
if (position.assetProfile.countries.length > 0) {
markets.developedMarkets.valueInBaseCurrency +=
position.markets.developedMarkets * value;
@ -1479,7 +1478,6 @@ export class PortfolioService {
marketsAdvanced[UNKNOWN_KEY].valueInBaseCurrency += value;
}
}
}
const marketsTotalInBaseCurrency = getSum(
Object.values(markets).map(({ valueInBaseCurrency }) => {
@ -2163,11 +2161,14 @@ export class PortfolioService {
return withExcludedAccounts || account.isExcluded === false;
});
for (const account of currentAccounts) {
// Iterate over the accounts plus a null entry to group activities without
// an account into the unknown bucket
for (const account of [...currentAccounts, null]) {
const ordersByAccount = activities.filter(({ accountId }) => {
return accountId === account.id;
return account ? accountId === account.id : !accountId;
});
if (account) {
accounts[account.id] = {
balance: account.balance,
currency: account.currency,
@ -2198,6 +2199,7 @@ export class PortfolioService {
)
};
}
}
for (const {
account,

26
apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts

@ -201,6 +201,26 @@ export class GfAllocationsPageComponent implements OnInit {
}
}
private extractCurrency({
assetClass,
assetSubClass,
currency
}: {
assetClass: PortfolioPosition['assetProfile']['assetClass'];
assetSubClass: PortfolioPosition['assetProfile']['assetSubClass'];
currency?: PortfolioPosition['assetProfile']['currency'];
}) {
if (
assetClass === AssetClass.COMMODITY ||
assetSubClass === AssetSubClass.CRYPTOCURRENCY
) {
// Commodities and cryptocurrencies have no meaningful currency exposure
return UNKNOWN_KEY;
}
return currency;
}
private extractEtfProvider({
assetSubClass,
name
@ -339,7 +359,7 @@ export class GfAllocationsPageComponent implements OnInit {
position.assetProfile.assetSubClass || (UNKNOWN_KEY as AssetSubClass),
assetSubClassLabel:
position.assetProfile.assetSubClassLabel || UNKNOWN_KEY,
currency: position.assetProfile.currency,
currency: this.extractCurrency(position.assetProfile),
etfProvider: this.extractEtfProvider({
assetSubClass: position.assetProfile.assetSubClass,
name: position.assetProfile.name
@ -348,8 +368,7 @@ export class GfAllocationsPageComponent implements OnInit {
name: position.assetProfile.name
};
if (position.assetProfile.assetClass !== AssetClass.LIQUIDITY) {
// Prepare analysis data by continents, countries, holdings and sectors except for liquidity
// Prepare analysis data by continents, countries, holdings and sectors
if (position.assetProfile.countries.length > 0) {
for (const country of position.assetProfile.countries) {
@ -461,7 +480,6 @@ export class GfAllocationsPageComponent implements OnInit {
? this.portfolioDetails.holdings[symbol].valueInBaseCurrency
: this.portfolioDetails.holdings[symbol].valueInPercentage;
}
}
if (this.holdings[symbol].assetSubClass === 'ETF') {
this.totalValueInEtf += this.holdings[symbol].value;

Loading…
Cancel
Save