%MEHRATS   simulates time series for the model in Mehra and Prescott,
%          JME 1985.  (See also Mehra.m)

%          Ellen McGrattan, 9-26-02

T      = 10000;
mu     = .018;
delta  = .036*3;
phi    = .43;
phi    = .8;
lam1   = 1+mu+delta;
lam2   = 1+mu-delta;
alpha  = 1.5;
beta   = (1+mu)^alpha/1.04;

Phi    = [phi,1-phi;
          1-phi,phi];
Lam    = [lam1;lam2];
s      = markov(Phi,T,1);
A      = [1-beta*phi*lam1^(1-alpha),-beta*(1-phi)*lam2^(1-alpha);
          -beta*(1-phi)*lam1^(1-alpha),1-beta*phi*lam2^(1-alpha)];
b      = [beta*phi*lam1^(1-alpha)+beta*(1-phi)*lam2^(1-alpha);
          beta*(1-phi)*lam1^(1-alpha)+beta*phi*lam2^(1-alpha)];
w      = A\b;
x      = Lam(s);
y      = cumprod(x);

W      = w(s);
Pe     = W.*y;
o      = ones(T,1);
Re     = (Phi(s,1) .* (lam1*(w(1)+1)* o./W-1 ) + ...
          Phi(s,2) .* (lam2*(w(2)+1)* o./W-1 ))*100;
Rf     = (o./(beta* (Phi(s,1)*lam1^(-alpha)+Phi(s,2)*lam2^(-alpha)) )-1)*100;        
EP     = mean(Re)-mean(Rf);

