mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.5 KiB
51 lines
1.5 KiB
6 months ago
|
import { Big } from 'big.js';
|
||
|
|
||
|
import { getAnnualizedPerformancePercent } from './calculation-helper';
|
||
|
|
||
|
describe('CalculationHelper', () => {
|
||
|
describe('annualized performance percentage', () => {
|
||
|
it('Get annualized performance', async () => {
|
||
|
expect(
|
||
|
getAnnualizedPerformancePercent({
|
||
|
daysInMarket: NaN, // differenceInDays of date-fns returns NaN for the same day
|
||
|
netPerformancePercentage: new Big(0)
|
||
|
}).toNumber()
|
||
|
).toEqual(0);
|
||
|
|
||
|
expect(
|
||
|
getAnnualizedPerformancePercent({
|
||
|
daysInMarket: 0,
|
||
|
netPerformancePercentage: new Big(0)
|
||
|
}).toNumber()
|
||
|
).toEqual(0);
|
||
|
|
||
|
/**
|
||
|
* Source: https://www.readyratios.com/reference/analysis/annualized_rate.html
|
||
|
*/
|
||
|
expect(
|
||
|
getAnnualizedPerformancePercent({
|
||
|
daysInMarket: 65, // < 1 year
|
||
|
netPerformancePercentage: new Big(0.1025)
|
||
|
}).toNumber()
|
||
|
).toBeCloseTo(0.729705);
|
||
|
|
||
|
expect(
|
||
|
getAnnualizedPerformancePercent({
|
||
|
daysInMarket: 365, // 1 year
|
||
|
netPerformancePercentage: new Big(0.05)
|
||
|
}).toNumber()
|
||
|
).toBeCloseTo(0.05);
|
||
|
|
||
|
/**
|
||
|
* Source: https://www.investopedia.com/terms/a/annualized-total-return.asp#annualized-return-formula-and-calculation
|
||
|
*/
|
||
|
expect(
|
||
|
getAnnualizedPerformancePercent({
|
||
|
daysInMarket: 575, // > 1 year
|
||
|
netPerformancePercentage: new Big(0.2374)
|
||
|
}).toNumber()
|
||
|
).toBeCloseTo(0.145);
|
||
|
});
|
||
|
});
|
||
|
});
|