From 5225beab2339fadff8d3a6a195641a096cbf5958 Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 10 May 2024 12:53:22 +0200 Subject: [PATCH] Fix and remove tests --- ...folio-calculator-baln-buy-and-sell.spec.ts | 1 - ...folio-calculator-novn-buy-and-sell.spec.ts | 2 - .../calculator/twr/portfolio-calculator.ts | 32 ---- ...-calculator-novn-baln-buy-and-sell.spec.ts | 152 ------------------ 4 files changed, 187 deletions(-) delete mode 100644 apps/api/src/app/portfolio/portfolio-calculator-novn-baln-buy-and-sell.spec.ts diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell.spec.ts index 4a26ee838..53ebdf19f 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell.spec.ts @@ -174,7 +174,6 @@ describe('PortfolioCalculator', () => { symbol: 'BALN.SW', tags: [], timeWeightedInvestment: new Big('285.8'), - tags: undefined, timeWeightedInvestmentWithCurrencyEffect: new Big('285.8'), transactionCount: 2, valueInBaseCurrency: new Big('0') diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell.spec.ts index 5c65a9f23..902f710ee 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell.spec.ts @@ -136,7 +136,6 @@ describe('PortfolioCalculator', () => { netPerformanceInPercentage: 0, netPerformanceInPercentageWithCurrencyEffect: 0, netPerformanceWithCurrencyEffect: 0, - timeWeightedPerformance: 0, netWorth: 151.6, totalAccountBalance: 0, totalInvestment: 151.6, @@ -152,7 +151,6 @@ describe('PortfolioCalculator', () => { netPerformanceInPercentage: 13.100263852242744, netPerformanceInPercentageWithCurrencyEffect: 13.100263852242744, netPerformanceWithCurrencyEffect: 19.86, - timeWeightedPerformance: 0, netWorth: 0, totalAccountBalance: 0, totalInvestment: 0, diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts index c5ed98543..69716e405 100644 --- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts @@ -574,38 +574,6 @@ export class TWRPortfolioCalculator extends PortfolioCalculator { totalUnits = totalUnits.plus(order.quantity.mul(getFactor(order.type))); - if (order.type === 'DIVIDEND') { - const dividend = order.quantity.mul(order.unitPrice); - - totalDividend = totalDividend.plus(dividend); - totalDividendInBaseCurrency = totalDividendInBaseCurrency.plus( - dividend.mul(exchangeRateAtOrderDate ?? 1) - ); - } else if (order.type === 'INTEREST') { - const interest = order.quantity.mul(order.unitPrice); - - totalInterest = totalInterest.plus(interest); - totalInterestInBaseCurrency = totalInterestInBaseCurrency.plus( - interest.mul(exchangeRateAtOrderDate ?? 1) - ); - } else if (order.type === 'ITEM') { - const valuables = order.quantity.mul(order.unitPrice); - - totalValuables = totalValuables.plus(valuables); - totalValuablesInBaseCurrency = totalValuablesInBaseCurrency.plus( - valuables.mul(exchangeRateAtOrderDate ?? 1) - ); - } else if (order.type === 'LIABILITY') { - const liabilities = order.quantity.mul(order.unitPrice); - - totalLiabilities = totalLiabilities.plus(liabilities); - totalLiabilitiesInBaseCurrency = totalLiabilitiesInBaseCurrency.plus( - liabilities.mul(exchangeRateAtOrderDate ?? 1) - ); - } else if (order.type === 'STAKE') { - totalStakeRewards = totalStakeRewards.plus(order.quantity); - } - const valueOfInvestment = totalUnits.mul(order.unitPriceInBaseCurrency); const valueOfInvestmentWithCurrencyEffect = totalUnits.mul( diff --git a/apps/api/src/app/portfolio/portfolio-calculator-novn-baln-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/portfolio-calculator-novn-baln-buy-and-sell.spec.ts deleted file mode 100644 index b56118b0c..000000000 --- a/apps/api/src/app/portfolio/portfolio-calculator-novn-baln-buy-and-sell.spec.ts +++ /dev/null @@ -1,152 +0,0 @@ -import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; -import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; -import { parseDate } from '@ghostfolio/common/helper'; - -import Big from 'big.js'; - -import { CurrentRateServiceMock } from './current-rate.service.mock'; -import { PortfolioCalculator } from './portfolio-calculator'; - -jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { - return { - // eslint-disable-next-line @typescript-eslint/naming-convention - CurrentRateService: jest.fn().mockImplementation(() => { - return CurrentRateServiceMock; - }) - }; -}); - -describe('PortfolioCalculator', () => { - let currentRateService: CurrentRateService; - let exchangeRateDataService: ExchangeRateDataService; - - beforeEach(() => { - currentRateService = new CurrentRateService(null, null, null, null); - - exchangeRateDataService = new ExchangeRateDataService( - null, - null, - null, - null - ); - }); - - describe('get current positions', () => { - it.only('with NOVN.SW and BALN.SW buy and sell', async () => { - const portfolioCalculator = new PortfolioCalculator({ - currentRateService, - exchangeRateDataService, - currency: 'CHF', - orders: [ - { - currency: 'CHF', - date: '2022-03-07', - dataSource: 'YAHOO', - fee: new Big(0), - name: 'Novartis AG', - quantity: new Big(2), - symbol: 'NOVN.SW', - type: 'BUY', - unitPrice: new Big(75.8) - }, - { - currency: 'CHF', - date: '2022-04-01', - dataSource: 'YAHOO', - fee: new Big(0), - name: 'Novartis AG', - quantity: new Big(0), - symbol: 'NOVN.SW', - type: 'BUY', - unitPrice: new Big(80.0) - }, - { - currency: 'CHF', - date: '2022-04-08', - dataSource: 'YAHOO', - fee: new Big(0), - name: 'Novartis AG', - quantity: new Big(2), - symbol: 'NOVN.SW', - type: 'SELL', - unitPrice: new Big(85.73) - }, - { - currency: 'CHF', - date: '2022-03-22', - dataSource: 'YAHOO', - fee: new Big(1.55), - name: 'Bâloise Holding AG', - quantity: new Big(2), - symbol: 'BALN.SW', - type: 'BUY', - unitPrice: new Big(142.9) - }, - { - currency: 'CHF', - date: '2022-04-01', - dataSource: 'YAHOO', - fee: new Big(0), - name: 'Bâloise Holding AG', - quantity: new Big(0), - symbol: 'BALN.SW', - type: 'BUY', - unitPrice: new Big(138) - }, - { - currency: 'CHF', - date: '2022-04-10', - dataSource: 'YAHOO', - fee: new Big(1.65), - name: 'Bâloise Holding AG', - quantity: new Big(2), - symbol: 'BALN.SW', - type: 'SELL', - unitPrice: new Big(136.6) - } - ] - }); - - portfolioCalculator.computeTransactionPoints(); - - const spy = jest - .spyOn(Date, 'now') - .mockImplementation(() => parseDate('2022-04-11').getTime()); - - const chartData = await portfolioCalculator.getChartData({ - start: parseDate('2022-03-07'), - calculateTimeWeightedPerformance: true - }); - - spy.mockRestore(); - - expect(chartData[0]).toEqual({ - date: '2022-03-07', - investmentValueWithCurrencyEffect: 151.6, - netPerformance: 0, - netPerformanceInPercentage: 0, - netPerformanceInPercentageWithCurrencyEffect: 0, - netPerformanceWithCurrencyEffect: 0, - timeWeightedPerformance: 0, - totalInvestment: 151.6, - totalInvestmentValueWithCurrencyEffect: 151.6, - value: 151.6, - valueWithCurrencyEffect: 151.6 - }); - - expect(chartData[chartData.length - 1]).toEqual({ - date: '2022-04-11', - investmentValueWithCurrencyEffect: 0, - netPerformance: 19.86, - netPerformanceInPercentage: 13.100263852242744, - netPerformanceInPercentageWithCurrencyEffect: 13.100263852242744, - netPerformanceWithCurrencyEffect: 19.86, - timeWeightedPerformance: 0, - totalInvestment: 0, - totalInvestmentValueWithCurrencyEffect: 0, - value: 0, - valueWithCurrencyEffect: 0 - }); - }); - }); -});