Browse Source

Readded Stake Handling

pull/5027/head
Dan 1 year ago
parent
commit
50f2f50dc2
  1. 7
      apps/api/src/app/import/import.service.ts
  2. 7
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  3. 12
      apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts
  4. 1
      apps/api/src/helper/portfolio.helper.ts

7
apps/api/src/app/import/import.service.ts

@ -604,7 +604,12 @@ export class ImportService {
)?.[symbol] )?.[symbol]
}; };
if (type === 'BUY' || type === 'DIVIDEND' || type === 'SELL') { if (
type === 'BUY' ||
type === 'DIVIDEND' ||
type === 'SELL' ||
type === 'STAKE'
) {
if (!assetProfile?.name) { if (!assetProfile?.name) {
throw new Error( throw new Error(
`activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")` `activities.${index}.symbol ("${symbol}") is not valid for the specified data source ("${dataSource}")`

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

@ -450,7 +450,12 @@ export abstract class PortfolioCalculator {
await this.currentRateService.getValues({ await this.currentRateService.getValues({
dataGatheringItems, dataGatheringItems,
dateQuery: { dateQuery: {
in: dates in: [
...dates,
...this.transactionPoints.map(({ date }) =>
resetHours(parseDate(date))
)
]
} }
}); });

12
apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts

@ -189,6 +189,7 @@ export class TWRPortfolioCalculator extends PortfolioCalculator {
} = {}; } = {};
let totalDividend = new Big(0); let totalDividend = new Big(0);
let totalStakeRewards = new Big(0);
let totalDividendInBaseCurrency = new Big(0); let totalDividendInBaseCurrency = new Big(0);
let totalInterest = new Big(0); let totalInterest = new Big(0);
let totalInterestInBaseCurrency = new Big(0); let totalInterestInBaseCurrency = new Big(0);
@ -421,6 +422,10 @@ export class TWRPortfolioCalculator extends PortfolioCalculator {
); );
} }
if (order.type === 'STAKE') {
order.unitPrice = marketSymbolMap[order.date]?.[symbol];
}
if (order.unitPrice) { if (order.unitPrice) {
order.unitPriceInBaseCurrency = order.unitPrice.mul( order.unitPriceInBaseCurrency = order.unitPrice.mul(
currentExchangeRate ?? 1 currentExchangeRate ?? 1
@ -568,6 +573,8 @@ export class TWRPortfolioCalculator extends PortfolioCalculator {
totalLiabilitiesInBaseCurrency = totalLiabilitiesInBaseCurrency.plus( totalLiabilitiesInBaseCurrency = totalLiabilitiesInBaseCurrency.plus(
liabilities.mul(exchangeRateAtOrderDate ?? 1) liabilities.mul(exchangeRateAtOrderDate ?? 1)
); );
} else if (order.type === 'STAKE') {
totalStakeRewards = totalStakeRewards.plus(order.quantity);
} }
const valueOfInvestment = totalUnits.mul(order.unitPriceInBaseCurrency); const valueOfInvestment = totalUnits.mul(order.unitPriceInBaseCurrency);
@ -647,7 +654,10 @@ export class TWRPortfolioCalculator extends PortfolioCalculator {
grossPerformanceWithCurrencyEffect; grossPerformanceWithCurrencyEffect;
} }
if (i > indexOfStartOrder && ['BUY', 'SELL'].includes(order.type)) { if (
i > indexOfStartOrder &&
['BUY', 'SELL', 'STAKE'].includes(order.type)
) {
// Only consider periods with an investment for the calculation of // Only consider periods with an investment for the calculation of
// the time weighted investment // the time weighted investment
if (valueOfInvestmentBeforeTransaction.gt(0)) { if (valueOfInvestmentBeforeTransaction.gt(0)) {

1
apps/api/src/helper/portfolio.helper.ts

@ -18,6 +18,7 @@ export function getFactor(activityType: ActivityType) {
switch (activityType) { switch (activityType) {
case 'BUY': case 'BUY':
case 'STAKE':
factor = 1; factor = 1;
break; break;
case 'SELL': case 'SELL':

Loading…
Cancel
Save