From 2df9077cb1dde547ca7871efe0070a54bb681ca4 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Thu, 13 Aug 2026 13:41:46 +0200 Subject: [PATCH] Refactoring --- .../calculator/roai/portfolio-calculator.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts index 7090e346b..48cbab170 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator.ts @@ -532,15 +532,18 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { ); } else if (order.type === 'SELL') { if (totalUnits.gt(0)) { + const remainingUnits = totalUnits.minus(order.quantity); + transactionInvestment = totalInvestment + .mul(remainingUnits) .div(totalUnits) - .mul(order.quantity) - .mul(getFactor(order.type)); + .minus(totalInvestment); + transactionInvestmentWithCurrencyEffect = totalInvestmentWithCurrencyEffect + .mul(remainingUnits) .div(totalUnits) - .mul(order.quantity) - .mul(getFactor(order.type)); + .minus(totalInvestmentWithCurrencyEffect); } } @@ -636,10 +639,8 @@ export class RoaiPortfolioCalculator extends PortfolioCalculator { if (totalUnits.eq(0)) { // Reset tracking variables when position is fully closed - totalInvestment = new Big(0); totalInvestmentFromBuyTransactions = new Big(0); totalInvestmentFromBuyTransactionsWithCurrencyEffect = new Big(0); - totalInvestmentWithCurrencyEffect = new Big(0); totalQuantityFromBuyTransactions = new Big(0); }