Dear forum members,
I have been trying (along 3 nights) to implement an algorith to calculate implied volatility.
Calculation of calls and puts prices is OK (follow the code).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Public Function normal(x)
normal = Application.WorksheetFunction.NormSDist(x)
End Function
Public Function precobs(S, sigma, r, strike, T, div, tipo)
Dim d1 As Single
Dim d2 As Single
T = T / 252
r = 1 * Log(1 + r / 1)
d1 = (Log(S / strike) + (r + (sigma ^ 2) / 2) * T) / (sigma * Sqr(T))
d2 = d1 - sigma * Sqr(T)
If tipo = "Call" Then
precobs = S * normal(d1) * Exp(-div * T) - strike * Exp(-r * T) * normal(d2)
Else
precobs = strike * Exp(-r * T) * normal(-d2) - S * normal(-d1) * Exp(-div * T)
End If
End Function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legend: precobs=price of option from black scholes formula
tipo=call/put
the rest is intuitive
User gives the inputs and the function calculates the price.
Well done.
But, implied volatility requires such a routine which finds the volatility (sigma) whose lets price from black scholes be equal to market price.
I tryed something like this:
Public Function impv(mktprice,S,r,T,tipo,div,strike)
dim dif as double
dim sigma as double
dim cont as double
dim limit as double
cont=0
dif=abs(mktprice-precobs(S,sigma,strike,r,T,tipo,div))
limit=10^(-2)
Do While dif>limit and cont<2000 and sigma>0
sigma=sigma-0.01
dif=abs(mktprice-precobs(S,sigma,strike,r,T,tipo,div))
cont=cont+1
loop
if cont>2000 or sigma<0 then
impv="fail!"
else
impv=sigma
end if
End Function
It doesn't work.
I tried other codes I found on web but neither works.
Thank You
Regards,
Rogerio.
I have been trying (along 3 nights) to implement an algorith to calculate implied volatility.
Calculation of calls and puts prices is OK (follow the code).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Public Function normal(x)
normal = Application.WorksheetFunction.NormSDist(x)
End Function
Public Function precobs(S, sigma, r, strike, T, div, tipo)
Dim d1 As Single
Dim d2 As Single
T = T / 252
r = 1 * Log(1 + r / 1)
d1 = (Log(S / strike) + (r + (sigma ^ 2) / 2) * T) / (sigma * Sqr(T))
d2 = d1 - sigma * Sqr(T)
If tipo = "Call" Then
precobs = S * normal(d1) * Exp(-div * T) - strike * Exp(-r * T) * normal(d2)
Else
precobs = strike * Exp(-r * T) * normal(-d2) - S * normal(-d1) * Exp(-div * T)
End If
End Function
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legend: precobs=price of option from black scholes formula
tipo=call/put
the rest is intuitive
User gives the inputs and the function calculates the price.
Well done.
But, implied volatility requires such a routine which finds the volatility (sigma) whose lets price from black scholes be equal to market price.
I tryed something like this:
Public Function impv(mktprice,S,r,T,tipo,div,strike)
dim dif as double
dim sigma as double
dim cont as double
dim limit as double
cont=0
dif=abs(mktprice-precobs(S,sigma,strike,r,T,tipo,div))
limit=10^(-2)
Do While dif>limit and cont<2000 and sigma>0
sigma=sigma-0.01
dif=abs(mktprice-precobs(S,sigma,strike,r,T,tipo,div))
cont=cont+1
loop
if cont>2000 or sigma<0 then
impv="fail!"
else
impv=sigma
end if
End Function
It doesn't work.
I tried other codes I found on web but neither works.
Thank You
Regards,
Rogerio.