필터 지우기
필터 지우기

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

답변 (1개)

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

카테고리

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