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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Darshan Ramakant Bhat
am 6 Mär. 2017
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 Kommentare
Siehe auch
Kategorien
Mehr zu Financial Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!