Skip to content

Commit

Permalink
Merge pull request #6 from primitivefinance/fix/spot-test
Browse files Browse the repository at this point in the history
fix(spot-price): normalized reserveRisky by dividing by liquidity in …
  • Loading branch information
Alexangelj authored Jul 28, 2021
2 parents 6d4e121 + 82b3fbf commit f608bcd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/CumulativeNormalDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const inverse_std_n_cdf = x => {
* @returns CDF(CDF(x)^-1)^-1
*/
export const quantilePrime = x => {
if (x > 1 || x < 0) return NaN
return gaussian(0, 1).pdf(inverse_std_n_cdf(x)) ** -1
}

Expand Down
4 changes: 3 additions & 1 deletion src/ReplicationMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export function getSpotPrice(
sigma: number,
tau: number
): number {
return getTradingFunction(0, reserveRisky, liquidity, strike, sigma, tau) * quantilePrime(1 - reserveRisky)
return (
getTradingFunction(0, reserveRisky, liquidity, strike, sigma, tau) * quantilePrime(1 - reserveRisky / liquidity)
)
}

/**
Expand Down
8 changes: 6 additions & 2 deletions test/replicationMath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ describe('Replication math', () => {
})

describe('calculate spot price', () => {
it('moneyness', () => {
expect(2).toEqual(2)
it('shouldnt be nan', () => {
expect(math.getSpotPrice(1, 2, 1, 1, 1) > 0).toBe(!NaN)
})

it('should be nan if reserveRisky is greater than 1', () => {
expect(math.getSpotPrice(3, 2, 1, 1, 1)).toBe(NaN)
})
})

Expand Down

0 comments on commit f608bcd

Please sign in to comment.