Browse Source

Feature/skip errors for custom asset profiles in portfolio snapshot calculation (#5175)

* Skip errors for custom asset profiles

* Update changelog
pull/5176/head
Thomas Kaul 6 days ago
committed by GitHub
parent
commit
e3546a53a5
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 24
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  3. 2
      apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts
  4. 1
      apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts

1
CHANGELOG.md

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved the label for asset profiles with `MANUAL` data source in the chart of the asset profile details dialog in the admin control panel - Improved the label for asset profiles with `MANUAL` data source in the chart of the asset profile details dialog in the admin control panel
- Improved the label for asset profiles with `MANUAL` data source in the chart of the holding detail dialog - Improved the label for asset profiles with `MANUAL` data source in the chart of the holding detail dialog
- Skipped errors for the custom asset profiles in the portfolio snapshot calculation
- Removed the date range query parameter from the search for the holdings in the assistant - Removed the date range query parameter from the search for the holdings in the assistant
- Improved the language localization for Chinese (`zh`) - Improved the language localization for Chinese (`zh`)
- Improved the language localization for Dutch (`nl`) - Improved the language localization for Dutch (`nl`)

24
apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

@ -446,7 +446,8 @@ export abstract class PortfolioCalculator {
currentRateErrors.find(({ dataSource, symbol }) => { currentRateErrors.find(({ dataSource, symbol }) => {
return dataSource === item.dataSource && symbol === item.symbol; return dataSource === item.dataSource && symbol === item.symbol;
})) && })) &&
item.investment.gt(0) item.investment.gt(0) &&
item.skipErrors === false
) { ) {
errors.push({ dataSource: item.dataSource, symbol: item.symbol }); errors.push({ dataSource: item.dataSource, symbol: item.symbol });
} }
@ -896,9 +897,14 @@ export abstract class PortfolioCalculator {
unitPrice unitPrice
} of this.activities) { } of this.activities) {
let currentTransactionPointItem: TransactionPointSymbol; let currentTransactionPointItem: TransactionPointSymbol;
const oldAccumulatedSymbol = symbols[SymbolProfile.symbol];
const currency = SymbolProfile.currency;
const dataSource = SymbolProfile.dataSource;
const factor = getFactor(type); const factor = getFactor(type);
const skipErrors = !!SymbolProfile.userId; // Skip errors for custom asset profiles
const symbol = SymbolProfile.symbol;
const oldAccumulatedSymbol = symbols[symbol];
if (oldAccumulatedSymbol) { if (oldAccumulatedSymbol) {
let investment = oldAccumulatedSymbol.investment; let investment = oldAccumulatedSymbol.investment;
@ -918,32 +924,34 @@ export abstract class PortfolioCalculator {
} }
currentTransactionPointItem = { currentTransactionPointItem = {
currency,
dataSource,
investment, investment,
skipErrors,
symbol,
averagePrice: newQuantity.gt(0) averagePrice: newQuantity.gt(0)
? investment.div(newQuantity) ? investment.div(newQuantity)
: new Big(0), : new Big(0),
currency: SymbolProfile.currency,
dataSource: SymbolProfile.dataSource,
dividend: new Big(0), dividend: new Big(0),
fee: oldAccumulatedSymbol.fee.plus(fee), fee: oldAccumulatedSymbol.fee.plus(fee),
firstBuyDate: oldAccumulatedSymbol.firstBuyDate, firstBuyDate: oldAccumulatedSymbol.firstBuyDate,
quantity: newQuantity, quantity: newQuantity,
symbol: SymbolProfile.symbol,
tags: oldAccumulatedSymbol.tags.concat(tags), tags: oldAccumulatedSymbol.tags.concat(tags),
transactionCount: oldAccumulatedSymbol.transactionCount + 1 transactionCount: oldAccumulatedSymbol.transactionCount + 1
}; };
} else { } else {
currentTransactionPointItem = { currentTransactionPointItem = {
currency,
dataSource,
fee, fee,
skipErrors,
symbol,
tags, tags,
averagePrice: unitPrice, averagePrice: unitPrice,
currency: SymbolProfile.currency,
dataSource: SymbolProfile.dataSource,
dividend: new Big(0), dividend: new Big(0),
firstBuyDate: date, firstBuyDate: date,
investment: unitPrice.mul(quantity).mul(factor), investment: unitPrice.mul(quantity).mul(factor),
quantity: quantity.mul(factor), quantity: quantity.mul(factor),
symbol: SymbolProfile.symbol,
transactionCount: 1 transactionCount: 1
}; };
} }

2
apps/api/src/app/portfolio/interfaces/portfolio-order.interface.ts

@ -6,7 +6,7 @@ export interface PortfolioOrder extends Pick<Activity, 'tags' | 'type'> {
quantity: Big; quantity: Big;
SymbolProfile: Pick< SymbolProfile: Pick<
Activity['SymbolProfile'], Activity['SymbolProfile'],
'currency' | 'dataSource' | 'name' | 'symbol' 'currency' | 'dataSource' | 'name' | 'symbol' | 'userId'
>; >;
unitPrice: Big; unitPrice: Big;
} }

1
apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts

@ -10,6 +10,7 @@ export interface TransactionPointSymbol {
firstBuyDate: string; firstBuyDate: string;
investment: Big; investment: Big;
quantity: Big; quantity: Big;
skipErrors: boolean;
symbol: string; symbol: string;
tags?: Tag[]; tags?: Tag[];
transactionCount: number; transactionCount: number;

Loading…
Cancel
Save