Browse Source

Take into account SPLIT in portfolio calculator

pull/3211/head
Nicolas Fedor 1 year ago
parent
commit
5e96a7d208
  1. 9
      apps/api/src/app/portfolio/portfolio-calculator.ts
  2. 4
      apps/api/src/app/portfolio/portfolio.service.ts
  3. 1
      apps/api/src/helper/portfolio.helper.ts

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

@ -90,9 +90,12 @@ export class PortfolioCalculator {
if (oldAccumulatedSymbol) { if (oldAccumulatedSymbol) {
let investment = oldAccumulatedSymbol.investment; let investment = oldAccumulatedSymbol.investment;
const newQuantity = order.quantity const newQuantity =
.mul(factor) order.type === 'SPLIT'
.plus(oldAccumulatedSymbol.quantity); ? order.quantity.s === 1
? oldAccumulatedSymbol.quantity.mul(order.quantity)
: oldAccumulatedSymbol.quantity.div(order.quantity)
: order.quantity.mul(factor).plus(oldAccumulatedSymbol.quantity);
if (order.type === 'BUY') { if (order.type === 'BUY') {
investment = oldAccumulatedSymbol.investment.plus( investment = oldAccumulatedSymbol.investment.plus(

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

@ -741,7 +741,9 @@ export class PortfolioService {
.filter((order) => { .filter((order) => {
tags = tags.concat(order.tags); tags = tags.concat(order.tags);
return ['BUY', 'DIVIDEND', 'ITEM', 'SELL'].includes(order.type); return ['BUY', 'DIVIDEND', 'ITEM', 'SELL', 'SPLIT'].includes(
order.type
);
}) })
.map((order) => ({ .map((order) => ({
currency: order.SymbolProfile.currency, currency: order.SymbolProfile.currency,

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

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

Loading…
Cancel
Save