From 8d5f2fd91d1d342e8e89ea634e11c60afe006c38 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 21 Jan 2024 10:24:43 +0100 Subject: [PATCH] Fix fee conversion (#2896) * Fix fee conversion * Update changelog --- CHANGELOG.md | 6 +++++- .../interfaces/portfolio-calculator.interface.ts | 2 ++ apps/api/src/app/portfolio/portfolio-calculator.ts | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bdde333c..51a3e0392 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Improved the language localization for German (`de`) - Upgraded `prisma` from version `5.7.1` to `5.8.1` +### Fixed + +- Fixed an issue in the performance calculation with the currency conversion of fees + ## 2.41.0 - 2024-01-16 ### Added @@ -3034,7 +3038,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed an issue with the user currency of the public page -- Fixed an issue of the performance calculation with recent activities in the new calculation engine +- Fixed an issue in the performance calculation with recent activities in the new calculation engine ## 1.127.0 - 16.03.2022 diff --git a/apps/api/src/app/portfolio/interfaces/portfolio-calculator.interface.ts b/apps/api/src/app/portfolio/interfaces/portfolio-calculator.interface.ts index 5d4c57fa1..357b454fd 100644 --- a/apps/api/src/app/portfolio/interfaces/portfolio-calculator.interface.ts +++ b/apps/api/src/app/portfolio/interfaces/portfolio-calculator.interface.ts @@ -3,6 +3,8 @@ import Big from 'big.js'; import { PortfolioOrder } from './portfolio-order.interface'; export interface PortfolioOrderItem extends PortfolioOrder { + feeInBaseCurrency?: Big; + feeInBaseCurrencyWithCurrencyEffect?: Big; itemType?: '' | 'start' | 'end'; unitPriceInBaseCurrency?: Big; unitPriceInBaseCurrencyWithCurrencyEffect?: Big; diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/portfolio-calculator.ts index e7295d89a..8168e2bc2 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/portfolio-calculator.ts @@ -1266,6 +1266,7 @@ export class PortfolioCalculator { date: format(start, DATE_FORMAT), dataSource: null, fee: new Big(0), + feeInBaseCurrency: new Big(0), itemType: 'start', name: '', quantity: new Big(0), @@ -1279,6 +1280,7 @@ export class PortfolioCalculator { date: format(end, DATE_FORMAT), dataSource: null, fee: new Big(0), + feeInBaseCurrency: new Big(0), itemType: 'end', name: '', quantity: new Big(0), @@ -1306,6 +1308,7 @@ export class PortfolioCalculator { date: format(day, DATE_FORMAT), dataSource: null, fee: new Big(0), + feeInBaseCurrency: new Big(0), name: '', quantity: new Big(0), type: TypeOfOrder.BUY, @@ -1369,6 +1372,13 @@ export class PortfolioCalculator { : unitPriceAtStartDate; } + if (order.fee) { + order.feeInBaseCurrency = order.fee.mul(currentExchangeRate ?? 1); + order.feeInBaseCurrencyWithCurrencyEffect = order.fee.mul( + exchangeRateAtOrderDate ?? 1 + ); + } + if (order.unitPrice) { order.unitPriceInBaseCurrency = order.unitPrice.mul( currentExchangeRate ?? 1 @@ -1468,10 +1478,10 @@ export class PortfolioCalculator { } } - fees = fees.plus(order.fee); + fees = fees.plus(order.feeInBaseCurrency ?? 0); feesWithCurrencyEffect = feesWithCurrencyEffect.plus( - order.fee.mul(exchangeRateAtOrderDate ?? 1) + order.feeInBaseCurrencyWithCurrencyEffect ?? 0 ); totalUnits = totalUnits.plus(