/*
 * This file implements the baseline Classical Monetary Economy model of Jordi Gal?(2008): Monetary Policy, Inflation,
 * and the Business Cycle, Princeton University Press, Chapter 2
 *
 * Note that this mod-file implements the non-linear first order conditions and that the IRFs show the linear deviations
 * from steady state.
 *
 * It demonstrate the neutrality of money by showing that real variables do not move after a monetary policy shock
 *
 * This implementation was written by Johannes Pfeifer. In case you spot mistakes,
 * email me at jpfeifer@gmx.de
 *
 * Please note that the following copyright notice only applies to this Dynare 
 * implementation of the model.
 */

/*
 * Copyright (C) 2013 Johannes Pfeifer
 *
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * It is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * For a copy of the GNU General Public License,
 * see <http://www.gnu.org/licenses/>.
 */

var C           //Consumption
    W_real      //Real Wage
    Pi          //inflation
    A           //AR(1) technology process
    N           //Hours worked
    R           //Nominal Interest Rate
    realinterest //Real Interest Rate
    Y           //Output
    m_growth_ann;//money growth
varexo eps_A    //technology shock
       eps_m;   //monetary policy shock

parameters alppha betta rho siggma phi phi_pi eta;

%----------------------------------------------------------------
% Follows parametrization of Chapter 3, p. 52
%----------------------------------------------------------------

alppha=0.33; //capital share
betta=0.99;  //discount factor
rho=0.9;     //autocorrelation technology shock
siggma=1;    //log utility   
phi=1;       //unitary Frisch elasticity
phi_pi=1.5;  //inflation feedback Taylor Rule
eta  =4;     // semi-elasticity of money demand


%----------------------------------------------------------------
% First Order Conditions
%----------------------------------------------------------------

model(linear);
//1. FOC Wages, eq. (6)
//W_real=C^siggma*N^phi;
W_real=siggma*C+phi*N;
//2. Euler equation eq. (7)
//1/R=betta*(C(+1)/C)^(-siggma)/Pi(+1);
0=R-siggma*(C(+1)-C)-Pi(+1);
//3. Production function eq. (11)
//A*N^(1-alppha)= C;
Y=A+N*(1-alppha);
//4. FOC wages firm, eq. (13)
//W_real=(1-alppha)*A*N^(-alppha);
W_real=A-alppha*N;
//5. Definition Real interest rate//
//realinterest=R/Pi(+1);
realinterest+Pi(+1)=R;
//6. Monetary Policy Rule, eq. (22)
R=1/betta*Pi^phi_pi+eps_m;

//7. Market Clearing, eq. (15)
C=Y;
//8. Technology Shock
//log(A)=rho*log(A(-1))+eps_A;
A=rho*A(-1)+eps_A;
//11. Money growth (derived from eq. (10))
//m_growth_ann=4*(log(Y)-log(Y(-1))-eta*(log(R)-log(R(-1)))+log(Pi));
m_growth_ann=Y-Y(-1)-eta*(R-R(-1))+Pi;

end;

%----------------------------------------------------------------
%  define shock variances
%---------------------------------------------------------------

shocks;
var eps_A; stderr 1;
var eps_m; stderr 1;
end;

%----------------------------------------------------------------
%  Initial Values for steady state
%---------------------------------------------------------------

initval;
A=0;
R=0;
Pi=0;
realinterest=0;
N=0;
C=0;
W_real=0;
Y=0;
m_growth_ann=0;
end;



steady;
check;

%----------------------------------------------------------------
% generate IRFs to show neutrality of money
%----------------------------------------------------------------

stoch_simul(irf=20,order=1) Y C Pi R realinterest m_growth_ann;