Debian Codegraph @

tests/forecast/forecast_test_AR1_varexo_det_order_2.mod

raw
1 %test whether forecast for AR1 is correct
2 // Endogenous variables: consumption and capital
3 var junk A junk2;
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)^2;
17 junk2=0.9*junk2(-1);
18 end;
19
20 steady_state_model;
21 A = 0;
22 junk=0;
23 junk2=0;
24 end;
25 steady;
26
27 // Declare a positive technological shock in period 1
28 shocks;
29 var epsilon=0.01^2;
30 end;
31
32 stoch_simul(order=2,irf=0);
33
34 options_.forecast_replic=10000;
35 forecast(periods=100,conf_sig=0.95) A;
36 %% get theoretical forecast error variance for AR(1) process:
37 var_analytical=NaN(1+100,1);
38 var_analytical(1,1)=0; %zero variance in initial period
39 for ii=1:100
40 var_analytical(ii+1,1)=var_analytical(ii,1)+(rho^(ii-1))^2*0.01^2;
41 end
42 std_analytical=sqrt(var_analytical);
43
44 if norm(oo_.forecast.Mean.A-0,Inf)>1e-9
45 error('Mean forecast does not match theoretical moments')
46 end
47 if norm(oo_.forecast.HPDsup.A-norminv(0.975)*std_analytical(2:end),Inf)>2e-3
48 error('Forecast variance does not match theoretical moments')
49 end
50
51 varobs A junk2;
52
53 shocks;
54 var epsilon=0.01^2;
55 var A=0.01^2;
56 var junk2=0.01^2;
57 end;
58
59 forecast(periods=100,conf_sig=0.95) A;
60 std_analytical_ME=sqrt(var_analytical+0.01^2);
61 if norm(oo_.forecast.Mean.A-0,Inf)>1e-9
62 error('Mean forecast with ME does not match theoretical moments')
63 end
64 if norm(oo_.forecast.HPDsup.A-norminv(0.975)*std_analytical(2:end),Inf)>2e-3
65 error('Forecast variance with ME does not match theoretical moments')
66 end
67 if norm(oo_.forecast.HPDsup_ME.A-norminv(0.975)*std_analytical_ME(2:end),Inf)>2e-3
68 error('Forecast variance with ME does not match theoretical moments')
69 end