-
Notifications
You must be signed in to change notification settings - Fork 308
/
sigmaCalculator.test.ts
39 lines (36 loc) · 1.53 KB
/
sigmaCalculator.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Decimal } from 'decimal.js'
import moment from 'moment'
import { CurrencyDerivativesData, OptionData } from '../../src/utils/derivativesDataProvider'
import { SigmaCalculator } from '../../src/utils/sigmaCalculator'
describe('sigma calculator', () => {
describe('data handling', () => {
it('sorts strikes prices correctly', () => {
const fixture1: CurrencyDerivativesData = {
e1: moment().unix(),
e2: moment().unix(),
callsE1: [_createOptionWithStrike(500, 'C'), _createOptionWithStrike(400, 'C')],
callsE2: [_createOptionWithStrike(500, 'C'), _createOptionWithStrike(400, 'C')],
putsE1: [_createOptionWithStrike(400, 'P'), _createOptionWithStrike(500, 'P')],
putsE2: [_createOptionWithStrike(400, 'P'), _createOptionWithStrike(500, 'P')],
exchangeRate: new Decimal(0),
}
const sigmaCalculator = new SigmaCalculator()
sigmaCalculator.sortByStrikePrice(fixture1)
const { callsE1, callsE2, putsE1, putsE2 } = fixture1
expect(callsE1[0].strikePrice.lt(callsE1[1].strikePrice))
expect(callsE2[0].strikePrice.lt(callsE1[1].strikePrice))
expect(putsE1[0].strikePrice.gt(putsE1[1].strikePrice))
expect(putsE1[0].strikePrice.gt(putsE2[1].strikePrice))
})
})
})
function _createOptionWithStrike(strikePrice: number, type: string): OptionData {
return {
instrumentName: '',
strikePrice: new Decimal(strikePrice),
midPrice: new Decimal(0),
underlyingPrice: new Decimal(0),
expiration: moment().utc().unix(),
type,
}
}