Implied Volatility for a European Call Option

Implied Volatility of a option is estimate of its underlying volatility. The arbitrage free price for a European Call option under the Black-Scholes model is:

$$C_0=S_0\mathrm{\Phi}\bigg(\frac{\log{\frac{S_0}{K^{*}}}}{\sigma\sqrt{T}}+\frac{1}{2} \sigma \sqrt{T}\bigg)-K^{*}\mathrm{\Phi}\bigg(\frac{\log{\frac{S_0}{K^{*}}}}{\sigma\sqrt{T}}-\frac{1}{2} \sigma \sqrt{T}\bigg)$$

where $S_0$ is the inital stock price, $K$ is the strike price, $r$ is the interest rate per year, $T$ is the expiration time in years, and $\sigma$ is the volatility. Define $K^{*}=Ke^{-rT}$. Solving for the implied volatility involves solving for $$f(\sigma)=P-C_0(\sigma)=0$$ where $P$ is the current option price. The implied volatility can be solved using a root-solving method such as Netwon's method.


In [1]:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from scipy.stats import norm
import numpy as np

def netwon_solve(func,x0):
    
    tol=1e-9
    max_iter=1e4
    f=np.inf
    x=x0
    
    k=0
    while abs(f)>tol and max_iter>=k:
        k+=1
        f,g=func(x)
        x=x-(f/g)
        print "Iteration: %d f(x)= %f x=%f" % (k,f,x) 
        
    return x
    
    

    
def europeanCall_impliedVolatility(S0,sig,K,T,r,Price):
    
    norm_x=norm()
    Ks=K*np.exp(-r*T)
    Z=np.log(S0/Ks)/(sig*np.sqrt(T))
    D=.5*sig*np.sqrt(T)
    
    
    dZ=.5*np.sqrt(T)
    dD=np.log(S0/Ks)/((sig**2)*np.sqrt(T))
    
    C=Price-(S0*norm_x.cdf(Z+D)-Ks*norm_x.cdf(Z-D))
    dC=-(S0*(dZ-dD)*norm_x.pdf(Z+D)+Ks*(dZ+dD)*norm_x.pdf(Z-D))
    
    return C,dC



if __name__=="__main__":
    
    S0=82.0
    K=70.0
    Price=14.0
    T=1.0/12.0
    r=.06
    
    
    func=lambda sig:europeanCall_impliedVolatility(S0,sig,K,T,r,Price)
    
    sig=2
    
    sig=netwon_solve(func,sig)
    
    
    print "The implied volatility is %f" % sig


Iteration: 1 f(x)= -10.063031 x=0.745443
Iteration: 2 f(x)= -0.444037 x=0.677024
Iteration: 3 f(x)= -0.012436 x=0.674989
Iteration: 4 f(x)= -0.000013 x=0.674987
Iteration: 5 f(x)= -0.000000 x=0.674987
The implied volatility is 0.674987

References:

  1. Introduction to the Mathematics of Finance, Ruth J. Williams,American Mathematical Society, 2006
  2. http://www.investopedia.com/articles/optioninvestor/08/implied-volatility.asp

In [ ]: