Debian Codegraph @

tests/forecast/forecast_test_AR1_varexo_det.mod

raw
1 %test whether forecast for AR1 is correct
2 // Endogenous variables: consumption and capital
3 var junk A;
4
5 // Exogenous variable: technology level
6 varexo epsilon;
7 varexo_det eps_det;
8 // Parameters declaration and calibration
9 parameters rho;
10
11 rho=0.9;
12
13 // Equilibrium conditions
14 model;
15 A= rho*A(-1)+epsilon + eps_det;
16 junk=0.9*junk(+1);
17 end;
18
19 steady_state_model;
20 A = 0;
21 end;
22 steady;
23
24 // Declare a positive technological shock in period 1
25 shocks;
26 var epsilon=0.01^2;
27 end;
28
29 stoch_simul(order=1,irf=0);
30
31 options_.forecast_replic=10000;
32 forecast(periods=500,conf_sig=0.95) A;
33 %% get theoretical forecast error variance for AR(1) process:
34 var_analytical=NaN(1+500,1);
35 var_analytical(1,1)=0; %zero variance in initial period
36 for ii=1:500
37 var_analytical(ii+1,1)=var_analytical(ii,1)+(rho^(ii-1))^2*0.01^2;
38 end
39 std_theoretical=sqrt(var_analytical);
40
41 if norm(oo_.forecast.Mean.A-0,Inf)>1e-9
42 error('Mean forecast does not match theoretical moments')
43 end
44 if norm(oo_.forecast.HPDsup.A-norminv(0.975)*std_theoretical(2:end),Inf)>1e-9
45 error('Forecast variance does not match theoretical moments')
46 end