[Matlab] Binomial tree

  • Thread starter Thread starter kelyos
  • Start date Start date
Joined
3/12/12
Messages
1
Points
11
Hello everyone,
I'm student girl in university of UCL and I' learning coding in Matlab to implement the Cox Ross Rubinstein formula to price Option.
That's my error..

"??? Index exceeds matrix dimensions.
Error in ==> americantree at 26
put(i, j) = exp(-R * dt) * (p * (pf(i , j )) + ( (1-p )* pf(i , j)));"

And here my entirely code to get the price of the option
If someone here could help me, please :(

Code:
function C = americantree(s,K,T,R,sigma,M)
 
dt=T/M;
voldt = sigma * sqrt(dt);
up = exp(voldt);
down = 1 / up;
r = exp(R * dt);
p = (r - down) / (up - down);
 
%compute stock price at each node
 
for  i=1:(M+1)
 
    %for j= 1:(i+1)
St= s*up^(M-1-i)*down^(i-1);
 
pf(i)= max(K-St,0);
end;
 
%compute terminal payoffs
 
 
% work backwards to price the option at each nodes
for i= (M-1):-1:1
    for j=(i+1):-1:1   
        put(i, j) = exp(-R * dt) * (p * (pf(i , j )) + ( (1-p )* pf(i , j)));
        v(i, j) = max(K - pr(i, j),put(i, j));
    end;
end;
 
  C=v(1,1);
 
I might be wrong because I myself started using MATLAB very recently but here is what I see. You have:
pf(i)= max(K-St,0);

which is supposedly a vector and then you have

pf(i , j ) where the put is? If pf is a vector why use two coefficients?
 
Back
Top Bottom