function [C0, P0] = CRRfltAD(T, S0, r, v, N)
% Octave/MATLAB function to price floating strike
% 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             (90)
%   r  =  riskless yield per year      (0.02)
%   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]=CRRfltAD(1,90,0.02,0.20,4);
%
  [pu,up,R]=CRRparams(T,r,v,N);
  Sbar=NRTCRR(S0,up,1/up,N); % expanded S tree
  Ubar=NRTpsums(Sbar,N); % all partial sums
  Lbar=PathAD(pu*ones(N,N),R*ones(N,N),N);
  mN=2^N:(2*2^N-1); % all m-indices at expiry
  AvgN=Ubar(mN)/(N+1); % S averages at expiry
  C0=max(0,Sbar(mN)-AvgN)*Lbar(mN)'; % Call
  P0=max(0,AvgN-Sbar(mN))*Lbar(mN)'; % Put
  return % ..inner producs give A-D expansions
end
