Browse Source

Refactoring

pull/5182/head
Thomas Kaul 4 weeks ago
parent
commit
553c0e0e32
  1. 26
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  2. 2
      apps/api/src/app/portfolio/interfaces/transaction-point-symbol.interface.ts
  3. 1
      libs/common/src/lib/config.ts

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

@ -288,12 +288,12 @@ export abstract class PortfolioCalculator {
firstIndex--; firstIndex--;
} }
const positions: (TimelinePosition & { const errors: ResponseError['errors'] = [];
isInvestmentAssetProfilePosition: boolean;
})[] = [];
let hasAnySymbolMetricsErrors = false; let hasAnySymbolMetricsErrors = false;
const errors: ResponseError['errors'] = []; const positions: (TimelinePosition & {
includeInHoldings: boolean;
})[] = [];
const accumulatedValuesByDate: { const accumulatedValuesByDate: {
[date: string]: { [date: string]: {
@ -412,9 +412,9 @@ export abstract class PortfolioCalculator {
grossPerformanceWithCurrencyEffect: !hasErrors grossPerformanceWithCurrencyEffect: !hasErrors
? (grossPerformanceWithCurrencyEffect ?? null) ? (grossPerformanceWithCurrencyEffect ?? null)
: null, : null,
includeInHoldings: item.includeInHoldings,
investment: totalInvestment, investment: totalInvestment,
investmentWithCurrencyEffect: totalInvestmentWithCurrencyEffect, investmentWithCurrencyEffect: totalInvestmentWithCurrencyEffect,
isInvestmentAssetProfilePosition: item.isInvestmentAssetProfileItem,
marketPrice: marketPrice:
marketSymbolMap[endDateString]?.[item.symbol]?.toNumber() ?? null, marketSymbolMap[endDateString]?.[item.symbol]?.toNumber() ?? null,
marketPriceInBaseCurrency: marketPriceInBaseCurrency:
@ -609,12 +609,12 @@ export abstract class PortfolioCalculator {
const overall = this.calculateOverallPerformance(positions); const overall = this.calculateOverallPerformance(positions);
const investmentPositions = positions const positionsIncludedInHoldings = positions
.filter(({ isInvestmentAssetProfilePosition }) => { .filter(({ includeInHoldings }) => {
return isInvestmentAssetProfilePosition; return includeInHoldings;
}) })
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
.map(({ isInvestmentAssetProfilePosition, ...rest }) => { .map(({ includeInHoldings, ...rest }) => {
return rest; return rest;
}); });
@ -625,7 +625,7 @@ export abstract class PortfolioCalculator {
totalInterestWithCurrencyEffect, totalInterestWithCurrencyEffect,
totalLiabilitiesWithCurrencyEffect, totalLiabilitiesWithCurrencyEffect,
hasErrors: hasAnySymbolMetricsErrors || overall.hasErrors, hasErrors: hasAnySymbolMetricsErrors || overall.hasErrors,
positions: investmentPositions positions: positionsIncludedInHoldings
}; };
} }
@ -948,8 +948,7 @@ export abstract class PortfolioCalculator {
dividend: new Big(0), dividend: new Big(0),
fee: oldAccumulatedSymbol.fee.plus(fee), fee: oldAccumulatedSymbol.fee.plus(fee),
firstBuyDate: oldAccumulatedSymbol.firstBuyDate, firstBuyDate: oldAccumulatedSymbol.firstBuyDate,
isInvestmentAssetProfileItem: includeInHoldings: oldAccumulatedSymbol.includeInHoldings,
oldAccumulatedSymbol.isInvestmentAssetProfileItem,
quantity: newQuantity, quantity: newQuantity,
tags: oldAccumulatedSymbol.tags.concat(tags), tags: oldAccumulatedSymbol.tags.concat(tags),
transactionCount: oldAccumulatedSymbol.transactionCount + 1 transactionCount: oldAccumulatedSymbol.transactionCount + 1
@ -965,9 +964,8 @@ export abstract class PortfolioCalculator {
averagePrice: unitPrice, averagePrice: unitPrice,
dividend: new Big(0), dividend: new Big(0),
firstBuyDate: date, firstBuyDate: date,
includeInHoldings: INVESTMENT_ACTIVITY_TYPES.includes(type),
investment: unitPrice.mul(quantity).mul(factor), investment: unitPrice.mul(quantity).mul(factor),
isInvestmentAssetProfileItem:
INVESTMENT_ACTIVITY_TYPES.includes(type),
quantity: quantity.mul(factor), quantity: quantity.mul(factor),
transactionCount: 1 transactionCount: 1
}; };

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

@ -8,8 +8,8 @@ export interface TransactionPointSymbol {
dividend: Big; dividend: Big;
fee: Big; fee: Big;
firstBuyDate: string; firstBuyDate: string;
includeInHoldings: boolean;
investment: Big; investment: Big;
isInvestmentAssetProfileItem: boolean;
quantity: Big; quantity: Big;
skipErrors: boolean; skipErrors: boolean;
symbol: string; symbol: string;

1
libs/common/src/lib/config.ts

@ -121,7 +121,6 @@ export const GATHER_HISTORICAL_MARKET_DATA_PROCESS_JOB_OPTIONS: JobOptions = {
export const INVESTMENT_ACTIVITY_TYPES = [ export const INVESTMENT_ACTIVITY_TYPES = [
Type.BUY, Type.BUY,
Type.DIVIDEND, Type.DIVIDEND,
Type.ITEM,
Type.SELL Type.SELL
] as Type[]; ] as Type[];

Loading…
Cancel
Save