cp=8.08;
vol=0.5075;
rate=0.0414;
T=3;
X=8.4;
N=100;
dt=T/N;
up=exp(vol*sqrt(dt));
down=1/up;
p=(exp(rate*dt)-down)/(up-down);
s=zeros(N,N);
v=zeros(N,N);
p=zeros(N,N);
for n=0:N-1;
for j=0:n;
s(n+1,j+1)=cp*(up)^(n-j)*(down)^j;
end;
end;
for j=N:-1:1;
v(N,j)=max(s(N,j)-X,0);
end;
for i=N-1:-1:1;
for j=i:-1:1;
H=(1-p)*(v(i+1,j+1))/(1+rate*dt)+p*(v(i+1,j))/(1+rate*dt);
v(i,j)=max(s(i,j)-X,H);
end;
end;
??? In an assignment A(matrix,matrix) = B, the number of rows in B
and the number of elements in the A row index matrix must be the same.
有高手知道程序怎么修改么 ,谢谢了。