I'm trying to create a function to calculate option price under Black-Scholes model. But it keeps saying that there is a mistake on d1; I double check it, but I can't find a mistake in there. Perhaps there is other thing I'm missing?
2 ビュー (過去 30 日間)
古いコメントを表示
function [c,p]=european_formula(id, K, T, S, sigma, q, r)
i=id;
X=K;
t=T;
S0=S;
v=sigma;
divd=q;
R=r;
d1=(log(So/X)+(R-d+0.5*v^2)*t)/(v*sqrt(t));
d2=d1-v*sqrt(t);
if i==1
c=So*exp(-divd*t)*cdf(d1)-x*exp(-r*t)*cdf(d2);
else
p=-S0*exp(-divd*t)*cdf(-d1)+x*exp(-r*t)*cdf(-d2);
end
0 件のコメント
回答 (1 件)
Darshan Ramakant Bhat
2017 年 3 月 6 日
In the line
d1=(log(So/X)+(R-d+0.5*v^2)*t)/(v*sqrt(t));
What is 'So' ?, it seems to be undefined. I think it should be 'S0'. Similarly in the line
c=So*exp(-divd*t)*cdf(d1)-x*exp(-r*t)*cdf(d2);
'So' is appearing again. I think this is the error you are getting.
Regards
Darshan Bhat
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Financial Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!