From f6d8d759c95a2476885ab2cbfc265dbaa4eef13a Mon Sep 17 00:00:00 2001 From: Daniel Devaud Date: Tue, 20 Feb 2024 21:05:35 +0100 Subject: [PATCH] Fix return of TotalDaysInvested --- .../src/app/portfolio/portfolio-calculator.ts | 63 ++++++++++--------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.ts index f177e85aa..d0b126452 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.ts @@ -422,7 +422,6 @@ export class PortfolioCalculator { accumulatedValuesByDate ); } - let values; const { investmentValueWithCurrencyEffect, @@ -1443,7 +1442,8 @@ export class PortfolioCalculator { averagePriceAtEndDate, initialValue, fees, - netPerformanceValuesPercentage + netPerformanceValuesPercentage, + totalInvestmentDays } = this.handleOrders( orders, indexOfStartOrder, @@ -1757,31 +1757,32 @@ export class PortfolioCalculator { grossPerformance.WithCurrencyEffect; } - this.calculatePerformancesForDate( - isChartMode, - i, - indexOfStartOrder, - currentValues, - order, - valueOfInvestment, - valueOfInvestmentBeforeTransaction, - netPerformanceValues, - grossPerformance, - grossPerformanceAtStartDate, - fees, - feesAtStartDate, - investmentValues, - investmentValuesAccumulated, - totalInvestment, - timeWeightedInvestmentValues, - previousOrderDateString, - totalInvestmentDays, - sumOfTimeWeightedInvestments, - valueAtStartDate, - investmentAtStartDate, - totalInvestmentBeforeTransaction, - transactionInvestment.WithCurrencyEffect - ); + totalInvestmentDays = + this.calculatePerformancesForDateAndReturnTotalInvestmentDays( + isChartMode, + i, + indexOfStartOrder, + currentValues, + order, + valueOfInvestment, + valueOfInvestmentBeforeTransaction, + netPerformanceValues, + grossPerformance, + grossPerformanceAtStartDate, + fees, + feesAtStartDate, + investmentValues, + investmentValuesAccumulated, + totalInvestment, + timeWeightedInvestmentValues, + previousOrderDateString, + totalInvestmentDays, + sumOfTimeWeightedInvestments, + valueAtStartDate, + investmentAtStartDate, + totalInvestmentBeforeTransaction, + transactionInvestment.WithCurrencyEffect + ); this.handleLoggingOfInvestmentMetrics( totalInvestment, @@ -1811,7 +1812,8 @@ export class PortfolioCalculator { averagePriceAtEndDate, initialValue, fees, - netPerformanceValuesPercentage + netPerformanceValuesPercentage, + totalInvestmentDays }; } @@ -2147,7 +2149,7 @@ export class PortfolioCalculator { }; } - private calculatePerformancesForDate( + private calculatePerformancesForDateAndReturnTotalInvestmentDays( isChartMode: boolean, i: number, indexOfStartOrder: number, @@ -2171,7 +2173,7 @@ export class PortfolioCalculator { investmentAtStartDate: WithCurrencyEffect, totalInvestmentBeforeTransaction: WithCurrencyEffect, transactionInvestmentWithCurrencyEffect: Big - ) { + ): number { if (i > indexOfStartOrder) { if (valueOfInvestmentBeforeTransaction.Value.gt(0)) { // Calculate the number of days since the previous order @@ -2246,6 +2248,7 @@ export class PortfolioCalculator { : new Big(0); } } + return totalInvestmentDays; } private calculateSellOrders(