|
|
@ -1,6 +1,8 @@
|
|
|
|
|
|
|
|
import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto';
|
|
|
|
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
|
|
|
|
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
activityDummyData,
|
|
|
|
activityDummyData,
|
|
|
|
|
|
|
|
loadActivityExportFile,
|
|
|
|
symbolProfileDummyData,
|
|
|
|
symbolProfileDummyData,
|
|
|
|
userDummyData
|
|
|
|
userDummyData
|
|
|
|
} from '@ghostfolio/api/app/portfolio/calculator/portfolio-calculator-test-utils';
|
|
|
|
} from '@ghostfolio/api/app/portfolio/calculator/portfolio-calculator-test-utils';
|
|
|
@ -20,6 +22,7 @@ import { parseDate } from '@ghostfolio/common/helper';
|
|
|
|
|
|
|
|
|
|
|
|
import { Big } from 'big.js';
|
|
|
|
import { Big } from 'big.js';
|
|
|
|
import { last } from 'lodash';
|
|
|
|
import { last } from 'lodash';
|
|
|
|
|
|
|
|
import { join } from 'path';
|
|
|
|
|
|
|
|
|
|
|
|
jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => {
|
|
|
|
jest.mock('@ghostfolio/api/app/portfolio/current-rate.service', () => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
@ -52,6 +55,8 @@ jest.mock('@ghostfolio/api/app/redis-cache/redis-cache.service', () => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe('PortfolioCalculator', () => {
|
|
|
|
describe('PortfolioCalculator', () => {
|
|
|
|
|
|
|
|
let activityDtos: CreateOrderDto[];
|
|
|
|
|
|
|
|
|
|
|
|
let configurationService: ConfigurationService;
|
|
|
|
let configurationService: ConfigurationService;
|
|
|
|
let currentRateService: CurrentRateService;
|
|
|
|
let currentRateService: CurrentRateService;
|
|
|
|
let exchangeRateDataService: ExchangeRateDataService;
|
|
|
|
let exchangeRateDataService: ExchangeRateDataService;
|
|
|
@ -59,6 +64,15 @@ describe('PortfolioCalculator', () => {
|
|
|
|
let portfolioSnapshotService: PortfolioSnapshotService;
|
|
|
|
let portfolioSnapshotService: PortfolioSnapshotService;
|
|
|
|
let redisCacheService: RedisCacheService;
|
|
|
|
let redisCacheService: RedisCacheService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
beforeAll(() => {
|
|
|
|
|
|
|
|
activityDtos = loadActivityExportFile(
|
|
|
|
|
|
|
|
join(
|
|
|
|
|
|
|
|
__dirname,
|
|
|
|
|
|
|
|
'../../../../../../../test/import/ok-novn-buy-and-sell-partially.json'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
beforeEach(() => {
|
|
|
|
configurationService = new ConfigurationService();
|
|
|
|
configurationService = new ConfigurationService();
|
|
|
|
|
|
|
|
|
|
|
@ -88,38 +102,18 @@ describe('PortfolioCalculator', () => {
|
|
|
|
it.only('with NOVN.SW buy and sell partially', async () => {
|
|
|
|
it.only('with NOVN.SW buy and sell partially', async () => {
|
|
|
|
jest.useFakeTimers().setSystemTime(parseDate('2022-04-11').getTime());
|
|
|
|
jest.useFakeTimers().setSystemTime(parseDate('2022-04-11').getTime());
|
|
|
|
|
|
|
|
|
|
|
|
const activities: Activity[] = [
|
|
|
|
const activities: Activity[] = activityDtos.map((activity) => ({
|
|
|
|
{
|
|
|
|
...activityDummyData,
|
|
|
|
...activityDummyData,
|
|
|
|
...activity,
|
|
|
|
date: new Date('2022-03-07'),
|
|
|
|
date: parseDate(activity.date),
|
|
|
|
fee: 1.3,
|
|
|
|
SymbolProfile: {
|
|
|
|
quantity: 2,
|
|
|
|
...symbolProfileDummyData,
|
|
|
|
SymbolProfile: {
|
|
|
|
currency: activity.currency,
|
|
|
|
...symbolProfileDummyData,
|
|
|
|
dataSource: activity.dataSource,
|
|
|
|
currency: 'CHF',
|
|
|
|
name: 'Novartis AG',
|
|
|
|
dataSource: 'YAHOO',
|
|
|
|
symbol: activity.symbol
|
|
|
|
name: 'Novartis AG',
|
|
|
|
|
|
|
|
symbol: 'NOVN.SW'
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
type: 'BUY',
|
|
|
|
|
|
|
|
unitPrice: 75.8
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
...activityDummyData,
|
|
|
|
|
|
|
|
date: new Date('2022-04-08'),
|
|
|
|
|
|
|
|
fee: 2.95,
|
|
|
|
|
|
|
|
quantity: 1,
|
|
|
|
|
|
|
|
SymbolProfile: {
|
|
|
|
|
|
|
|
...symbolProfileDummyData,
|
|
|
|
|
|
|
|
currency: 'CHF',
|
|
|
|
|
|
|
|
dataSource: 'YAHOO',
|
|
|
|
|
|
|
|
name: 'Novartis AG',
|
|
|
|
|
|
|
|
symbol: 'NOVN.SW'
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
type: 'SELL',
|
|
|
|
|
|
|
|
unitPrice: 85.73
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
const portfolioCalculator = portfolioCalculatorFactory.createCalculator({
|
|
|
|
const portfolioCalculator = portfolioCalculatorFactory.createCalculator({
|
|
|
|
activities,
|
|
|
|
activities,
|
|
|
|