Debian Codegraph @

tests/estimation/method_of_moments/RBC/RBC_MoM_SMM_ME.mod

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