Browse Source

Handle division by zero

pull/1398/head
Thomas 3 years ago
parent
commit
a30c58cd02
  1. 6
      apps/api/src/app/portfolio/portfolio-calculator.ts

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

@ -1036,10 +1036,12 @@ export class PortfolioCalculator {
const transactionInvestment =
order.type === 'BUY'
? order.quantity.mul(order.unitPrice).mul(this.getFactor(order.type))
: totalInvestment
: totalUnits.gt(0)
? totalInvestment
.div(totalUnits)
.mul(order.quantity)
.mul(this.getFactor(order.type));
.mul(this.getFactor(order.type))
: new Big(0);
if (PortfolioCalculator.ENABLE_LOGGING) {
console.log('totalInvestment', totalInvestment.toNumber());

Loading…
Cancel
Save