Debian Codegraph @

tests/moments/example1_hp_test.mod

raw
1 @#include "example1_common.inc"
2
3 // Parameter values
4 alpha = 0.36;
5 rho = 0.95;
6 tau = 0.025;
7 beta = 0.99;
8 delta = 0.025;
9 psi = 0;
10 theta = 2.95;
11
12 phi = 0.1;
13
14 shocks;
15 var e; stderr 0.009;
16 var u; stderr 0.009;
17 var e, u = phi*0.009*0.009;
18 end;
19
20 steady(solve_algo=4,maxit=1000);
21
22 stoch_simul(order=1,nofunctions,hp_filter=1600,irf=0,filtered_theoretical_moments_grid=8192);
23
24 total_var_filtered=diag(oo_.var);
25 oo_filtered_all_shocks=oo_;
26
27 stoch_simul(order=1,nofunctions,hp_filter=0,periods=2500000,nomoments);
28 send_endogenous_variables_to_workspace;
29 options_.nomoments=0;
30 oo_unfiltered_all_shocks=oo_;
31
32 [junk, y_filtered]=sample_hp_filter(y,1600);
33 [junk, c_filtered]=sample_hp_filter(c,1600);
34 [junk, k_filtered]=sample_hp_filter(k,1600);
35 [junk, a_filtered]=sample_hp_filter(a,1600);
36 [junk, h_filtered]=sample_hp_filter(h,1600);
37 [junk, b_filtered]=sample_hp_filter(b,1600);
38
39 verbatim;
40 total_std_all_shocks_filtered_sim=std([y_filtered c_filtered k_filtered a_filtered h_filtered b_filtered]);
41 cov_filtered_all_shocks=cov([y_filtered c_filtered k_filtered a_filtered h_filtered b_filtered]);
42 acf = zeros(6);
43 [junk, acf(:,1)] = sample_autocovariance([y_filtered ],5);
44 [junk, acf(:,2)] = sample_autocovariance([c_filtered ],5);
45 [junk, acf(:,3)] = sample_autocovariance([k_filtered ],5);
46 [junk, acf(:,4)] = sample_autocovariance([a_filtered ],5);
47 [junk, acf(:,5)] = sample_autocovariance([h_filtered ],5);
48 [junk, acf(:,6)] = sample_autocovariance([b_filtered ],5);
49 autocorr_filtered_all_shocks=acf(2:end,:)';
50 end;
51
52 shocks;
53 var e; stderr 0;
54 var u; stderr 0.009;
55 var e, u = phi*0.009*0;
56 end;
57
58 stoch_simul(order=1,nofunctions,hp_filter=1600,irf=0,periods=0);
59
60 total_var_filtered_one_shock=diag(oo_.var);
61 oo_filtered_one_shock=oo_;
62
63 stoch_simul(order=1,nofunctions,hp_filter=0,periods=2500000,nomoments);
64 send_endogenous_variables_to_workspace;
65 oo_unfiltered_one_shock=oo_;
66
67 [junk, y_filtered]=sample_hp_filter(y,1600);
68 [junk, c_filtered]=sample_hp_filter(c,1600);
69 [junk, k_filtered]=sample_hp_filter(k,1600);
70 [junk, a_filtered]=sample_hp_filter(a,1600);
71 [junk, h_filtered]=sample_hp_filter(h,1600);
72 [junk, b_filtered]=sample_hp_filter(b,1600);
73
74 verbatim;
75 total_std_one_shock_filtered_sim=std([y_filtered c_filtered k_filtered a_filtered h_filtered b_filtered]);
76 cov_filtered_one_shock=cov([y_filtered c_filtered k_filtered a_filtered h_filtered b_filtered]);
77 acf = zeros(6);
78 [junk, acf(:,1)] = sample_autocovariance([y_filtered ],5);
79 [junk, acf(:,2)] = sample_autocovariance([c_filtered ],5);
80 [junk, acf(:,3)] = sample_autocovariance([k_filtered ],5);
81 [junk, acf(:,4)] = sample_autocovariance([a_filtered ],5);
82 [junk, acf(:,5)] = sample_autocovariance([h_filtered ],5);
83 [junk, acf(:,6)] = sample_autocovariance([b_filtered ],5);
84 autocorr_filtered_one_shock=acf(2:end,:)';
85 end;
86
87 if max(abs((1-(total_std_one_shock_filtered_sim.^2)./(total_std_all_shocks_filtered_sim.^2))*100-oo_filtered_all_shocks.variance_decomposition(:,1)'))>2
88 error('Variance Decomposition wrong')
89 end
90
91 if max(max(abs(oo_filtered_all_shocks.var-cov_filtered_all_shocks)))>1e-4;
92 error('Covariance wrong')
93 end
94
95 if max(max(abs(oo_filtered_one_shock.var-cov_filtered_one_shock)))>5e-5;
96 error('Covariance wrong')
97 end
98
99 for ii=1:options_.ar
100 autocorr_model_all_shocks(:,ii)=diag(oo_filtered_all_shocks.autocorr{ii});
101 autocorr_model_one_shock(:,ii)=diag(oo_filtered_one_shock.autocorr{ii});
102 end
103
104 if max(max(abs(autocorr_model_all_shocks-autocorr_filtered_all_shocks)))>1e-2;
105 error('Covariance wrong')
106 end
107
108 if max(max(abs(autocorr_model_one_shock-autocorr_filtered_one_shock)))>1e-2;
109 error('Covariance wrong')
110 end