diff --git a/src/utils/vol/index.ts b/src/utils/vol/index.ts index f59d89af..dd8a7134 100644 --- a/src/utils/vol/index.ts +++ b/src/utils/vol/index.ts @@ -164,9 +164,7 @@ class OptionsGreeks { sigma: number, tau: number, ): number { - return ( - (log(st / K) + (r - q + pow(sigma, 2) / 2) * tau) / (sigma * sqrt(tau)) - ); + return (log(st / K) + (r + pow(sigma, 2) / 2) * tau) / (sigma * sqrt(tau)); } /** @@ -205,20 +203,23 @@ class OptionsGreeks { return 0; } + let ist = st; + + if (q !== 0) { + const dividendValue = st * q * tau * exp(-r * tau); + ist = st - dividendValue; + } + // Calculate d1 and d2 - const d1 = this.d1(st, K, r, q, sigma, tau); + const d1 = this.d1(ist, K, r, q, sigma, tau); const d2 = this.d2(d1, sigma, tau); if (type === TypeOfOption.Call) { // Calculate call option price - return ( - st * exp(-q * tau) * this.phi(d1) - K * exp(-r * tau) * this.phi(d2) - ); + return ist * this.phi(d1) - K * exp(-r * tau) * this.phi(d2); } // Calculate put option price - return ( - K * exp(-r * tau) * this.phi(-d2) - st * exp(-q * tau) * this.phi(-d1) - ); + return K * exp(-r * tau) * this.phi(-d2) - ist * this.phi(-d1); } /** diff --git a/src/utils/vol/vol.test.ts b/src/utils/vol/vol.test.ts index 4a5c49ac..c3c4226c 100644 --- a/src/utils/vol/vol.test.ts +++ b/src/utils/vol/vol.test.ts @@ -45,15 +45,15 @@ describe('Brent root-finding algorithm', () => { describe('Options Greeks BSM and IV convergence', () => { it('should calculate the correct price for a European put option using Black-Scholes-Merton model', () => { - const st = 100; // Spot price of the underlying asset - const K = 95; // Strike price of the option + const st = 40; // Spot price of the underlying asset + const K = 40; // Strike price of the option const q = 0.05; // Dividend yield const t = 0.5; // Time to expiration - const r = 0.1; // Risk-free interest rate - const sigma = 0.2; // Volatility of the asset + const r = 0.09; // Risk-free interest rate + const sigma = 0.3; // Volatility of the asset const calculatedPutPrice = OptionsGreeks.blackScholesMerton( - TypeOfOption.Put, + TypeOfOption.Call, st, K, r, @@ -63,7 +63,7 @@ describe('Options Greeks BSM and IV convergence', () => { ); // assertEquals in QUnit is analogous to toBeCloseTo in vitest with a precision of 4 decimal places - expect(calculatedPutPrice).toBeCloseTo(2.4648, 4); + expect(calculatedPutPrice).toBeCloseTo(3.6817718494101577, 2); }); it('should calculate the correct implied volatility', () => {