k=0.045; pr=0.5; N=100; interestUp=2.5; InterestDown=0.4; t=0.5; T=2; period=T/t; nodes=0; step=zeros(1,period); for x = 1 : period nodes=nodes+x; step(1,x)=x; end value=zeros(period,period); interestrate = [0.0554,0.06004,0.04421,0.06915,0.05437,0.04275,0.07864,0.06184,0.04862,0.03823]; m=period; n=nodes; lastValue=ones(1,period); for x = 1 : period if k > interestrate(n) lastValue(1,m)= N*(k-interestrate(n))*t; else lastValue(1,m) = 0; end m=m-1; n=n-1; end display(lastValue); n = nodes; m = period; for x = 1 : period value(period,m)= lastValue(m)/(1+(interestrate(n)*t)); display(value(period,m)); n=n-1; m=m-1; end n=period-1; p=period-1; for x = 1:(period-1) n=p; for j = 1:p value(p,n)=(pr*value(p+1,n)+(1-pr)*value(p+1,n+1))/(1+interestrate(n)*t); n=n-1; end p=p-1; end display(value);