% Marcet's parameterized expectations method as applied to
% the optimal growth problem: 
%
%             max sum beta^t u(c[t])    
%           {c[t]} t 
%
%       s.t. c[t]+k[t]=theta[t]k[t-1]^alpha +mu k[t-1]
%            ln(theta[t])=rho ln(theta[t-1])+eps[t]
%

% Ellen R. McGrattan, 11-28-90

% Reference: Den Haan and Marcet, JBES, 1990.

beta=.95;
alpha=.33;
rho=.95;
tau=1;
sige=.1;
lambda=.5;
mu=.1;
delta= [1.5333; -.33; -1];

maxn=100;
T=2500;


rand('normal');
rand('seed',0);
epsilon=rand(T+1,1)*sqrt(sige);
omega(1,1)=0;
for i=2:T+1; 
  omega(i,1)=rho*omega(i-1)+epsilon(i); 
end;
theta=exp(omega);

taui=1/tau;
k(1,1)=(alpha*beta/(1-beta*mu))^(1/(1-alpha));
c=zeros(T+1,1);
global zxv
for n=1:maxn;
  for i=2:T+1;   
    phi=delta(1)*k(i-1)^delta(2)*theta(i)^delta(3);
    k(i,1)=theta(i)*k(i-1)^alpha+mu*k(i-1)-(beta*phi)^(-taui);
  end;
  c(2:T+1,1)=(beta*delta(1)*k(1:T).^delta(2).*theta(2:T+1).^delta(3)).^ ..
              (-taui);
  zxv=[c(3:T+1).^(-tau).*(alpha*theta(3:T+1).*k(2:T).^(alpha-1)+mu), ..
       k(1:T-1),theta(2:T)];
  [deltan,f,g]=uncmin(delta,'marcetf1');
  if norm(deltan-delta)<1e-5; break; end;
  [deltan(:),delta(:)]
  delta=(1-lambda)*delta+lambda*deltan;
end;




