Debian Codegraph @

tests/estimation/method_of_moments/RBC/RBC_MoM_Andreasen.mod

raw
1 % Tests SMM and GMM routines
2 %
3 % Copyright © 2020-2021 Dynare Team
4 %
5 % This file is part of Dynare.
6 %
7 % Dynare is free software: you can redistribute it and/or modify
8 % it under the terms of the GNU General Public License as published by
9 % the Free Software Foundation, either version 3 of the License, or
10 % (at your option) any later version.
11 %
12 % Dynare is distributed in the hope that it will be useful,
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 % GNU General Public License for more details.
16 %
17 % You should have received a copy of the GNU General Public License
18 % along with Dynare. If not, see <https://www.gnu.org/licenses/>.
19 % =========================================================================
20
21 % Define testscenario
22 @#define orderApp = 2
23 @#define estimParams = 1
24
25 % Note that we will set the numerical optimization tolerance levels very large to speed up the testsuite
26 @#define optimizer = 13
27
28
29 @#include "RBC_MoM_common.inc"
30
31 shocks;
32 var u_a; stderr 0.0072;
33 end;
34
35 varobs c iv n;
36
37
38 @#if estimParams == 0
39 estimated_params;
40 DELTA, 0.025;
41 BETTA, 0.984;
42 B, 0.5;
43 ETAc, 2;
44 ALFA, 0.667;
45 RHOA, 0.979;
46 stderr u_a, 0.0072;
47 end;
48 @#endif
49
50 @#if estimParams == 1
51 estimated_params;
52 DELTA, , 0, 1;
53 BETTA, , 0, 1;
54 B, , 0, 1;
55 ETAc, , 0, 10;
56 ALFA, , 0, 1;
57 RHOA, , 0, 1;
58 stderr u_a, , 0, 1;
59 end;
60 @#endif
61
62 @#if estimParams == 2
63 estimated_params;
64 DELTA, 0.025, 0, 1, normal_pdf, 0.02, 0.5;
65 BETTA, 0.98, 0, 1, beta_pdf, 0.90, 0.25;
66 B, 0.45, 0, 1, normal_pdf, 0.40, 0.5;
67 %ETAl, 1, 0, 10, normal_pdf, 0.25, 0.0.1;
68 ETAc, 1.8, 0, 10, normal_pdf, 1.80, 0.5;
69 ALFA, 0.65, 0, 1, normal_pdf, 0.60, 0.5;
70 RHOA, 0.95, 0, 1, normal_pdf, 0.90, 0.5;
71 stderr u_a, 0.01, 0, 1, normal_pdf, 0.01, 0.5;
72 %THETA, 3.48, 0, 10, normal_pdf, 0.25, 0.0.1;
73 end;
74 @#endif
75
76 % Simulate data
77 %stoch_simul(order=@{orderApp},pruning,nodisplay,nomoments,periods=500);
78 %save('RBC_MoM_data_@{orderApp}.mat', options_.varobs{:} );
79 %pause(1);
80
81
82 estimated_params_init(use_calibration);
83 end;
84
85
86 %--------------------------------------------------------------------------
87 % Method of Moments Estimation
88 %--------------------------------------------------------------------------
89 matched_moments;
90 c;
91 n;
92 iv;
93 c*c;
94 c*iv;
95 iv*n;
96 iv*iv;
97 n*c;
98 n*n;
99 c*c(-1);
100 n*n(-1);
101 iv*iv(-1);
102
103 c*c(-3);
104 n*n(-3);
105 iv*iv(-3);
106
107 c*c(-5);
108 n*n(-5);
109 iv*iv(-5);
110 end;
111
112 % get indices in declaration order
113 ic = strmatch('c', M_.endo_names,'exact');
114 iiv = strmatch('iv', M_.endo_names,'exact');
115 in = strmatch('n', M_.endo_names,'exact');
116 % first entry: number of variable in declaration order
117 % second entry: lag
118 % third entry: power
119
120 matched_moments_ = {
121 [ic ] [0 ], [1 ];
122 [in ] [0 ], [1 ];
123 [iiv ] [0 ], [1 ];
124
125 [ic ic ] [0 0], [1 1];
126 [ic iiv] [0 0], [1 1];
127 %[ic in ] [0 0], [1 1];
128 %[iiv ic ] [0 0], [1 1];
129 [in iiv] [0 0], [1 1];
130 [iiv iiv] [0 0], [1 1];
131 [ic in] [0 0], [1 1];
132 %[in iiv] [0 0], [1 1];
133 [in in ] [0 0], [1 1];
134
135 [ic ic ] [0 -1], [1 1];
136 [in in ] [0 -1], [1 1];
137 [iiv iiv] [0 -1], [1 1];
138
139 [ic ic ] [0 -3], [1 1];
140 [in in ] [0 -3], [1 1];
141 [iiv iiv] [0 -3], [1 1];
142
143 [ic ic ] [0 -5], [1 1];
144 [in in ] [0 -5], [1 1];
145 [iiv iiv] [0 -5], [1 1];
146
147 };
148
149 if ~isequal(M_.matched_moments,matched_moments_)
150 error('Translation to matched_moments-block failed')
151 end
152
153
154 method_of_moments(
155 % Necessary options
156 mom_method = GMM % method of moments method; possible values: GMM|SMM
157 , datafile = 'RBC_Andreasen_Data_2.mat' % name of filename with data
158
159 % Options for both GMM and SMM
160 % , bartlett_kernel_lag = 20 % bandwith in optimal weighting matrix
161 , order = @{orderApp} % order of Taylor approximation in perturbation
162 % , penalized_estimator % include deviation from prior mean as additional moment restriction and use prior precision as weight
163 % , pruning % use pruned state space system at higher-order
164 % , verbose % display and store intermediate estimation results
165 , weighting_matrix = ['DIAGONAL','OPTIMAL'] % weighting matrix in moments distance objective function; possible values: OPTIMAL|IDENTITY_MATRIX|DIAGONAL|filename. Size of cell determines stages in iterated estimation, e.g. two state with ['DIAGONAL','OPTIMAL']
166 % , weighting_matrix_scaling_factor=1 % scaling of weighting matrix in objective function
167 , se_tolx=1e-6 % step size for numerical computation of standard errors
168
169 % Options for SMM
170 % , burnin=500 % number of periods dropped at beginning of simulation
171 % , bounded_shock_support % trim shocks in simulation to +- 2 stdev
172 % , seed = 24051986 % seed used in simulations
173 % , simulation_multiple = 5 % multiple of the data length used for simulation
174
175 % Options for GMM
176 % , analytic_standard_errors % compute standard errors using analytical derivatives
177
178 % General options
179 % , dirname = 'MM' % directory in which to store estimation output
180 % , graph_format = EPS % specify the file format(s) for graphs saved to disk
181 % , nodisplay % do not display the graphs, but still save them to disk
182 % , nograph % do not create graphs (which implies that they are not saved to the disk nor displayed)
183 % , noprint % do not print stuff to console
184 % , plot_priors = 1 % control plotting of priors
185 % , prior_trunc = 1e-10 % probability of extreme values of the prior density that is ignored when computing bounds for the parameters
186 , TeX % print TeX tables and graphics
187
188 % Data and model options
189 % , first_obs = 501 % number of first observation
190 % , logdata % if data is already in logs
191 % , nobs = 250 % number of observations
192 % , prefilter=0 % demean each data series by its empirical mean and use centered moments
193 % , xls_sheet = data % name/number of sheet with data in Excel
194 % , xls_range = B2:D200 % range of data in Excel sheet
195
196 % Optimization options that can be set by the user in the mod file, otherwise default values are provided
197 % , huge_number=1e7 % value for replacing the infinite bounds on parameters by finite numbers. Used by some optimizers for numerical reasons
198 , mode_compute = 3 % specifies the optimizer for minimization of moments distance
199 , additional_optimizer_steps = [13] % vector of additional mode-finders run after mode_compute
200 % optim: a list of NAME and VALUE pairs to set options for the optimization routines. Available options depend on mode_compute, some exemplary common options:
201 , optim = ('TolFun' , 1D-6 % termination tolerance on the function value, a positive scalar
202 ,'TolX' , 1e-6 % termination tolerance on x, a positive scalar
203 % ,'MaxIter' , 3000 % maximum number of iterations allowed, a positive integer
204 % ,'MaxFunEvals' , 1D6 % maximum number of function evaluations allowed, a positive integer
205 % ,'UseParallel' , 1 % when true (and supported by optimizer) solver estimates gradients in parallel (using Matlab/Octave's parallel toolbox)
206 % ,'Jacobian' , 'off' % when 'off' gradient-based solvers approximate Jacobian using finite differences; for GMM we can also pass the analytical Jacobian to gradient-based solvers by setting this 'on'
207 )
208 , silent_optimizer % run minimization of moments distance silently without displaying results or saving files in between
209
210 % Numerical algorithms options
211 % , k_order_solver % use k_order_solver in higher order perturbation approximations
212 % , dr=default % method used to compute the decision rule; possible values are DEFAULT, CYCLE_REDUCTION, LOGARITHMIC_REDUCTION, AIM
213 % , dr_cycle_reduction_tol = 1e-7 % convergence criterion used in the cycle reduction algorithm
214 % , dr_logarithmic_reduction_tol = 1e-12 % convergence criterion used in the logarithmic reduction algorithm
215 % , dr_logarithmic_reduction_maxiter = 100 % maximum number of iterations used in the logarithmic reduction algorithm
216 % , lyapunov = DEFAULT % algorithm used to solve lyapunov equations; possible values are DEFAULT, FIXED_POINT, DOUBLING, SQUARE_ROOT_SOLVER
217 % , lyapunov_complex_threshold = 1e-15 % complex block threshold for the upper triangular matrix in symmetric Lyapunov equation solver
218 % , lyapunov_fixed_point_tol = 1e-10 % convergence criterion used in the fixed point Lyapunov solver
219 % , lyapunov_doubling_tol = 1e-16 % convergence criterion used in the doubling algorithm
220 % , qz_criterium = 0.999999 % value used to split stable from unstable eigenvalues in reordering the Generalized Schur decomposition used for solving first order problems
221 % , qz_zero_threshold = 1e-6 % value used to test if a generalized eigenvalue is 0/0 in the generalized Schur decomposition
222 % , schur_vec_tol=1e-11 % tolerance level used to find nonstationary variables in Schur decomposition of the transition matrix
223 , mode_check % plot the target function for values around the computed minimum for each estimated parameter in turn
224 % , mode_check_neighbourhood_size = 5 % width of the window (expressed in percentage deviation) around the computed minimum to be displayed on the diagnostic plots
225 % , mode_check_symmetric_plots=1 % ensure that the check plots are symmetric around the minimum
226 % , mode_check_number_of_points = 20 % number of points around the minimum where the target function is evaluated (for each parameter)
227 );