Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Fix fee conversion (#2896)

Thomas Kaul8d5f2fd91d1d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8bdde333cb..51a3e0392b 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 5d4c57fa10..357b454fd8 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 e7295d89ad..8168e2bc2f 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(