function Sbar = NRTCRR(S0, up, down, N)
% Octave/MATLAB function to compute the binary non-
% recombining tree of underlying asset prices from a
% spot price and constant up and down factors.
% INPUTS:                                 (Example)
%   S0 = asset spot price                     (100)
%   up = up factor                            (1.2)
%   down = down factor                        (0.8)
%   N = binomial tree height, must be >=0       (3)
% OUTPUT:
%   Sbar = tree as linear array Sbar(m), 0<m<2*2^N
% EXAMPLE:
%  Sbar = NRTCRR(100,1.2,0.8,3)
%
  Sbar = zeros(1,2*2^N-1); % allocate the output matrix
  Sbar(1) = S0;   % initialize with the spot price
  for m=1:2^N-1   % all future times up to N-1
    Sbar(2*m) = down*Sbar(m);   % down descendent
    Sbar(2*m+1) = up*Sbar(m);   % up descendent
  end
  return
end
