Implied Volatility Using Black Scholes & fsolve

Hello, I am trying to calculate the implied volatility using fsolve, but I keep getting an error in fsolve and an error in:
Volatility = fsolve(@(x) myfunc(x,put_price,Interest,Stock,StrikePrice, TimeToMaturity,Yield),iniGuess);
Any suggestions on how to fix these errors would be greatly appreciated.
My code:
if true
iniGuess(1:32,1)=1; %%initial volatility guess
Interest(1:32,1)=.004; %%risk free interest rate
Stock(1:32,1)=158.69; %%Index level: 158.69
Volatility(1:32,1)=1; %%Volatility to be Optimized
TimeToMaturity(1:32,1)= 35/365; %%Time to Maturity: 35 days
StrikePrice=hw_3_dat(:,1); %%Strike Price (Given)
put_price=hw_3_dat(:,2); %%Put Price (Given)
Yield(1:32,1)=.01*Stock*35/365;
K=hw_3_dat(:,1);
Volatility = fsolve(@(x) myfunc(x,put_price,Interest,Stock,StrikePrice, TimeToMaturity,Yield),iniGuess);
function P = bs ( Interest, Volatility, Stock, StrikePrice, TimeToMaturity, Yield )
d1 = (ln(Stock ./ StrikePrice) + (Interest-Yield + (Volatility .^ 2) ./ 2) .* TimeToMaturity) ./ (Volatility .* sqrt(TimeToMaturity));
d2 = d1 - (Volatility .* sqrt(TimeToMaturity))
P = StrikePrice.*exp(-Interest-TimeToMaturity).*(-normcdf(d2)) - Stock.*exp(-Yield.*TimeToMaturity).*-normcdf(d1)
end

1 个评论

Please copy and paste the entire error message that fsolve returns. Then we might have a chance of understanding what happens.
Alan Weiss
MATLAB mathematical toolbox documentation

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Financial Toolbox 的更多信息

产品

版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by