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?

1 次查看(过去 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

回答(1 个)

Darshan Ramakant Bhat
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

类别

Help CenterFile Exchange 中查找有关 Financial Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by