function S = StreeCRR(S0,up,N)
% Octave/MATLAB function to compute the recombining
% binomial tree S of underlying asset prices in the
% Cox-Ross-Rubinstein (CRR) model.
% INPUTS:                                 (Example)
%   S0 = asset spot price                     (100)
%   up = up factor, must be > 0               (1.2)
%   N = binomial tree height, must be >=0       (3)
% OUTPUT:
%   S =  (N+1)x(N+1) matrix S(n,j) of asset prices.
% EXAMPLE:
%  S = StreeCRR(100,1.2,3)
%
  S = zeros(N+1,N+1); % allocate the output matrix
  for n=0:N        % all time steps up to N
    for j=0:n      % state indices at time n
      S(n+1,j+1)=S0*up^(2*j-n);
    end
  end
  return
end
