diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d723806..fda0209e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the position of the currency column in the accounts table - Improved the position of the currency column in the activities table +### Fixed + +- Fixed an issue with the performance calculation in connection with fees in the new calculation engine + ## 1.112.1 - 06.02.2022 ### Fixed diff --git a/apps/api/src/app/portfolio/portfolio-calculator-new.ts b/apps/api/src/app/portfolio/portfolio-calculator-new.ts index 6f95fd3a..ebf18188 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator-new.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator-new.ts @@ -82,7 +82,7 @@ export class PortfolioCalculatorNew { : unitPrice .mul(order.quantity) .mul(factor) - .add(oldAccumulatedSymbol.investment), + .plus(oldAccumulatedSymbol.investment), quantity: newQuantity, symbol: order.symbol, transactionCount: oldAccumulatedSymbol.transactionCount + 1 @@ -452,7 +452,7 @@ export class PortfolioCalculatorNew { .eq(0) ) { const grossHoldingPeriodReturn = valueOfInvestmentBeforeTransaction - .sub( + .minus( lastValueOfInvestmentBeforeTransaction.plus( lastTransactionInvestment ) @@ -469,8 +469,8 @@ export class PortfolioCalculatorNew { ); const netHoldingPeriodReturn = valueOfInvestmentBeforeTransaction - .sub(fees.minus(feesAtStartDate)) - .sub( + .minus(fees.minus(feesAtStartDate)) + .minus( lastValueOfInvestmentBeforeTransaction.plus( lastTransactionInvestment ) @@ -509,10 +509,10 @@ export class PortfolioCalculatorNew { } timeWeightedGrossPerformancePercentage = - timeWeightedGrossPerformancePercentage.sub(1); + timeWeightedGrossPerformancePercentage.minus(1); timeWeightedNetPerformancePercentage = - timeWeightedNetPerformancePercentage.sub(1); + timeWeightedNetPerformancePercentage.minus(1); const totalGrossPerformance = grossPerformance.minus( grossPerformanceAtStartDate @@ -525,7 +525,7 @@ export class PortfolioCalculatorNew { let valueOfInvestmentSum = new Big(0); for (const holdingPeriodPerformance of holdingPeriodPerformances) { - valueOfInvestmentSum = valueOfInvestmentSum.add( + valueOfInvestmentSum = valueOfInvestmentSum.plus( holdingPeriodPerformance.valueOfInvestment ); } @@ -568,7 +568,7 @@ export class PortfolioCalculatorNew { date: transactionPoint.date, investment: transactionPoint.items.reduce( (investment, transactionPointSymbol) => - investment.add(transactionPointSymbol.investment), + investment.plus(transactionPointSymbol.investment), new Big(0) ) }; @@ -685,13 +685,13 @@ export class PortfolioCalculatorNew { for (const currentPosition of positions) { if (currentPosition.marketPrice) { - currentValue = currentValue.add( + currentValue = currentValue.plus( new Big(currentPosition.marketPrice).mul(currentPosition.quantity) ); } else { hasErrors = true; } - totalInvestment = totalInvestment.add(currentPosition.investment); + totalInvestment = totalInvestment.plus(currentPosition.investment); if (currentPosition.grossPerformance) { grossPerformance = grossPerformance.plus( currentPosition.grossPerformance @@ -760,8 +760,8 @@ export class PortfolioCalculatorNew { dataSource: item.dataSource, symbol: item.symbol }); - investment = investment.add(item.investment); - fees = fees.add(item.fee); + investment = investment.plus(item.investment); + fees = fees.plus(item.fee); } let marketSymbols: GetValueObject[] = []; @@ -817,7 +817,7 @@ export class PortfolioCalculatorNew { invalid = true; break; } - value = value.add( + value = value.plus( item.quantity.mul(marketSymbolMap[currentDateAsString][item.symbol]) ); } diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.ts index f69349fa..1bdc03de 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.ts @@ -69,7 +69,7 @@ export class PortfolioCalculator { : unitPrice .mul(order.quantity) .mul(factor) - .add(oldAccumulatedSymbol.investment), + .plus(oldAccumulatedSymbol.investment), quantity: newQuantity, symbol: order.symbol, transactionCount: oldAccumulatedSymbol.transactionCount + 1 @@ -354,7 +354,7 @@ export class PortfolioCalculator { date: transactionPoint.date, investment: transactionPoint.items.reduce( (investment, transactionPointSymbol) => - investment.add(transactionPointSymbol.investment), + investment.plus(transactionPointSymbol.investment), new Big(0) ) }; @@ -475,13 +475,13 @@ export class PortfolioCalculator { for (const currentPosition of positions) { if (currentPosition.marketPrice) { - currentValue = currentValue.add( + currentValue = currentValue.plus( new Big(currentPosition.marketPrice).mul(currentPosition.quantity) ); } else { hasErrors = true; } - totalInvestment = totalInvestment.add(currentPosition.investment); + totalInvestment = totalInvestment.plus(currentPosition.investment); if (currentPosition.grossPerformance) { grossPerformance = grossPerformance.plus( currentPosition.grossPerformance @@ -562,8 +562,8 @@ export class PortfolioCalculator { dataSource: item.dataSource, symbol: item.symbol }); - investment = investment.add(item.investment); - fees = fees.add(item.fee); + investment = investment.plus(item.investment); + fees = fees.plus(item.fee); } let marketSymbols: GetValueObject[] = []; @@ -619,7 +619,7 @@ export class PortfolioCalculator { invalid = true; break; } - value = value.add( + value = value.plus( item.quantity.mul(marketSymbolMap[currentDateAsString][item.symbol]) ); } diff --git a/apps/api/src/app/portfolio/portfolio.service-new.ts b/apps/api/src/app/portfolio/portfolio.service-new.ts index 64d4ea0a..4fbbeaff 100644 --- a/apps/api/src/app/portfolio/portfolio.service-new.ts +++ b/apps/api/src/app/portfolio/portfolio.service-new.ts @@ -895,7 +895,7 @@ export class PortfolioServiceNew { const totalBuy = this.getTotalByType(orders, userCurrency, 'BUY'); const totalSell = this.getTotalByType(orders, userCurrency, 'SELL'); - const committedFunds = new Big(totalBuy).sub(totalSell); + const committedFunds = new Big(totalBuy).minus(totalSell); const netWorth = new Big(balance) .plus(performanceInformation.performance.currentValue) diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 5cd06dc5..84ac4c84 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -873,7 +873,7 @@ export class PortfolioService { const totalBuy = this.getTotalByType(orders, userCurrency, 'BUY'); const totalSell = this.getTotalByType(orders, userCurrency, 'SELL'); - const committedFunds = new Big(totalBuy).sub(totalSell); + const committedFunds = new Big(totalBuy).minus(totalSell); const netWorth = new Big(balance) .plus(performanceInformation.performance.currentValue)