From f209519d958cad60381db5dedae4f0227c5f2dfb Mon Sep 17 00:00:00 2001 From: csehatt741 <77381875+csehatt741@users.noreply.github.com> Date: Sun, 27 Apr 2025 14:26:14 +0200 Subject: [PATCH] Bugfix/investment calculation for activities in custom currency (#4597) * Investment calculation for activities in custom currency * Update changelog --- CHANGELOG.md | 1 + .../portfolio-calculator-test-utils.ts | 2 + .../calculator/portfolio-calculator.ts | 2 +- .../roai/portfolio-calculator-btceur.spec.ts | 238 ++++++++++++++++++ .../roai/portfolio-calculator-btcusd.spec.ts | 238 ++++++++++++++++++ ...-calculator-msft-buy-with-dividend.spec.ts | 13 - .../portfolio/current-rate.service.mock.ts | 4 + .../src/app/portfolio/portfolio.service.ts | 14 +- 8 files changed, 494 insertions(+), 18 deletions(-) create mode 100644 apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur.spec.ts create mode 100644 apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 580489cd..9cace5a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed an issue with the investment calculation for activities in a custom currency - Improved the file selector of the activities import functionality to accept case-insensitive file extensions (`.CSV` and `.JSON`) - Fixed the missing localization for "someone" on the public page diff --git a/apps/api/src/app/portfolio/calculator/portfolio-calculator-test-utils.ts b/apps/api/src/app/portfolio/calculator/portfolio-calculator-test-utils.ts index 2c9f7b6f..db80652c 100644 --- a/apps/api/src/app/portfolio/calculator/portfolio-calculator-test-utils.ts +++ b/apps/api/src/app/portfolio/calculator/portfolio-calculator-test-utils.ts @@ -7,10 +7,12 @@ export const activityDummyData = { createdAt: new Date(), currency: undefined, fee: undefined, + feeInAssetProfileCurrency: undefined, id: undefined, isDraft: false, symbolProfileId: undefined, unitPrice: undefined, + unitPriceInAssetProfileCurrency: undefined, updatedAt: new Date(), userId: undefined, value: undefined, diff --git a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts index 850b5811..99aeb42f 100644 --- a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts @@ -902,8 +902,8 @@ export abstract class PortfolioCalculator { let lastTransactionPoint: TransactionPoint = null; for (const { - fee, date, + fee, quantity, SymbolProfile, tags, diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur.spec.ts new file mode 100644 index 00000000..2c5b9005 --- /dev/null +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btceur.spec.ts @@ -0,0 +1,238 @@ +import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto'; +import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; +import { + activityDummyData, + loadActivityExportFile, + symbolProfileDummyData, + userDummyData +} from '@ghostfolio/api/app/portfolio/calculator/portfolio-calculator-test-utils'; +import { PortfolioCalculatorFactory } from '@ghostfolio/api/app/portfolio/calculator/portfolio-calculator.factory'; +import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentRateServiceMock } from '@ghostfolio/api/app/portfolio/current-rate.service.mock'; +import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service'; +import { RedisCacheServiceMock } from '@ghostfolio/api/app/redis-cache/redis-cache.service.mock'; +import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; +import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; +import { PortfolioSnapshotService } from '@ghostfolio/api/services/queues/portfolio-snapshot/portfolio-snapshot.service'; +import { PortfolioSnapshotServiceMock } from '@ghostfolio/api/services/queues/portfolio-snapshot/portfolio-snapshot.service.mock'; +import { parseDate } from '@ghostfolio/common/helper'; +import { PerformanceCalculationType } from '@ghostfolio/common/types/performance-calculation-type.type'; + +import { Big } from 'big.js'; +import { join } from 'path'; + +jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { + return { + // eslint-disable-next-line @typescript-eslint/naming-convention + CurrentRateService: jest.fn().mockImplementation(() => { + return CurrentRateServiceMock; + }) + }; +}); + +jest.mock( + '@ghostfolio/api/services/queues/portfolio-snapshot/portfolio-snapshot.service', + () => { + return { + // eslint-disable-next-line @typescript-eslint/naming-convention + PortfolioSnapshotService: jest.fn().mockImplementation(() => { + return PortfolioSnapshotServiceMock; + }) + }; + } +); + +jest.mock('@ghostfolio/api/app/redis-cache/redis-cache.service', () => { + return { + // eslint-disable-next-line @typescript-eslint/naming-convention + RedisCacheService: jest.fn().mockImplementation(() => { + return RedisCacheServiceMock; + }) + }; +}); + +describe('PortfolioCalculator', () => { + let activityDtos: CreateOrderDto[]; + + let configurationService: ConfigurationService; + let currentRateService: CurrentRateService; + let exchangeRateDataService: ExchangeRateDataService; + let portfolioCalculatorFactory: PortfolioCalculatorFactory; + let portfolioSnapshotService: PortfolioSnapshotService; + let redisCacheService: RedisCacheService; + + beforeAll(() => { + activityDtos = loadActivityExportFile( + join(__dirname, '../../../../../../../test/import/ok-btceur.json') + ); + }); + + beforeEach(() => { + configurationService = new ConfigurationService(); + + currentRateService = new CurrentRateService(null, null, null, null); + + exchangeRateDataService = new ExchangeRateDataService( + null, + null, + null, + null + ); + + portfolioSnapshotService = new PortfolioSnapshotService(null); + + redisCacheService = new RedisCacheService(null, null); + + portfolioCalculatorFactory = new PortfolioCalculatorFactory( + configurationService, + currentRateService, + exchangeRateDataService, + portfolioSnapshotService, + redisCacheService + ); + }); + + describe('get current positions', () => { + it.only('with BTCUSD buy (in EUR)', async () => { + jest.useFakeTimers().setSystemTime(parseDate('2022-01-14').getTime()); + + const activities: Activity[] = activityDtos.map((activity) => ({ + ...activityDummyData, + ...activity, + date: parseDate(activity.date), + feeInAssetProfileCurrency: 4.46, + SymbolProfile: { + ...symbolProfileDummyData, + currency: 'USD', + dataSource: activity.dataSource, + name: 'Bitcoin', + symbol: activity.symbol + }, + unitPriceInAssetProfileCurrency: 44558.42 + })); + + const portfolioCalculator = portfolioCalculatorFactory.createCalculator({ + activities, + calculationType: PerformanceCalculationType.ROAI, + currency: 'USD', + userId: userDummyData.id + }); + + const portfolioSnapshot = await portfolioCalculator.computeSnapshot(); + + const investments = portfolioCalculator.getInvestments(); + + const investmentsByMonth = portfolioCalculator.getInvestmentsByGroup({ + data: portfolioSnapshot.historicalData, + groupBy: 'month' + }); + + expect(portfolioSnapshot.historicalData[0]).toEqual({ + date: '2021-12-11', + investmentValueWithCurrencyEffect: 0, + netPerformance: 0, + netPerformanceInPercentage: 0, + netPerformanceInPercentageWithCurrencyEffect: 0, + netPerformanceWithCurrencyEffect: 0, + netWorth: 0, + totalAccountBalance: 0, + totalInvestment: 0, + totalInvestmentValueWithCurrencyEffect: 0, + value: 0, + valueWithCurrencyEffect: 0 + }); + + expect(portfolioSnapshot.historicalData[1]).toEqual({ + date: '2021-12-12', + investmentValueWithCurrencyEffect: 44558.42, + netPerformance: -4.46, + netPerformanceInPercentage: 0, + netPerformanceInPercentageWithCurrencyEffect: 0, + netPerformanceWithCurrencyEffect: -4.46, + netWorth: 44558.42, + totalAccountBalance: 0, + totalInvestment: 44558.42, + totalInvestmentValueWithCurrencyEffect: 44558.42, + value: 44558.42, + valueWithCurrencyEffect: 44558.42 + }); + + expect( + portfolioSnapshot.historicalData[ + portfolioSnapshot.historicalData.length - 1 + ] + ).toEqual({ + date: '2022-01-14', + investmentValueWithCurrencyEffect: 0, + netPerformance: -1463.18, + netPerformanceInPercentage: -0.032837340282712, + netPerformanceInPercentageWithCurrencyEffect: -0.032837340282712, + netPerformanceWithCurrencyEffect: -1463.18, + netWorth: 43099.7, + totalAccountBalance: 0, + totalInvestment: 44558.42, + totalInvestmentValueWithCurrencyEffect: 44558.42, + value: 43099.7, + valueWithCurrencyEffect: 43099.7 + }); + + expect(portfolioSnapshot).toMatchObject({ + currentValueInBaseCurrency: new Big('43099.7'), + errors: [], + hasErrors: false, + positions: [ + { + averagePrice: new Big('44558.42'), + currency: 'USD', + dataSource: 'YAHOO', + dividend: new Big('0'), + dividendInBaseCurrency: new Big('0'), + fee: new Big('4.46'), + feeInBaseCurrency: new Big('4.46'), + firstBuyDate: '2021-12-12', + grossPerformance: new Big('-1458.72'), + grossPerformancePercentage: new Big('-0.03273724696701543726'), + grossPerformancePercentageWithCurrencyEffect: new Big( + '-0.03273724696701543726' + ), + grossPerformanceWithCurrencyEffect: new Big('-1458.72'), + investment: new Big('44558.42'), + investmentWithCurrencyEffect: new Big('44558.42'), + netPerformance: new Big('-1463.18'), + netPerformancePercentage: new Big('-0.03283734028271199921'), + netPerformancePercentageWithCurrencyEffectMap: { + max: new Big('-0.03283734028271199921') + }, + netPerformanceWithCurrencyEffectMap: { + max: new Big('-1463.18') + }, + marketPrice: 43099.7, + marketPriceInBaseCurrency: 43099.7, + quantity: new Big('1'), + symbol: 'BTCUSD', + tags: [], + timeWeightedInvestment: new Big('44558.42'), + timeWeightedInvestmentWithCurrencyEffect: new Big('44558.42'), + transactionCount: 1, + valueInBaseCurrency: new Big('43099.7') + } + ], + totalFeesWithCurrencyEffect: new Big('4.46'), + totalInterestWithCurrencyEffect: new Big('0'), + totalInvestment: new Big('44558.42'), + totalInvestmentWithCurrencyEffect: new Big('44558.42'), + totalLiabilitiesWithCurrencyEffect: new Big('0'), + totalValuablesWithCurrencyEffect: new Big('0') + }); + + expect(investments).toEqual([ + { date: '2021-12-12', investment: new Big('44558.42') } + ]); + + expect(investmentsByMonth).toEqual([ + { date: '2021-12-01', investment: 44558.42 }, + { date: '2022-01-01', investment: 0 } + ]); + }); + }); +}); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd.spec.ts new file mode 100644 index 00000000..96205fd7 --- /dev/null +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-btcusd.spec.ts @@ -0,0 +1,238 @@ +import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto'; +import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; +import { + activityDummyData, + loadActivityExportFile, + symbolProfileDummyData, + userDummyData +} from '@ghostfolio/api/app/portfolio/calculator/portfolio-calculator-test-utils'; +import { PortfolioCalculatorFactory } from '@ghostfolio/api/app/portfolio/calculator/portfolio-calculator.factory'; +import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentRateServiceMock } from '@ghostfolio/api/app/portfolio/current-rate.service.mock'; +import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service'; +import { RedisCacheServiceMock } from '@ghostfolio/api/app/redis-cache/redis-cache.service.mock'; +import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; +import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; +import { PortfolioSnapshotService } from '@ghostfolio/api/services/queues/portfolio-snapshot/portfolio-snapshot.service'; +import { PortfolioSnapshotServiceMock } from '@ghostfolio/api/services/queues/portfolio-snapshot/portfolio-snapshot.service.mock'; +import { parseDate } from '@ghostfolio/common/helper'; +import { PerformanceCalculationType } from '@ghostfolio/common/types/performance-calculation-type.type'; + +import { Big } from 'big.js'; +import { join } from 'path'; + +jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { + return { + // eslint-disable-next-line @typescript-eslint/naming-convention + CurrentRateService: jest.fn().mockImplementation(() => { + return CurrentRateServiceMock; + }) + }; +}); + +jest.mock( + '@ghostfolio/api/services/queues/portfolio-snapshot/portfolio-snapshot.service', + () => { + return { + // eslint-disable-next-line @typescript-eslint/naming-convention + PortfolioSnapshotService: jest.fn().mockImplementation(() => { + return PortfolioSnapshotServiceMock; + }) + }; + } +); + +jest.mock('@ghostfolio/api/app/redis-cache/redis-cache.service', () => { + return { + // eslint-disable-next-line @typescript-eslint/naming-convention + RedisCacheService: jest.fn().mockImplementation(() => { + return RedisCacheServiceMock; + }) + }; +}); + +describe('PortfolioCalculator', () => { + let activityDtos: CreateOrderDto[]; + + let configurationService: ConfigurationService; + let currentRateService: CurrentRateService; + let exchangeRateDataService: ExchangeRateDataService; + let portfolioCalculatorFactory: PortfolioCalculatorFactory; + let portfolioSnapshotService: PortfolioSnapshotService; + let redisCacheService: RedisCacheService; + + beforeAll(() => { + activityDtos = loadActivityExportFile( + join(__dirname, '../../../../../../../test/import/ok-btcusd.json') + ); + }); + + beforeEach(() => { + configurationService = new ConfigurationService(); + + currentRateService = new CurrentRateService(null, null, null, null); + + exchangeRateDataService = new ExchangeRateDataService( + null, + null, + null, + null + ); + + portfolioSnapshotService = new PortfolioSnapshotService(null); + + redisCacheService = new RedisCacheService(null, null); + + portfolioCalculatorFactory = new PortfolioCalculatorFactory( + configurationService, + currentRateService, + exchangeRateDataService, + portfolioSnapshotService, + redisCacheService + ); + }); + + describe('get current positions', () => { + it.only('with BTCUSD buy (in USD)', async () => { + jest.useFakeTimers().setSystemTime(parseDate('2022-01-14').getTime()); + + const activities: Activity[] = activityDtos.map((activity) => ({ + ...activityDummyData, + ...activity, + date: parseDate(activity.date), + feeInAssetProfileCurrency: 4.46, + SymbolProfile: { + ...symbolProfileDummyData, + currency: 'USD', + dataSource: activity.dataSource, + name: 'Bitcoin', + symbol: activity.symbol + }, + unitPriceInAssetProfileCurrency: 44558.42 + })); + + const portfolioCalculator = portfolioCalculatorFactory.createCalculator({ + activities, + calculationType: PerformanceCalculationType.ROAI, + currency: 'USD', + userId: userDummyData.id + }); + + const portfolioSnapshot = await portfolioCalculator.computeSnapshot(); + + const investments = portfolioCalculator.getInvestments(); + + const investmentsByMonth = portfolioCalculator.getInvestmentsByGroup({ + data: portfolioSnapshot.historicalData, + groupBy: 'month' + }); + + expect(portfolioSnapshot.historicalData[0]).toEqual({ + date: '2021-12-11', + investmentValueWithCurrencyEffect: 0, + netPerformance: 0, + netPerformanceInPercentage: 0, + netPerformanceInPercentageWithCurrencyEffect: 0, + netPerformanceWithCurrencyEffect: 0, + netWorth: 0, + totalAccountBalance: 0, + totalInvestment: 0, + totalInvestmentValueWithCurrencyEffect: 0, + value: 0, + valueWithCurrencyEffect: 0 + }); + + expect(portfolioSnapshot.historicalData[1]).toEqual({ + date: '2021-12-12', + investmentValueWithCurrencyEffect: 44558.42, + netPerformance: -4.46, + netPerformanceInPercentage: 0, + netPerformanceInPercentageWithCurrencyEffect: 0, + netPerformanceWithCurrencyEffect: -4.46, + netWorth: 44558.42, + totalAccountBalance: 0, + totalInvestment: 44558.42, + totalInvestmentValueWithCurrencyEffect: 44558.42, + value: 44558.42, + valueWithCurrencyEffect: 44558.42 + }); + + expect( + portfolioSnapshot.historicalData[ + portfolioSnapshot.historicalData.length - 1 + ] + ).toEqual({ + date: '2022-01-14', + investmentValueWithCurrencyEffect: 0, + netPerformance: -1463.18, + netPerformanceInPercentage: -0.032837340282712, + netPerformanceInPercentageWithCurrencyEffect: -0.032837340282712, + netPerformanceWithCurrencyEffect: -1463.18, + netWorth: 43099.7, + totalAccountBalance: 0, + totalInvestment: 44558.42, + totalInvestmentValueWithCurrencyEffect: 44558.42, + value: 43099.7, + valueWithCurrencyEffect: 43099.7 + }); + + expect(portfolioSnapshot).toMatchObject({ + currentValueInBaseCurrency: new Big('43099.7'), + errors: [], + hasErrors: false, + positions: [ + { + averagePrice: new Big('44558.42'), + currency: 'USD', + dataSource: 'YAHOO', + dividend: new Big('0'), + dividendInBaseCurrency: new Big('0'), + fee: new Big('4.46'), + feeInBaseCurrency: new Big('4.46'), + firstBuyDate: '2021-12-12', + grossPerformance: new Big('-1458.72'), + grossPerformancePercentage: new Big('-0.03273724696701543726'), + grossPerformancePercentageWithCurrencyEffect: new Big( + '-0.03273724696701543726' + ), + grossPerformanceWithCurrencyEffect: new Big('-1458.72'), + investment: new Big('44558.42'), + investmentWithCurrencyEffect: new Big('44558.42'), + netPerformance: new Big('-1463.18'), + netPerformancePercentage: new Big('-0.03283734028271199921'), + netPerformancePercentageWithCurrencyEffectMap: { + max: new Big('-0.03283734028271199921') + }, + netPerformanceWithCurrencyEffectMap: { + max: new Big('-1463.18') + }, + marketPrice: 43099.7, + marketPriceInBaseCurrency: 43099.7, + quantity: new Big('1'), + symbol: 'BTCUSD', + tags: [], + timeWeightedInvestment: new Big('44558.42'), + timeWeightedInvestmentWithCurrencyEffect: new Big('44558.42'), + transactionCount: 1, + valueInBaseCurrency: new Big('43099.7') + } + ], + totalFeesWithCurrencyEffect: new Big('4.46'), + totalInterestWithCurrencyEffect: new Big('0'), + totalInvestment: new Big('44558.42'), + totalInvestmentWithCurrencyEffect: new Big('44558.42'), + totalLiabilitiesWithCurrencyEffect: new Big('0'), + totalValuablesWithCurrencyEffect: new Big('0') + }); + + expect(investments).toEqual([ + { date: '2021-12-12', investment: new Big('44558.42') } + ]); + + expect(investmentsByMonth).toEqual([ + { date: '2021-12-01', investment: 44558.42 }, + { date: '2022-01-01', investment: 0 } + ]); + }); + }); +}); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-with-dividend.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-with-dividend.spec.ts index 8fc17987..4c1962c1 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-with-dividend.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-msft-buy-with-dividend.spec.ts @@ -11,7 +11,6 @@ import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.s import { RedisCacheServiceMock } from '@ghostfolio/api/app/redis-cache/redis-cache.service.mock'; import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; -import { ExchangeRateDataServiceMock } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service.mock'; import { PortfolioSnapshotService } from '@ghostfolio/api/services/queues/portfolio-snapshot/portfolio-snapshot.service'; import { PortfolioSnapshotServiceMock } from '@ghostfolio/api/services/queues/portfolio-snapshot/portfolio-snapshot.service.mock'; import { parseDate } from '@ghostfolio/common/helper'; @@ -49,18 +48,6 @@ jest.mock('@ghostfolio/api/app/redis-cache/redis-cache.service', () => { }; }); -jest.mock( - '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service', - () => { - return { - // eslint-disable-next-line @typescript-eslint/naming-convention - ExchangeRateDataService: jest.fn().mockImplementation(() => { - return ExchangeRateDataServiceMock; - }) - }; - } -); - describe('PortfolioCalculator', () => { let configurationService: ConfigurationService; let currentRateService: CurrentRateService; diff --git a/apps/api/src/app/portfolio/current-rate.service.mock.ts b/apps/api/src/app/portfolio/current-rate.service.mock.ts index fab25ae2..4b4b8f00 100644 --- a/apps/api/src/app/portfolio/current-rate.service.mock.ts +++ b/apps/api/src/app/portfolio/current-rate.service.mock.ts @@ -47,6 +47,10 @@ function mockGetValue(symbol: string, date: Date) { return { marketPrice: 14156.4 }; } else if (isSameDay(parseDate('2018-01-01'), date)) { return { marketPrice: 13657.2 }; + } else if (isSameDay(parseDate('2021-12-12'), date)) { + return { marketPrice: 50098.3 }; + } else if (isSameDay(parseDate('2022-01-14'), date)) { + return { marketPrice: 43099.7 }; } return { marketPrice: 0 }; diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 6d0cde40..87b2bc9d 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -748,8 +748,14 @@ export class PortfolioService { ); const historicalDataArray: HistoricalDataItem[] = []; - let maxPrice = Math.max(activitiesOfPosition[0].unitPrice, marketPrice); - let minPrice = Math.min(activitiesOfPosition[0].unitPrice, marketPrice); + let maxPrice = Math.max( + activitiesOfPosition[0].unitPriceInAssetProfileCurrency, + marketPrice + ); + let minPrice = Math.min( + activitiesOfPosition[0].unitPriceInAssetProfileCurrency, + marketPrice + ); if (historicalData[aSymbol]) { let j = -1; @@ -793,9 +799,9 @@ export class PortfolioService { } else { // Add historical entry for buy date, if no historical data available historicalDataArray.push({ - averagePrice: activitiesOfPosition[0].unitPrice, + averagePrice: activitiesOfPosition[0].unitPriceInAssetProfileCurrency, date: firstBuyDate, - marketPrice: activitiesOfPosition[0].unitPrice, + marketPrice: activitiesOfPosition[0].unitPriceInAssetProfileCurrency, quantity: activitiesOfPosition[0].quantity }); }