diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy.spec.ts index 1f8434bd0..c8b5c4d40 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy.spec.ts @@ -194,7 +194,7 @@ describe('PortfolioCalculator', () => { ]); }); - it.only('with BALN.SW buy lower than closing price, calculation after buy date', async () => { + it.only('with BALN.SW buy (with unit price lower than closing price)', async () => { jest.useFakeTimers().setSystemTime(parseDate('2021-12-18').getTime()); const activities: Activity[] = [ @@ -227,18 +227,11 @@ describe('PortfolioCalculator', () => { (snapshot) => snapshot.date === '2021-11-30' ); - /** - * Closing price on 2021-11-30: 136.6 - * Correct calculation: 2 * (136.6 - 135.0) - 1.55 = 1.65 - * Current calculation: 2 * (135.0 - 135.0) - 1.55 = -1.55 - * - * The performance should be calculated based on the closing price of the day, - * not the buy price. - */ - expect(snapshotOnTheDate?.netPerformanceWithCurrencyEffect).toEqual(1.65); + // Closing price on 2021-11-30: 136.6 + expect(snapshotOnTheDate?.netPerformanceWithCurrencyEffect).toEqual(1.65); // 2 * (136.6 - 135.0) - 1.55 = 1.65 }); - it.only('with BALN.SW buy lower than closing price, calculation on buy date', async () => { + it.only('with BALN.SW buy (with unit price lower than closing price), calculated on buy date', async () => { jest.useFakeTimers().setSystemTime(parseDate('2021-11-30').getTime()); const activities: Activity[] = [ @@ -271,15 +264,8 @@ describe('PortfolioCalculator', () => { (snapshot) => snapshot.date === '2021-11-30' ); - /** - * Closing price on 2021-11-30: 136.6 - * Correct calculation: 2 * (136.6 - 135.0) - 1.55 = 1.65 - * Current calculation: 2 * (135.0 - 135.0) - 1.55 = -1.55 - * - * The performance should be calculated based on the closing price of the day, - * not the buy price. - */ - expect(snapshotOnTheDate?.netPerformanceWithCurrencyEffect).toEqual(1.65); + // Closing price on 2021-11-30: 136.6 + expect(snapshotOnTheDate?.netPerformanceWithCurrencyEffect).toEqual(1.65); // 2 * (136.6 - 135.0) - 1.55 = 1.65 }); }); }); 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 index 30134ae3c..3e26ed8b5 100644 --- 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 @@ -148,27 +148,15 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot.historicalData[1]).toEqual({ date: '2021-12-12', investmentValueWithCurrencyEffect: 44558.42, - /** - * Correct calculation: 1 * (50098.3 - 44558.42) - 4.46 = 5535.42 - * Current calculation: 1 * (44558.42 - 44558.42) - 4.46 = -4.46 - */ - netPerformance: 5535.42, + netPerformance: 5535.42, // 1 * (50098.3 - 44558.42) - 4.46 = 5535.42 netPerformanceInPercentage: 0, netPerformanceInPercentageWithCurrencyEffect: 0, netPerformanceWithCurrencyEffect: 5535.42, - /** - * Correct calculation: 1 * 50098.3 = 50098.3 - * Current calculation: 1 * 44558.42 = 44558.42 - */ - netWorth: 50098.3, + netWorth: 50098.3, // 1 * 50098.3 = 50098.3 totalAccountBalance: 0, totalInvestment: 44558.42, totalInvestmentValueWithCurrencyEffect: 44558.42, - /** - * Correct calculation: 1 * 50098.3 = 50098.3 - * Current calculation: 1 * 44558.42 = 44558.42 - */ - value: 50098.3, + value: 50098.3, // 1 * 50098.3 = 50098.3 valueWithCurrencyEffect: 50098.3 }); 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 index bc411142b..71820cde4 100644 --- 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 @@ -148,31 +148,15 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot.historicalData[1]).toEqual({ date: '2021-12-12', investmentValueWithCurrencyEffect: 44558.42, - /** - * Correct calculation: 1 * (50098.3 - 44558.42) - 4.46 = 5535.42 - * Current calculation: 1 * (44558.42 - 44558.42) - 4.46 = -4.46 - */ - netPerformance: 5535.42, + netPerformance: 5535.42, // 1 * (50098.3 - 44558.42) - 4.46 = 5535.42 netPerformanceInPercentage: 0, netPerformanceInPercentageWithCurrencyEffect: 0, - /** - * Correct calculation: 1 * (50098.3 - 44558.42) - 4.46 = 5535.42 - * Current calculation: 1 * (44558.42 - 44558.42) - 4.46 = -4.46 - */ - netPerformanceWithCurrencyEffect: 5535.42, - /** - * Correct calculation: 1 * 50098.3 = 50098.3 - * Current calculation: 1 * 44558.42 = 44558.42 - */ - netWorth: 50098.3, + netPerformanceWithCurrencyEffect: 5535.42, // 1 * (50098.3 - 44558.42) - 4.46 = 5535.42 + netWorth: 50098.3, // 1 * 50098.3 = 50098.3 totalAccountBalance: 0, totalInvestment: 44558.42, totalInvestmentValueWithCurrencyEffect: 44558.42, - /** - * Correct calculation: 1 * 50098.3 = 50098.3 - * Current calculation: 1 * 44558.42 = 44558.42 - */ - value: 50098.3, + value: 50098.3, // 1 * 50098.3 = 50098.3 valueWithCurrencyEffect: 50098.3 }); diff --git a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell.spec.ts index 38a5c659b..0854bd20b 100644 --- a/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell.spec.ts +++ b/apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-novn-buy-and-sell.spec.ts @@ -152,27 +152,15 @@ describe('PortfolioCalculator', () => { expect(portfolioSnapshot.historicalData[1]).toEqual({ date: '2022-03-07', investmentValueWithCurrencyEffect: 151.6, - /** - * Correct calculation: 2 * (87.8 - 75.8) = 24 - * Current calculation: 2 * (75.8 - 75.8) = 0 - */ - netPerformance: 24, + netPerformance: 24, // 2 * (87.8 - 75.8) = 24 netPerformanceInPercentage: 0, netPerformanceInPercentageWithCurrencyEffect: 0, netPerformanceWithCurrencyEffect: 24, - /** - * Correct calculation: 2 * 87.8 = 175.6 - * Current calculation: 2 * 75.8 = 151.6 - */ - netWorth: 175.6, + netWorth: 175.6, // 2 * 87.8 = 175.6 totalAccountBalance: 0, totalInvestment: 151.6, totalInvestmentValueWithCurrencyEffect: 151.6, - /** - * Correct calculation: 2 * 87.8 = 175.6 - * Current calculation: 2 * 75.8 = 151.6 - */ - value: 175.6, + value: 175.6, // 2 * 87.8 = 175.6 valueWithCurrencyEffect: 175.6 });