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 个评论
Alan Weiss
2018-11-12
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 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!