欧式期权二叉树MATLAB程序
function EXS()
S=input('请输入当前股价:\n');
K=input('请输入股票执行价格:\n');
r=input('请输入无风险利率:\n');
theta=input('请输入波动率:\n');
T=input('请输入到期时间:\n');
bc=input('请输入步长:\n');
q=input('请输入股息率:\n');
KZ=input('是否为看涨期权?若是请输入1,若不是请输入其他任意值\n');
u=exp(theta*(T/bc)^0.5);
d=1/u;
a=exp((r-q)*(T/bc));
p=(a-d)/(u-d);
stock=[];
option=[];
stock(1,1)=S;
for i=2:bc+1
for j=1:i
if(j<=i/2)
stock(i,j)=stock(i-1,j)*u;
else
stock(i,j)=stock(i-1,j-1)*d;
end
end
end
for i=1:bc+1
if(KZ==1)
if(stock(bc+1,i)<=K)
option(bc+1,i)=0;
else
option(bc+1,i)=stock(bc+1,i)-K;
end
else
if(stock(bc+1,i)>=S)
option(bc+1,i)=0;
else
option(bc+1,i)=K-stock(bc+1,i);
end
end
end
for i=bc:-1:1;
for j=1:i
option(i,j)=(option(i+1,j)*p+option(i+1,j+1)*(1-p))*exp(-r*T/bc);
end
end
stock,option