function [C, P] = CRRflt(T, S0, r, v, N)
% Octave/MATLAB function to price floating strike
% Call and Put options using 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:
%    C = Call option NRT.
%    P = Put option NRT.
% EXAMPLE:
%    [C,P] = CRRflt(1,90,0.02,0.20,4);
% To get just the premiums at t=0, use
%   C(1),P(1)
%
  [pu,up,R]=CRRparams(T,r,v,N);
  Sbar=NRTCRR(S0,up,1/up,N); % expanded S tree
  Ubar=NRTpsums(Sbar,N); % path partial sums
  C=zeros(size(Sbar));  P=zeros(size(Sbar));
  for m=2^N:(2*2^N -1) % m indices at expiry
    Avg = Ubar(m)/(N+1);       % N+1 summands
    C(m) = max(0,Sbar(m)-Avg); % Call payoff
    P(m) = max(0,Avg-Sbar(m)); % Put payoff
  end  % ...prices set at expiry.
  for m=(2^N-1):-1:1 % recursive previous indices
    C(m) = (pu*C(2*m+1) + (1-pu)*C(2*m))/R;
    P(m) = (pu*P(2*m+1) + (1-pu)*P(2*m))/R;
  end % ...all prices set by backward induction. 
  return
end

