From 043a77b71a867946d4dd8ebb07da1b564476b6c2 Mon Sep 17 00:00:00 2001 From: Dan Date: Thu, 1 May 2025 15:38:20 +0200 Subject: [PATCH] Remove log performance + plus further work on performance calculation --- ...rtfolio-calculator-symbolmetrics-helper.ts | 1 - .../calculator/roi/portfolio-calculator.ts | 27 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/apps/api/src/app/portfolio/calculator/roi/portfolio-calculator-symbolmetrics-helper.ts b/apps/api/src/app/portfolio/calculator/roi/portfolio-calculator-symbolmetrics-helper.ts index 2bae172a6..656988f63 100644 --- a/apps/api/src/app/portfolio/calculator/roi/portfolio-calculator-symbolmetrics-helper.ts +++ b/apps/api/src/app/portfolio/calculator/roi/portfolio-calculator-symbolmetrics-helper.ts @@ -121,7 +121,6 @@ export class RoiPortfolioCalculatorSymbolMetricsHelper { } } - @LogPerformance public processOrderMetrics( orders: PortfolioOrderItem[], i: number, diff --git a/apps/api/src/app/portfolio/calculator/roi/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/roi/portfolio-calculator.ts index b11896557..156dff719 100644 --- a/apps/api/src/app/portfolio/calculator/roi/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/roi/portfolio-calculator.ts @@ -52,11 +52,34 @@ export class RoiPortfolioCalculator extends PortfolioCalculator { let netPerformanceWithCurrencyEffect: number; let netPerformanceInPercentageWithCurrencyEffect: number; + const totalInvestments = positions.reduce( + (total, position) => { + return { + total: total.total.plus(position.investment), + totalWithCurrencyEffect: total.totalWithCurrencyEffect.plus( + position.investmentWithCurrencyEffect + ) + }; + }, + { total: new Big(0), totalWithCurrencyEffect: new Big(0) } + ); for (const position of positions) { netPerformance = netPerformance + position.netPerformance.toNumber(); + // TODO GET Net performance with currency effect netPerformanceInPercentage = - netPerformanceInPercentage * - position.valueInBaseCurrency.div(netWorth).toNumber(); + netPerformanceInPercentage + + position.netPerformancePercentage + .mul(position.investment.div(totalInvestments.total)) + .toNumber(); + netPerformanceInPercentageWithCurrencyEffect = + netPerformanceInPercentageWithCurrencyEffect + + position.netPerformancePercentage + .mul( + position.investmentWithCurrencyEffect.div( + totalInvestments.totalWithCurrencyEffect + ) + ) + .toNumber(); //TODO Calculate performance values not using chart }