Browse Source

feat(test): extend test cases

pull/4650/head
KenTandrian 4 months ago
parent
commit
81dc7044f9
  1. 88
      apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy.spec.ts

88
apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy.spec.ts

@ -193,5 +193,93 @@ describe('PortfolioCalculator', () => {
{ date: '2021-12-01', investment: 0 }
]);
});
it.only('with BALN.SW buy lower than closing price, calculation after buy date', async () => {
jest.useFakeTimers().setSystemTime(parseDate('2021-12-18').getTime());
const activities: Activity[] = [
{
...activityDummyData,
date: new Date('2021-11-30'),
feeInAssetProfileCurrency: 1.55,
quantity: 2,
SymbolProfile: {
...symbolProfileDummyData,
currency: 'CHF',
dataSource: 'YAHOO',
name: 'Bâloise Holding AG',
symbol: 'BALN.SW'
},
type: 'BUY',
unitPriceInAssetProfileCurrency: 135.0
}
];
const portfolioCalculator = portfolioCalculatorFactory.createCalculator({
activities,
calculationType: PerformanceCalculationType.ROAI,
currency: 'CHF',
userId: userDummyData.id
});
const portfolioSnapshot = await portfolioCalculator.computeSnapshot();
const snapshotOnTheDate = portfolioSnapshot.historicalData.find(
(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);
});
it.only('with BALN.SW buy lower than closing price, calculation on buy date', async () => {
jest.useFakeTimers().setSystemTime(parseDate('2021-11-30').getTime());
const activities: Activity[] = [
{
...activityDummyData,
date: new Date('2021-11-30'),
feeInAssetProfileCurrency: 1.55,
quantity: 2,
SymbolProfile: {
...symbolProfileDummyData,
currency: 'CHF',
dataSource: 'YAHOO',
name: 'Bâloise Holding AG',
symbol: 'BALN.SW'
},
type: 'BUY',
unitPriceInAssetProfileCurrency: 135.0
}
];
const portfolioCalculator = portfolioCalculatorFactory.createCalculator({
activities,
calculationType: PerformanceCalculationType.ROAI,
currency: 'CHF',
userId: userDummyData.id
});
const portfolioSnapshot = await portfolioCalculator.computeSnapshot();
const snapshotOnTheDate = portfolioSnapshot.historicalData.find(
(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);
});
});
});

Loading…
Cancel
Save