function [L] = ADnrt(p, R, N)
% Octave/Matlab function to compute Arrow-Debreu
% prices in a non-recombining tree by a variant
% of Jamshidian's forward induction.
% INPUTS:                             (Example)
%   p = array of up probabilities   (all 0.51)
%   R = array of riskless returns  (all 1.002)
%   N = tree height, must be >1           (10)
% OUTPUTS:
%   L = array of Arrow-Debreu prices lambda(m).
% EXAMPLE:
%   N = 10;
%   R = zeros(1,2*2^N-1); R(:,:)=1.002;  
%   p = zeros(1,2*2^N-1); p(:,:)=0.51;
%   L = ADnrt(p,R,10)
%
  L = zeros(1,2*2^N-1); % initialize output array
  L(1) = 1;      % lambda(1)=1
  for m=1:2^N-1  % all indices before the last row
    L(2*m)=(1-p(m))*L(m)/R(m); % down descendent
    L(2*m+1) = p(m)*L(m)/R(m); % up descendent
  end
  return; % L(m) now holds lambda(m)
end
