function [C0,P0] = CRRlbAD(T,S0,r,v,N)
% Octave/MATLAB function to price Lookback Call
% and Put options using path-dependent Arrow-Debreu
% expansions with the Cox-Ross-Rubinstein (CRR)
% binomial pricing model.
% INPUTS:                             (Example)
%   T  =  expiration time in years     (1)
%   S0 =  spot stock price             (100)
%   r  =  riskless yield per year      (0.05)
%   v  =  volatility; must be >0       (0.20)
%   N  =  height of the tree           (4)
% OUTPUTS:
%    C0 = Call option premium at t=0
%    P0 = Put option premium at t=0
% EXAMPLE:
%    [C0,P0]=CRRlb(1,100,0.05,0.20,4)
%
  [pu,up,R]=CRRparams(T,r,v,N);
  Sbar=NRTCRR(S0,up,1/up,N); % expanded S tree
  MinS=NRTmin(Sbar,N); MaxS=NRTmax(Sbar,N);
  Lbar=PathAD(pu*ones(N,N),R*ones(N,N),N);
  mN=2^N:(2*2^N-1); % all m-indices at expiry
  C0=(Sbar(mN)-MinS(mN))*Lbar(mN)'; % Call
  P0=(MaxS(mN)-Sbar(mN))*Lbar(mN)'; % Put
  return % ..inner producs give A-D expansions
end

