Browse Source

Merge 4210e07947 into eae2c20dfe

pull/6230/merge
neverstop2023 2 days ago
committed by GitHub
parent
commit
52400de595
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 89
      apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-sell.spec.ts

89
apps/api/src/app/portfolio/calculator/roai/portfolio-calculator-baln-buy-and-sell.spec.ts

@ -79,7 +79,7 @@ describe('PortfolioCalculator', () => {
}); });
describe('get current positions', () => { describe('get current positions', () => {
it.only('with BALN.SW buy and sell', async () => { it('with BALN.SW buy and sell', async () => {
jest.useFakeTimers().setSystemTime(parseDate('2021-12-18').getTime()); jest.useFakeTimers().setSystemTime(parseDate('2021-12-18').getTime());
const activities: Activity[] = [ const activities: Activity[] = [
@ -211,5 +211,90 @@ describe('PortfolioCalculator', () => {
{ date: '2021-01-01', investment: 0 } { date: '2021-01-01', investment: 0 }
]); ]);
}); });
it('with COIN multiple round-trip trades', async () => {
jest.useFakeTimers().setSystemTime(parseDate('2024-12-01').getTime());
const activities: Activity[] = [
{
...activityDummyData,
date: new Date('2024-10-31'),
feeInAssetProfileCurrency: 16,
feeInBaseCurrency: 16,
quantity: 20,
SymbolProfile: {
...symbolProfileDummyData,
currency: 'USD',
dataSource: 'MANUAL',
name: 'Coinbase Global, Inc.',
symbol: 'COIN'
},
type: 'BUY',
unitPriceInAssetProfileCurrency: 218
},
{
...activityDummyData,
date: new Date('2024-11-13'),
feeInAssetProfileCurrency: 16.18,
feeInBaseCurrency: 16.18,
quantity: 20,
SymbolProfile: {
...symbolProfileDummyData,
currency: 'USD',
dataSource: 'MANUAL',
name: 'Coinbase Global, Inc.',
symbol: 'COIN'
},
type: 'SELL',
unitPriceInAssetProfileCurrency: 320
},
{
...activityDummyData,
date: new Date('2024-11-19'),
feeInAssetProfileCurrency: 16,
feeInBaseCurrency: 16,
quantity: 30,
SymbolProfile: {
...symbolProfileDummyData,
currency: 'USD',
dataSource: 'MANUAL',
name: 'Coinbase Global, Inc.',
symbol: 'COIN'
},
type: 'BUY',
unitPriceInAssetProfileCurrency: 290
},
{
...activityDummyData,
date: new Date('2024-11-20'),
feeInAssetProfileCurrency: 16.27,
feeInBaseCurrency: 16.27,
quantity: 30,
SymbolProfile: {
...symbolProfileDummyData,
currency: 'USD',
dataSource: 'MANUAL',
name: 'Coinbase Global, Inc.',
symbol: 'COIN'
},
type: 'SELL',
unitPriceInAssetProfileCurrency: 321
}
];
const portfolioCalculator = portfolioCalculatorFactory.createCalculator({
activities,
calculationType: PerformanceCalculationType.ROAI,
currency: 'USD',
userId: userDummyData.id
});
const portfolioSnapshot = await portfolioCalculator.computeSnapshot();
const coinPosition = portfolioSnapshot.positions.find((p) => p.symbol === 'COIN');
expect(coinPosition).toBeDefined();
expect(coinPosition.netPerformance).not.toBeNull();
expect(coinPosition.netPerformance.toNumber()).toBeCloseTo(2905.55, 2);
});
}); });
}); });
Loading…
Cancel
Save