From 63a61fb49237742eab999b1ed7f3c9ce051a2c00 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 29 Mar 2024 17:47:44 +0100 Subject: [PATCH] Move portfolio calculator (#3204) * Move portfolio calculator --- ...ator-baln-buy-and-sell-in-two-activities.spec.ts | 2 +- .../portfolio-calculator-baln-buy-and-sell.spec.ts | 2 +- .../twr}/portfolio-calculator-baln-buy.spec.ts | 2 +- ...calculator-btcusd-buy-and-sell-partially.spec.ts | 2 +- .../twr}/portfolio-calculator-googl-buy.spec.ts | 2 +- ...tfolio-calculator-msft-buy-with-dividend.spec.ts | 2 +- .../twr}/portfolio-calculator-no-orders.spec.ts | 2 +- ...o-calculator-novn-buy-and-sell-partially.spec.ts | 2 +- .../portfolio-calculator-novn-buy-and-sell.spec.ts | 2 +- .../twr}/portfolio-calculator.spec.ts | 2 +- .../{ => calculator/twr}/portfolio-calculator.ts | 13 ++++++------- apps/api/src/app/portfolio/portfolio.service.ts | 2 +- 12 files changed, 17 insertions(+), 18 deletions(-) rename apps/api/src/app/portfolio/{ => calculator/twr}/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts (95%) rename apps/api/src/app/portfolio/{ => calculator/twr}/portfolio-calculator-baln-buy-and-sell.spec.ts (98%) rename apps/api/src/app/portfolio/{ => calculator/twr}/portfolio-calculator-baln-buy.spec.ts (97%) rename apps/api/src/app/portfolio/{ => calculator/twr}/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts (98%) rename apps/api/src/app/portfolio/{ => calculator/twr}/portfolio-calculator-googl-buy.spec.ts (98%) rename apps/api/src/app/portfolio/{ => calculator/twr}/portfolio-calculator-msft-buy-with-dividend.spec.ts (97%) rename apps/api/src/app/portfolio/{ => calculator/twr}/portfolio-calculator-no-orders.spec.ts (96%) rename apps/api/src/app/portfolio/{ => calculator/twr}/portfolio-calculator-novn-buy-and-sell-partially.spec.ts (98%) rename apps/api/src/app/portfolio/{ => calculator/twr}/portfolio-calculator-novn-buy-and-sell.spec.ts (98%) rename apps/api/src/app/portfolio/{ => calculator/twr}/portfolio-calculator.spec.ts (96%) rename apps/api/src/app/portfolio/{ => calculator/twr}/portfolio-calculator.ts (98%) diff --git a/apps/api/src/app/portfolio/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts similarity index 95% rename from apps/api/src/app/portfolio/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts rename to apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts index 4a90409c9..e08de8e22 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell-in-two-activities.spec.ts @@ -1,11 +1,11 @@ import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentRateServiceMock } from '@ghostfolio/api/app/portfolio/current-rate.service.mock'; 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', () => { diff --git a/apps/api/src/app/portfolio/portfolio-calculator-baln-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell.spec.ts similarity index 98% rename from apps/api/src/app/portfolio/portfolio-calculator-baln-buy-and-sell.spec.ts rename to apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell.spec.ts index 6176acbb5..411c5e4db 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator-baln-buy-and-sell.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy-and-sell.spec.ts @@ -1,11 +1,11 @@ import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentRateServiceMock } from '@ghostfolio/api/app/portfolio/current-rate.service.mock'; 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', () => { diff --git a/apps/api/src/app/portfolio/portfolio-calculator-baln-buy.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy.spec.ts similarity index 97% rename from apps/api/src/app/portfolio/portfolio-calculator-baln-buy.spec.ts rename to apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy.spec.ts index 61dfb5915..32f582647 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator-baln-buy.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-baln-buy.spec.ts @@ -1,11 +1,11 @@ import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentRateServiceMock } from '@ghostfolio/api/app/portfolio/current-rate.service.mock'; 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', () => { diff --git a/apps/api/src/app/portfolio/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts similarity index 98% rename from apps/api/src/app/portfolio/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts rename to apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts index d17a12ba8..f5687f810 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-btcusd-buy-and-sell-partially.spec.ts @@ -1,12 +1,12 @@ import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentRateServiceMock } from '@ghostfolio/api/app/portfolio/current-rate.service.mock'; 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 { 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', () => { diff --git a/apps/api/src/app/portfolio/portfolio-calculator-googl-buy.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-googl-buy.spec.ts similarity index 98% rename from apps/api/src/app/portfolio/portfolio-calculator-googl-buy.spec.ts rename to apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-googl-buy.spec.ts index 5e870b447..743733733 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator-googl-buy.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-googl-buy.spec.ts @@ -1,12 +1,12 @@ import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentRateServiceMock } from '@ghostfolio/api/app/portfolio/current-rate.service.mock'; 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 { 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', () => { diff --git a/apps/api/src/app/portfolio/portfolio-calculator-msft-buy-with-dividend.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-msft-buy-with-dividend.spec.ts similarity index 97% rename from apps/api/src/app/portfolio/portfolio-calculator-msft-buy-with-dividend.spec.ts rename to apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-msft-buy-with-dividend.spec.ts index 9ec51094e..afd5e9ff2 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator-msft-buy-with-dividend.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-msft-buy-with-dividend.spec.ts @@ -1,12 +1,12 @@ import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentRateServiceMock } from '@ghostfolio/api/app/portfolio/current-rate.service.mock'; 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 { 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', () => { diff --git a/apps/api/src/app/portfolio/portfolio-calculator-no-orders.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-no-orders.spec.ts similarity index 96% rename from apps/api/src/app/portfolio/portfolio-calculator-no-orders.spec.ts rename to apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-no-orders.spec.ts index 9947e2f45..39a563b85 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator-no-orders.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-no-orders.spec.ts @@ -1,11 +1,11 @@ import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentRateServiceMock } from '@ghostfolio/api/app/portfolio/current-rate.service.mock'; 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 { subDays } from 'date-fns'; -import { CurrentRateServiceMock } from './current-rate.service.mock'; import { PortfolioCalculator } from './portfolio-calculator'; jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => { diff --git a/apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell-partially.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell-partially.spec.ts similarity index 98% rename from apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell-partially.spec.ts rename to apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell-partially.spec.ts index 8eeb216ba..d7e7c6eab 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell-partially.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell-partially.spec.ts @@ -1,11 +1,11 @@ import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentRateServiceMock } from '@ghostfolio/api/app/portfolio/current-rate.service.mock'; 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', () => { diff --git a/apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell.spec.ts similarity index 98% rename from apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell.spec.ts rename to apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell.spec.ts index ec00fffe7..68eecea22 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator-novn-buy-and-sell.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator-novn-buy-and-sell.spec.ts @@ -1,11 +1,11 @@ import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentRateServiceMock } from '@ghostfolio/api/app/portfolio/current-rate.service.mock'; 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', () => { diff --git a/apps/api/src/app/portfolio/portfolio-calculator.spec.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.spec.ts similarity index 96% rename from apps/api/src/app/portfolio/portfolio-calculator.spec.ts rename to apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.spec.ts index a385774ff..de011d813 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.spec.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.spec.ts @@ -1,8 +1,8 @@ +import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; import { Big } from 'big.js'; -import { CurrentRateService } from './current-rate.service'; import { PortfolioCalculator } from './portfolio-calculator'; describe('PortfolioCalculator', () => { diff --git a/apps/api/src/app/portfolio/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts similarity index 98% rename from apps/api/src/app/portfolio/portfolio-calculator.ts rename to apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts index d95acc836..6ea93a670 100644 --- a/apps/api/src/app/portfolio/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts @@ -1,4 +1,10 @@ import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; +import { CurrentRateService } from '@ghostfolio/api/app/portfolio/current-rate.service'; +import { CurrentPositions } from '@ghostfolio/api/app/portfolio/interfaces/current-positions.interface'; +import { PortfolioOrderItem } from '@ghostfolio/api/app/portfolio/interfaces/portfolio-calculator.interface'; +import { PortfolioOrder } from '@ghostfolio/api/app/portfolio/interfaces/portfolio-order.interface'; +import { TransactionPointSymbol } from '@ghostfolio/api/app/portfolio/interfaces/transaction-point-symbol.interface'; +import { TransactionPoint } from '@ghostfolio/api/app/portfolio/interfaces/transaction-point.interface'; import { getFactor } from '@ghostfolio/api/helper/portfolio.helper'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; @@ -30,13 +36,6 @@ import { } from 'date-fns'; import { cloneDeep, first, isNumber, last, sortBy, uniq } from 'lodash'; -import { CurrentRateService } from './current-rate.service'; -import { CurrentPositions } from './interfaces/current-positions.interface'; -import { PortfolioOrderItem } from './interfaces/portfolio-calculator.interface'; -import { PortfolioOrder } from './interfaces/portfolio-order.interface'; -import { TransactionPointSymbol } from './interfaces/transaction-point-symbol.interface'; -import { TransactionPoint } from './interfaces/transaction-point.interface'; - export class PortfolioCalculator { private static readonly ENABLE_LOGGING = false; diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index fe0e5a601..7fe82504f 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -86,11 +86,11 @@ import { } from 'date-fns'; import { isEmpty, last, uniq, uniqBy } from 'lodash'; +import { PortfolioCalculator } from './calculator/twr/portfolio-calculator'; import { HistoricalDataContainer, PortfolioPositionDetail } from './interfaces/portfolio-position-detail.interface'; -import { PortfolioCalculator } from './portfolio-calculator'; import { RulesService } from './rules.service'; const asiaPacificMarkets = require('../../assets/countries/asia-pacific-markets.json');