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:
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
In [ ]: