function [C0, P0] = CRReurAD(T,S0,K,r,v,N)
% Octave/MATLAB function to price European Call
% and Put options by Arrow-Debreu expansion
% in the Cox-Ross-Rubinstein (CRR) model.
% INPUTS:                              (Example)
%    T =  expiration time in years     (1)
%    S0 =  spot stock price            (90)
%    K =  strike price                 (95)
%    r =  riskless yield per year      (0.02)
%    v =  volatility; must be >0       (0.15)
%    N =  height of the binomial tree  (10)
% OUTPUTS:
%    C0 =  price of the Call option at t=0.
%    P0  =  price of the Put option at t=0.
% EXAMPLE:
%    [C0, P0]=CRReurAD(1,90,95,0.02,0.15,10);
%
  [pu,up,R] = CRRparams(T,r,v,N); % Use CRR values 
  Njs=0:N;  % all j values for n=N (expiry t=T)
  SNj=S0*up.^(2*Njs-N);  % Terminal prices S(N,j)
  lAD=binopdf(Njs,N,pu)*exp(-r*T); % A-D prices
  C0=max(SNj-K,0)*lAD'; % i.p. with Call payoff
  P0=max(K-SNj,0)*lAD'; % i.p. with Put payoff
  return; % Premiums C0 and P0 by A-D expansion
end
