| 1 |
% Test whether gradient-based optimizers are able to use analytical |
| 2 |
% Jacobian of moments in GMM estimation |
| 3 |
% |
| 4 |
% Copyright © 2021 Dynare Team |
| 5 |
% |
| 6 |
% This file is part of Dynare. |
| 7 |
% |
| 8 |
% Dynare is free software: you can redistribute it and/or modify |
| 9 |
% it under the terms of the GNU General Public License as published by |
| 10 |
% the Free Software Foundation, either version 3 of the License, or |
| 11 |
% (at your option) any later version. |
| 12 |
% |
| 13 |
% Dynare is distributed in the hope that it will be useful, |
| 14 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
% GNU General Public License for more details. |
| 17 |
% |
| 18 |
% You should have received a copy of the GNU General Public License |
| 19 |
% along with Dynare. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
% ========================================================================= |
| 21 |
@#include "RBC_MoM_common.inc" |
| 22 |
|
| 23 |
shocks; |
| 24 |
var u_a; stderr 0.0072; |
| 25 |
end; |
| 26 |
|
| 27 |
varobs c iv n; |
| 28 |
|
| 29 |
%-------------------------------------------------------------------------- |
| 30 |
% Method of Moments Estimation |
| 31 |
%-------------------------------------------------------------------------- |
| 32 |
matched_moments; |
| 33 |
c; |
| 34 |
n; |
| 35 |
iv; |
| 36 |
c*c; |
| 37 |
c*iv; |
| 38 |
iv*n; |
| 39 |
iv*iv; |
| 40 |
n*c; |
| 41 |
n*n; |
| 42 |
c*c(-1); |
| 43 |
n*n(-1); |
| 44 |
iv*iv(-1); |
| 45 |
end; |
| 46 |
|
| 47 |
|
| 48 |
@#for estimParams in [0, 1, 2] |
| 49 |
@#if estimParams == 0 |
| 50 |
estimated_params(overwrite); |
| 51 |
%DELTA, 0.025; |
| 52 |
%BETTA, 0.984; |
| 53 |
%B, 0.5; |
| 54 |
%ETAc, 2; |
| 55 |
ALFA, 0.667; |
| 56 |
RHOA, 0.979; |
| 57 |
stderr u_a, 0.0072; |
| 58 |
end; |
| 59 |
@#endif |
| 60 |
|
| 61 |
@#if estimParams == 1 |
| 62 |
estimated_params(overwrite); |
| 63 |
%DELTA, , 0, 1; |
| 64 |
%BETTA, , 0, 1; |
| 65 |
%B, , 0, 1; |
| 66 |
%ETAc, , 0, 10; |
| 67 |
ALFA, , 0, 1; |
| 68 |
RHOA, , 0, 1; |
| 69 |
stderr u_a, , 0, 1; |
| 70 |
end; |
| 71 |
@#endif |
| 72 |
|
| 73 |
@#if estimParams == 2 |
| 74 |
estimated_params(overwrite); |
| 75 |
%DELTA, 0.025, 0, 1, normal_pdf, 0.02, 0.5; |
| 76 |
%BETTA, 0.98, 0, 1, beta_pdf, 0.90, 0.25; |
| 77 |
%B, 0.45, 0, 1, normal_pdf, 0.40, 0.5; |
| 78 |
%ETAl, 1, 0, 10, normal_pdf, 0.25, 0.0.1; |
| 79 |
%ETAc, 1.8, 0, 10, normal_pdf, 1.80, 0.5; |
| 80 |
ALFA, 0.65, 0, 1, normal_pdf, 0.60, 0.5; |
| 81 |
RHOA, 0.95, 0, 1, normal_pdf, 0.90, 0.5; |
| 82 |
stderr u_a, 0.01, 0, 1, normal_pdf, 0.01, 0.5; |
| 83 |
%THETA, 3.48, 0, 10, normal_pdf, 0.25, 0.0.1; |
| 84 |
end; |
| 85 |
@#endif |
| 86 |
|
| 87 |
estimated_params_init(use_calibration); |
| 88 |
end; |
| 89 |
|
| 90 |
@#for optimizer in [1, 3, 4, 101, 13] |
| 91 |
@#if estimParams == 2 && optimizer == 13 |
| 92 |
%skip due to buggy behavior in Octave |
| 93 |
if ~isoctave |
| 94 |
@#endif |
| 95 |
|
| 96 |
method_of_moments( |
| 97 |
mom_method = GMM % method of moments method; possible values: GMM|SMM |
| 98 |
, datafile = 'RBC_Andreasen_Data_2.mat' % name of filename with data |
| 99 |
, order = 2 % order of Taylor approximation in perturbation |
| 100 |
, weighting_matrix = ['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'] |
| 101 |
, nodisplay |
| 102 |
, nograph |
| 103 |
, mode_compute = @{optimizer} % specifies the optimizer for minimization of moments distance |
| 104 |
%, additional_optimizer_steps = [1 3 13] |
| 105 |
% , optim = ('DerivativeCheck', 'on','FiniteDifferenceType','central' |
| 106 |
% ,'TolX', 1e-6 |
| 107 |
% ,'MaxIter', 3000 |
| 108 |
% ,'MaxFunEvals', 1D6 |
| 109 |
% ,'UseParallel' , 1 |
| 110 |
% ,'Jacobian' , 'on' |
| 111 |
% ,'GradObj','on' |
| 112 |
% ) % a list of NAME and VALUE pairs to set options for the optimization routines. Available options depend on mode_compute |
| 113 |
, silent_optimizer % run minimization of moments distance silently without displaying results or saving files in between |
| 114 |
, analytic_jacobian |
| 115 |
); |
| 116 |
|
| 117 |
@#if estimParams == 2 && optimizer == 13 |
| 118 |
%skip due to buggy behavior in Octave |
| 119 |
end |
| 120 |
@#endif |
| 121 |
@#endfor |
| 122 |
|
| 123 |
@#endfor |