Browse Source

Feature/improve allocations by etf holding for impersonation mode (#3534)

* Improve allocations by ETF holding for impersonation mode

* Update changelog
pull/3540/head
Thomas Kaul 7 months ago
committed by GitHub
parent
commit
1c9805bb96
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 12
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 3
      apps/api/src/services/symbol-profile/symbol-profile.service.ts
  4. 38
      apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts

1
CHANGELOG.md

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Improved the allocations by ETF holding on the allocations page for the impersonation mode (experimental)
- Improved the detection of REST APIs (`JSON`) used via the scraper configuration - Improved the detection of REST APIs (`JSON`) used via the scraper configuration
## 2.92.0 - 2024-06-30 ## 2.92.0 - 2024-06-30

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

@ -499,7 +499,17 @@ export class PortfolioService {
grossPerformancePercentageWithCurrencyEffect?.toNumber() ?? 0, grossPerformancePercentageWithCurrencyEffect?.toNumber() ?? 0,
grossPerformanceWithCurrencyEffect: grossPerformanceWithCurrencyEffect:
grossPerformanceWithCurrencyEffect?.toNumber() ?? 0, grossPerformanceWithCurrencyEffect?.toNumber() ?? 0,
holdings: assetProfile.holdings, holdings: assetProfile.holdings.map(
({ allocationInPercentage, name }) => {
return {
allocationInPercentage,
name,
valueInBaseCurrency: valueInBaseCurrency
.mul(allocationInPercentage)
.toNumber()
};
}
),
investment: investment.toNumber(), investment: investment.toNumber(),
marketState: dataProviderResponse?.marketState ?? 'delayed', marketState: dataProviderResponse?.marketState ?? 'delayed',
name: assetProfile.name, name: assetProfile.name,

3
apps/api/src/services/symbol-profile/symbol-profile.service.ts

@ -221,8 +221,9 @@ export class SymbolProfileService {
const { name, weight } = holding as Prisma.JsonObject; const { name, weight } = holding as Prisma.JsonObject;
return { return {
allocationInPercentage: weight as number,
name: (name as string) ?? UNKNOWN_KEY, name: (name as string) ?? UNKNOWN_KEY,
valueInBaseCurrency: weight as number valueInBaseCurrency: undefined
}; };
} }
); );

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

@ -454,33 +454,25 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
if (position.holdings.length > 0) { if (position.holdings.length > 0) {
for (const holding of position.holdings) { for (const holding of position.holdings) {
const { name, valueInBaseCurrency } = holding; const { allocationInPercentage, name, valueInBaseCurrency } =
holding;
if (
!this.hasImpersonationId &&
!this.user.settings.isRestrictedView
) {
if (this.topHoldingsMap[name]?.value) { if (this.topHoldingsMap[name]?.value) {
this.topHoldingsMap[name].value += this.topHoldingsMap[name].value += isNumber(valueInBaseCurrency)
valueInBaseCurrency * ? valueInBaseCurrency
(isNumber(position.valueInBaseCurrency) : allocationInPercentage *
? position.valueInBaseCurrency this.portfolioDetails.holdings[symbol].valueInPercentage;
: position.valueInPercentage);
} else { } else {
this.topHoldingsMap[name] = { this.topHoldingsMap[name] = {
name, name,
value: value: isNumber(valueInBaseCurrency)
valueInBaseCurrency * ? valueInBaseCurrency
(isNumber(position.valueInBaseCurrency) : allocationInPercentage *
? this.portfolioDetails.holdings[symbol] this.portfolioDetails.holdings[symbol].valueInPercentage
.valueInBaseCurrency
: this.portfolioDetails.holdings[symbol]
.valueInPercentage)
}; };
} }
} }
} }
}
if (position.sectors.length > 0) { if (position.sectors.length > 0) {
for (const sector of position.sectors) { for (const sector of position.sectors) {
@ -562,6 +554,14 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
this.topHoldings = Object.values(this.topHoldingsMap) this.topHoldings = Object.values(this.topHoldingsMap)
.map(({ name, value }) => { .map(({ name, value }) => {
if (this.hasImpersonationId || this.user.settings.isRestrictedView) {
return {
name,
allocationInPercentage: value,
valueInBaseCurrency: null
};
}
return { return {
name, name,
allocationInPercentage: allocationInPercentage:
@ -570,7 +570,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit {
}; };
}) })
.sort((a, b) => { .sort((a, b) => {
return b.valueInBaseCurrency - a.valueInBaseCurrency; return b.allocationInPercentage - a.allocationInPercentage;
}); });
if (this.topHoldings.length > MAX_TOP_HOLDINGS) { if (this.topHoldings.length > MAX_TOP_HOLDINGS) {

Loading…
Cancel
Save