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

질문:

2018년 11월 10일

댓글:

2018년 11월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by