Browse Source

Refactoring

pull/7610/head
Thomas Kaul 2 weeks ago
parent
commit
2df9077cb1
  1. 13
      apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts

13
apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts

@ -532,15 +532,18 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
); );
} else if (order.type === 'SELL') { } else if (order.type === 'SELL') {
if (totalUnits.gt(0)) { if (totalUnits.gt(0)) {
const remainingUnits = totalUnits.minus(order.quantity);
transactionInvestment = totalInvestment transactionInvestment = totalInvestment
.mul(remainingUnits)
.div(totalUnits) .div(totalUnits)
.mul(order.quantity) .minus(totalInvestment);
.mul(getFactor(order.type));
transactionInvestmentWithCurrencyEffect = transactionInvestmentWithCurrencyEffect =
totalInvestmentWithCurrencyEffect totalInvestmentWithCurrencyEffect
.mul(remainingUnits)
.div(totalUnits) .div(totalUnits)
.mul(order.quantity) .minus(totalInvestmentWithCurrencyEffect);
.mul(getFactor(order.type));
} }
} }
@ -636,10 +639,8 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator {
if (totalUnits.eq(0)) { if (totalUnits.eq(0)) {
// Reset tracking variables when position is fully closed // Reset tracking variables when position is fully closed
totalInvestment = new Big(0);
totalInvestmentFromBuyTransactions = new Big(0); totalInvestmentFromBuyTransactions = new Big(0);
totalInvestmentFromBuyTransactionsWithCurrencyEffect = new Big(0); totalInvestmentFromBuyTransactionsWithCurrencyEffect = new Big(0);
totalInvestmentWithCurrencyEffect = new Big(0);
totalQuantityFromBuyTransactions = new Big(0); totalQuantityFromBuyTransactions = new Big(0);
} }

Loading…
Cancel
Save