| 1 |
/* |
| 2 |
* The Hansen model following McCandless, George T. (2008): The ABCs of RBCs, Hardvard University Press, Chapter 6 |
| 3 |
* |
| 4 |
* This mod-file tests the correctness of forecasting with exogenous deterministic variables. |
| 5 |
* A forecast starting at the steady state in t=0, where the only shock is a perfectly |
| 6 |
* anticipated shock in t=8, is equal to the IRF to a 7 period anticipated news shock. |
| 7 |
* Note the timing difference due to the fact that in forecasting. the agent starts at the |
| 8 |
* steady state at time 0 and has the first endogenous reaction period at t=1 so that the shock at |
| 9 |
* t=8 is only 7 period anticipated |
| 10 |
|
| 11 |
* This implementation was written by Johannes Pfeifer. Please note that the |
| 12 |
* following copyright notice only applies to this Dynare implementation of the |
| 13 |
* model. |
| 14 |
*/ |
| 15 |
|
| 16 |
/* |
| 17 |
* Copyright © 2014 Johannes Pfeifer |
| 18 |
* |
| 19 |
* This file is part of Dynare. |
| 20 |
* |
| 21 |
* Dynare is free software: you can redistribute it and/or modify |
| 22 |
* it under the terms of the GNU General Public License as published by |
| 23 |
* the Free Software Foundation, either version 3 of the License, or |
| 24 |
* (at your option) any later version. |
| 25 |
* |
| 26 |
* Dynare is distributed in the hope that it will be useful, |
| 27 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 |
* GNU General Public License for more details. |
| 30 |
* |
| 31 |
* You should have received a copy of the GNU General Public License |
| 32 |
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. |
| 33 |
*/ |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
var c r y h k a; |
| 38 |
varexo eps_a_surp eps_a_antic; |
| 39 |
varexo_det e_det; |
| 40 |
|
| 41 |
parameters beta delta theta rho_a A_disutil; |
| 42 |
|
| 43 |
beta = 0.99; |
| 44 |
delta = 0.025; |
| 45 |
theta = 0.36; |
| 46 |
rho_a = 0.35; |
| 47 |
A_disutil = 2; |
| 48 |
|
| 49 |
model; |
| 50 |
1/c = beta*((1/c(+1))*(r(+1) +(1-delta))); |
| 51 |
(1-h)*(1-theta)*(y/h) = A_disutil*c; |
| 52 |
c = y +(1-delta)*k(-1) - k; |
| 53 |
y = a*k(-1)^(theta)*h^(1-theta); |
| 54 |
r = theta*(y/k(-1)); |
| 55 |
log(a)=rho_a*log(a(-1))+eps_a_surp+eps_a_antic(-7)+e_det; |
| 56 |
end; |
| 57 |
|
| 58 |
steady_state_model; |
| 59 |
a = 1; |
| 60 |
h = (1+(A_disutil/(1-theta))*(1 - (beta*delta*theta)/(1-beta*(1-delta))))^(-1); |
| 61 |
k = h*(theta*a/(1/beta -(1-delta)))^(1/(1-theta)); |
| 62 |
y = a*k^(theta)*h^(1-theta); |
| 63 |
c = y-delta*k; |
| 64 |
r = 1/beta - (1-delta); |
| 65 |
end; |
| 66 |
|
| 67 |
steady; |
| 68 |
|
| 69 |
shocks; |
| 70 |
var eps_a_surp; stderr 0; |
| 71 |
var eps_a_antic; stderr 0.01; |
| 72 |
var e_det; |
| 73 |
periods 8; |
| 74 |
values 0.01; |
| 75 |
end; |
| 76 |
|
| 77 |
stoch_simul(irf=40,nomoments, order=1); |
| 78 |
|
| 79 |
% make_ex_; |
| 80 |
|
| 81 |
forecast(periods=40); |
| 82 |
figure |
| 83 |
for ii=1:M_.orig_endo_nbr |
| 84 |
subplot(3,3,ii) |
| 85 |
var_name=M_.endo_names{ii}; |
| 86 |
var_index=strmatch(var_name, M_.endo_names,'exact'); |
| 87 |
plot(1:40,oo_.dr.ys(var_index)+oo_.irfs.([var_name,'_eps_a_antic']),'b',1:40,... % |
| 88 |
oo_.forecast.Mean.(var_name),'r--') |
| 89 |
title(var_name) |
| 90 |
difference(ii,:)=oo_.dr.ys(var_index)+oo_.irfs.([var_name,'_eps_a_antic'])-oo_.forecast.Mean.(var_name)'; |
| 91 |
end |
| 92 |
|
| 93 |
if max(max(abs(difference)))>1e-10 |
| 94 |
error('Forecasts with exogenous deterministic variable is wrong') |
| 95 |
end |