% Basic CIA  Model as in Walsh
%
close all;

%----------------------------------------------------------------
% 1. Defining variables
%----------------------------------------------------------------

var c m pie n y r k i w z theta; % the endogenous variables
varexo e1 e2; % the exogenous variables

parameters psi eta phi beta alpha delta rho1 rho2 rho3; % the parameters
%----------------------------------------------------------------
% 2. Calibration
%----------------------------------------------------------------

psi =1.34;
eta =1;
phi=2;
beta = 0.975;
alpha   = 0.36;
delta   = 0.019;
rho1     = 0.95;  
rho2 = 0.49;
rho3 =0;
sigmae1 = 0.007;
sigmae2 = 0.0089;

%----------------------------------------------------------------
% 3. Model
%----------------------------------------------------------------
model; 

psi*((1-n)^(-eta))=((1-alpha)*(y/n))*((beta)/(1+pie(+1)))*((c(+1))^(-phi));
((beta)/(1+pie(+1)))*((c(+1))^(-phi))=((beta)/(1+pie(+2)))*((c(+2))^(-phi))*(((1-alpha)*(y(+1)/k))+(1-delta));
y=c+i;
r=alpha*(y/k(-1))-delta;
w=(1-alpha)*(y/n);
i=k-(1-delta)*k(-1);
y = exp(z)*(k(-1)^alpha)*(n^(1-alpha));
m=((1+theta)/(1+pie))*m(-1);
(1+i)=(1+r)*(1+pie(+1));
z = rho1*z(-1)+e1;
theta=(rho2*theta(-1))+(rho3*z(-1))+(e2*-1);
end;


%----------------------------------------------------------------
% 4. Computation
%----------------------------------------------------------------

initval;
i=0.1; 
c =0.9;
m= 2;
pie=0.5;
n=0.2;
y=1;
r=0.06;
k = 3;
z=0;
theta=0;
end;

shocks;
var e1 = sigmae1^(2);
var e2 = sigmae2^(2);
end;

steady;
stoch_simul(hp_filter = 1600, irf=30, order = 1) c m pie n y r i;
%stoch_simul(irf=40) c m pie n y i r k;

%----------------------------------------------------------------
% 5. Some Results
%----------------------------------------------------------------

%statistic1 = 100*sqrt(diag(oo_.var(1:6,1:6)))./oo_.mean(1:6);
%table('Relative standard deviations in %',strvcat('VARIABLE','REL. S.D.'),lgy_(1:6,:),statistic1,10,8,4);
