From b0d3b4950bbd8b7d05154fe1fb1372719389d1ab Mon Sep 17 00:00:00 2001 From: Alcibiades Athens Date: Thu, 21 Dec 2023 19:19:28 -0500 Subject: [PATCH 1/2] fix: increase bracket size to handle heinously wrong values --- src/utils/vol/index.ts | 4 ++-- src/utils/vol/vol.test.ts | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/utils/vol/index.ts b/src/utils/vol/index.ts index dd8a7134..a8ed8af7 100644 --- a/src/utils/vol/index.ts +++ b/src/utils/vol/index.ts @@ -244,8 +244,8 @@ class OptionsGreeks { T: number, ): number { const brent = new Brent(); - const lowerBound = 0.001; // Lower bound for volatility search - const upperBound = 5.0; // Upper bound for volatility search + const lowerBound = -5; // Lower bound for volatility search + const upperBound = 5; // Upper bound for volatility search // Function for Brent's method to find the root const marketPriceDelta = (sigma: number) => { diff --git a/src/utils/vol/vol.test.ts b/src/utils/vol/vol.test.ts index c3c4226c..65db57eb 100644 --- a/src/utils/vol/vol.test.ts +++ b/src/utils/vol/vol.test.ts @@ -67,19 +67,21 @@ describe('Options Greeks BSM and IV convergence', () => { }); it('should calculate the correct implied volatility', () => { - const S = 100; // Spot price of the underlying asset - const K = 100; // Strike price of the option + const S = 2225; // Spot price of the underlying asset + const K = 2200; // Strike price of the option const sigma = 0.2; // Volatility of the asset const r = 0.01; // Risk-free interest rate const type = TypeOfOption.Call; // 'c' for call option - const t = 0.5; // Time to expiration + const t = 0.0076; // Time to expiration const q = 0; // Dividend yield const expectedPrice = 5.87602423383; const expectedIv = 0.2; // Calculate the option price using Black-Scholes-Merton model - const price = OptionsGreeks.blackScholesMerton(type, S, K, r, q, sigma, t); + //const price = OptionsGreeks.blackScholesMerton(type, S, K, r, q, sigma, t); + + const price = 10; // Calculate the implied volatility using the provided sigma function const impliedVol = OptionsGreeks.sigma(type, price, S, K, r, q, t); From a97961eeddbdcf716e1a8adc5fbc3b9343a5a52c Mon Sep 17 00:00:00 2001 From: Alcibiades Athens Date: Thu, 21 Dec 2023 19:21:22 -0500 Subject: [PATCH 2/2] fix: revert broken test case --- src/utils/vol/vol.test.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/utils/vol/vol.test.ts b/src/utils/vol/vol.test.ts index 65db57eb..c3c4226c 100644 --- a/src/utils/vol/vol.test.ts +++ b/src/utils/vol/vol.test.ts @@ -67,21 +67,19 @@ describe('Options Greeks BSM and IV convergence', () => { }); it('should calculate the correct implied volatility', () => { - const S = 2225; // Spot price of the underlying asset - const K = 2200; // Strike price of the option + const S = 100; // Spot price of the underlying asset + const K = 100; // Strike price of the option const sigma = 0.2; // Volatility of the asset const r = 0.01; // Risk-free interest rate const type = TypeOfOption.Call; // 'c' for call option - const t = 0.0076; // Time to expiration + const t = 0.5; // Time to expiration const q = 0; // Dividend yield const expectedPrice = 5.87602423383; const expectedIv = 0.2; // Calculate the option price using Black-Scholes-Merton model - //const price = OptionsGreeks.blackScholesMerton(type, S, K, r, q, sigma, t); - - const price = 10; + const price = OptionsGreeks.blackScholesMerton(type, S, K, r, q, sigma, t); // Calculate the implied volatility using the provided sigma function const impliedVol = OptionsGreeks.sigma(type, price, S, K, r, q, t);