From e1d0ce28d2870160e22067ccd96ea42c72bb08f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Thu, 13 Jan 2022 19:09:18 +0100 Subject: [PATCH] Remove aux variables from evaluate routine. Auxiliary variables were still present in the growth neutrality correction. This commit remove the auxiliaries, so that the user doesn't need to update the database with the auxiliary variable definitions. Also adds integration test. TODO Check that it works with log unary op TODO Complete tests by checking that the written evaluate routine works --- matlab/print_expectations.m | 71 +++++++++++------- matlab/rewrite_aux_variable.m | 47 ++++++++++++ tests/Makefile.am | 4 + tests/pac/var-12/example1.mod | 74 +++++++++++++++++++ .../pac-expectations/pacman-expression.inc | 5 ++ .../pacman-growth-neutrality-correction.inc | 2 + .../pac-expectations/pacman-parameters.inc | 18 +++++ tests/pac/var-12/example11.mod | 55 ++++++++++++++ .../pac-expectations/pacman-expression.inc | 5 ++ .../pacman-growth-neutrality-correction.inc | 2 + .../pac-expectations/pacman-parameters.inc | 13 ++++ tests/pac/var-12/example12.mod | 56 ++++++++++++++ .../pac-expectations/pacman-expression.inc | 5 ++ .../pacman-growth-neutrality-correction.inc | 2 + .../pac-expectations/pacman-parameters.inc | 13 ++++ tests/pac/var-12/example13.mod | 55 ++++++++++++++ tests/pac/var-12/example2.mod | 74 +++++++++++++++++++ .../pac-expectations/pacman-expression.inc | 5 ++ .../pacman-growth-neutrality-correction.inc | 2 + .../pac-expectations/pacman-parameters.inc | 18 +++++ tests/pac/var-12/example3.mod | 68 +++++++++++++++++ 21 files changed, 568 insertions(+), 26 deletions(-) create mode 100644 matlab/rewrite_aux_variable.m create mode 100644 tests/pac/var-12/example1.mod create mode 100644 tests/pac/var-12/example1/model/pac-expectations/pacman-expression.inc create mode 100644 tests/pac/var-12/example1/model/pac-expectations/pacman-growth-neutrality-correction.inc create mode 100644 tests/pac/var-12/example1/model/pac-expectations/pacman-parameters.inc create mode 100644 tests/pac/var-12/example11.mod create mode 100644 tests/pac/var-12/example11/model/pac-expectations/pacman-expression.inc create mode 100644 tests/pac/var-12/example11/model/pac-expectations/pacman-growth-neutrality-correction.inc create mode 100644 tests/pac/var-12/example11/model/pac-expectations/pacman-parameters.inc create mode 100644 tests/pac/var-12/example12.mod create mode 100644 tests/pac/var-12/example12/model/pac-expectations/pacman-expression.inc create mode 100644 tests/pac/var-12/example12/model/pac-expectations/pacman-growth-neutrality-correction.inc create mode 100644 tests/pac/var-12/example12/model/pac-expectations/pacman-parameters.inc create mode 100644 tests/pac/var-12/example13.mod create mode 100644 tests/pac/var-12/example2.mod create mode 100644 tests/pac/var-12/example2/model/pac-expectations/pacman-expression.inc create mode 100644 tests/pac/var-12/example2/model/pac-expectations/pacman-growth-neutrality-correction.inc create mode 100644 tests/pac/var-12/example2/model/pac-expectations/pacman-parameters.inc create mode 100644 tests/pac/var-12/example3.mod diff --git a/matlab/print_expectations.m b/matlab/print_expectations.m index e32ba2d84..89be53633 100644 --- a/matlab/print_expectations.m +++ b/matlab/print_expectations.m @@ -299,23 +299,7 @@ for i=1:maxlag for j=1:length(auxmodel.list_of_variables_in_companion_var) id = id+1; variable = auxmodel.list_of_variables_in_companion_var{j}; - transformations = {}; - ida = get_aux_variable_id(variable); - op = 0; - while ida - op = op+1; - if isequal(M_.aux_vars(ida).type, 8) - transformations(op) = {'diff'}; - variable = M_.endo_names{M_.aux_vars(ida).orig_index}; - ida = get_aux_variable_id(variable); - elseif isequal(M_.aux_vars(ida).type, 10) - transformations(op) = {M_.aux_vars(ida).unary_op}; - variable = M_.endo_names{M_.aux_vars(ida).orig_index}; - ida = get_aux_variable_id(variable); - else - error('This case is not implemented.') - end - end + [variable, transformations] = rewrite_aux_variable(variable, M_); switch expectationmodelkind case 'var' parameter = M_.params(expectationmodel.param_indices(id)); @@ -378,13 +362,31 @@ if isequal(expectationmodelkind, 'pac') && growth_correction for iter = 1:numel(expectationmodel.growth_linear_comb) vgrowth=''; if expectationmodel.growth_linear_comb(iter).exo_id > 0 - vgrowth = strcat('dbase.', M_.exo_names{expectationmodel.growth_linear_comb(iter).exo_id}); + variable = M_.exo_names{expectationmodel.growth_linear_comb(iter).exo_id}; elseif expectationmodel.growth_linear_comb(iter).endo_id > 0 - vgrowth = strcat('dbase.', M_.endo_names{expectationmodel.growth_linear_comb(iter).endo_id}); + variable = M_.endo_names{expectationmodel.growth_linear_comb(iter).endo_id}; end - if expectationmodel.growth_linear_comb(iter).lag ~= 0 - vgrowth = sprintf('%s(%d)', vgrowth, expectationmodel.growth_linear_comb(iter).lag); + [variable, transformations] = rewrite_aux_variable(variable, M_); + if isempty(transformations) + if expectationmodel.growth_linear_comb(iter).lag ~= 0 + variable = sprintf('%s(%d)', variable, expectationmodel.growth_linear_comb(iter).lag); + end + else + for k=rows(transformations):-1:1 + if isequal(transformations{k,1}, 'lag') + variable = sprintf('%s.lag(%u)', variable, -transformations{k,2}); + elseif isequal(transformations{k,1}, 'diff') + if isempty(transformations{k,2}) + variable = sprintf('%s.%s()', variable, transformations{k,1}); + else + variable = sprintf('%s(-%u).%s()', variable, transformations{k,2}, transformations{k,1}); + end + else + variable = sprintf('%s.%s()', variable, transformations{k}); + end + end end + vgrowth = strcat('dbase.', variable); if expectationmodel.growth_linear_comb(iter).param_id > 0 if ~isempty(vgrowth) vgrowth = sprintf('%1.16f*%s',M_.params(expectationmodel.growth_linear_comb(iter).param_id), vgrowth); @@ -418,14 +420,31 @@ if isequal(expectationmodelkind, 'pac') && growth_correction for iter = 1:numel(expectationmodel.components(i).growth_linear_comb) vgrowth=''; if expectationmodel.components(i).growth_linear_comb(iter).exo_id > 0 - vgrowth = strcat('dbase.', M_.exo_names{expectationmodel.components(i).growth_linear_comb(iter).exo_id}); + variable = M_.exo_names{expectationmodel.components(i).growth_linear_comb(iter).exo_id}; elseif expectationmodel.components(i).growth_linear_comb(iter).endo_id > 0 - vgrowth = strcat('dbase.', M_.endo_names{expectationmodel.components(i).growth_linear_comb(iter).endo_id}); - % TODO Check if we should not substitute auxiliary variables with original transformed variables here. + variable = M_.endo_names{expectationmodel.components(i).growth_linear_comb(iter).endo_id}; end - if expectationmodel.components(i).growth_linear_comb(iter).lag ~= 0 - vgrowth = sprintf('%s(%d)', vgrowth, expectationmodel.components(i).growth_linear_comb(iter).lag); + [variable, transformations] = rewrite_aux_variable(variable, M_); + if isempty(transformations) + if expectationmodel.components(i).growth_linear_comb(iter).lag ~= 0 + variable = sprintf('%s(%d)', variable, expectationmodel.components(i).growth_linear_comb(iter).lag); + end + else + for k=rows(transformations):-1:1 + if isequal(transformations{k,1}, 'lag') + variable = sprintf('%s.lag(%u)', variable, -transformations{k,2}); + elseif isequal(transformations{k,1}, 'diff') + if isempty(transformations{k,2}) + variable = sprintf('%s.%s()', variable, transformations{k,1}); + else + variable = sprintf('%s(-%u).%s()', variable, transformations{k,2}, transformations{k,1}); + end + else + variable = sprintf('%s.%s()', variable, transformations{k}); + end + end end + vgrowth = strcat('dbase.', variable); if expectationmodel.components(i).growth_linear_comb(iter).param_id > 0 if ~isempty(vgrowth) vgrowth = sprintf('%1.16f*%s',M_.params(expectationmodel.components(i).growth_linear_comb(iter).param_id), vgrowth); diff --git a/matlab/rewrite_aux_variable.m b/matlab/rewrite_aux_variable.m new file mode 100644 index 000000000..f49bd1183 --- /dev/null +++ b/matlab/rewrite_aux_variable.m @@ -0,0 +1,47 @@ +function [variable, transformations] = rewrite_aux_variable(variable, M_) + +% Copyright © 2021 Dynare Team +% +% This file is part of Dynare. +% +% Dynare is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% Dynare is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with Dynare. If not, see . + +transformations = {}; +ida = get_aux_variable_id(variable); +op = 0; +dl = 0; + +while ida + op = op+1; + if isequal(M_.aux_vars(ida).type, 1) + transformations(op,1) = {'lag'}; + transformations(op,2) = {M_.aux_vars(ida).orig_lead_lag-1}; + variable = M_.endo_names{M_.aux_vars(ida).orig_index}; + elseif isequal(M_.aux_vars(ida).type, 8) + transformations(op, 1) = {'diff'}; + variable = M_.endo_names{M_.aux_vars(ida).orig_index}; + elseif isequal(M_.aux_vars(ida).type, 9) + dl = dl+1; + transformations(op, 1) = {'lag'}; + transformations(op, 2) = {dl}; + op = op-1; + variable = M_.endo_names{M_.aux_vars(ida).orig_index}; + elseif isequal(M_.aux_vars(ida).type, 10) + transformations(op, 1) = {M_.aux_vars(ida).unary_op}; + variable = M_.endo_names{M_.aux_vars(ida).orig_index}; + else + error('This case is not implemented.') + end + ida = get_aux_variable_id(variable); +end \ No newline at end of file diff --git a/tests/Makefile.am b/tests/Makefile.am index 783cb4c90..8d007ff13 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -529,6 +529,10 @@ ECB_MODFILES = \ pac/var-10e/example1.mod \ pac/var-10e/example2.mod \ pac/var-11e/example1.mod \ + pac/var-12/example1.mod \ + pac/var-12/example2.mod \ + pac/var-12/example11.mod \ + pac/var-12/example12.mod \ pac/trend-component-1/example1.mod \ pac/trend-component-2/example1.mod \ pac/trend-component-3/example1.mod \ diff --git a/tests/pac/var-12/example1.mod b/tests/pac/var-12/example1.mod new file mode 100644 index 000000000..0cb734f26 --- /dev/null +++ b/tests/pac/var-12/example1.mod @@ -0,0 +1,74 @@ +// --+ options: json=compute, stochastic +-- + +var y x z v; + +varexo ex ey ez ; + +parameters a_y_1 a_y_2 b_y_1 b_y_2 b_x_1 b_x_2 d_y; // VAR parameters + +parameters beta e_c_m c_z_1 c_z_2; // PAC equation parameters + +a_y_1 = .2; +a_y_2 = .3; +b_y_1 = .1; +b_y_2 = .4; +b_x_1 = -.1; +b_x_2 = -.2; +d_y = .5; + + +beta = .9; +e_c_m = .1; +c_z_1 = .7; +c_z_2 = -.3; + +var_model(model_name=toto, structural, eqtags=['eq:x', 'eq:y']); + +pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman); + +pac_target_info(pacman); + target v; + auxname_target_nonstationary vns; + + component y; + auxname pv_y_; + kind ll; + + component x; + growth diff(x(-2)); + auxname pv_dx_; + kind dd; + +end; + +model; + + [name='eq:y'] + y = a_y_1*y(-1) + a_y_2*diff(x(-1)) + b_y_1*y(-2) + b_y_2*diff(x(-2)) + ey ; + + + [name='eq:x'] + diff(x) = b_x_1*y(-2) + b_x_2*diff(x(-1)) + ex ; + + [name='eq:v'] + v = x + d_y*y ; + + [name='eq:pac'] + diff(z) = e_c_m*(pac_target_nonstationary(pacman)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez; + +end; + +shocks; + var ex = 1.0; + var ey = 1.0; + var ez = 1.0; +end; + +// Initialize the PAC model (build the Companion VAR representation for the auxiliary model). +pac.initialize('pacman'); + +// Update the parameters of the PAC expectation model (h0 and h1 vectors). +pac.update.expectation('pacman'); + +// Print expanded PAC_EXPECTATION term. +pac.print('pacman', 'eq:pac'); diff --git a/tests/pac/var-12/example1/model/pac-expectations/pacman-expression.inc b/tests/pac/var-12/example1/model/pac-expectations/pacman-expression.inc new file mode 100644 index 000000000..989a0b1c4 --- /dev/null +++ b/tests/pac/var-12/example1/model/pac-expectations/pacman-expression.inc @@ -0,0 +1,5 @@ +// This file has been generated by dynare (14-Jan-2022 17:56:36). +d_y*h_pacman_component1_constant+h_pacman_component2_constant + (d_y*h_pacman_component1_var_AUX_DIFF_11_lag_1+h_pacman_component2_var_AUX_DIFF_11_lag_1)*diff(x(-1)) + + (d_y*h_pacman_component1_var_y_lag_1+h_pacman_component2_var_y_lag_1)*y(-1) + + (d_y*h_pacman_component1_var_AUX_DIFF_11_lag_2+h_pacman_component2_var_AUX_DIFF_11_lag_2)*diff(x(-2)) + + (d_y*h_pacman_component1_var_y_lag_2+h_pacman_component2_var_y_lag_2)*y(-2) diff --git a/tests/pac/var-12/example1/model/pac-expectations/pacman-growth-neutrality-correction.inc b/tests/pac/var-12/example1/model/pac-expectations/pacman-growth-neutrality-correction.inc new file mode 100644 index 000000000..a84abb44e --- /dev/null +++ b/tests/pac/var-12/example1/model/pac-expectations/pacman-growth-neutrality-correction.inc @@ -0,0 +1,2 @@ +// This file has been generated by dynare (14-Jan-2022 17:56:36). +pacman_component2_pac_growth_neutrality_correction*diff(x(-2)) \ No newline at end of file diff --git a/tests/pac/var-12/example1/model/pac-expectations/pacman-parameters.inc b/tests/pac/var-12/example1/model/pac-expectations/pacman-parameters.inc new file mode 100644 index 000000000..3b1d44338 --- /dev/null +++ b/tests/pac/var-12/example1/model/pac-expectations/pacman-parameters.inc @@ -0,0 +1,18 @@ +// This file has been generated by dynare (14-Jan-2022 17:56:36). + +parameters h_pacman_component1_constant h_pacman_component1_var_AUX_DIFF_11_lag_1 h_pacman_component1_var_y_lag_1 h_pacman_component1_var_AUX_DIFF_11_lag_2 h_pacman_component1_var_y_lag_2 h_pacman_component2_constant h_pacman_component2_var_AUX_DIFF_11_lag_1 h_pacman_component2_var_y_lag_1 h_pacman_component2_var_AUX_DIFF_11_lag_2 h_pacman_component2_var_y_lag_2; + +h_pacman_component1_constant = 0.0000000000000000; +h_pacman_component1_var_AUX_DIFF_11_lag_1 = 0.0145990564819670; +h_pacman_component1_var_y_lag_1 = 0.0060141756634789; +h_pacman_component1_var_AUX_DIFF_11_lag_2 = 0.0088556033620678; +h_pacman_component1_var_y_lag_2 = 0.0007072909429702; +h_pacman_component2_constant = 0.0000000000000000; +h_pacman_component2_var_AUX_DIFF_11_lag_1 = -0.0204386323060280; +h_pacman_component2_var_y_lag_1 = -0.0090103235508248; +h_pacman_component2_var_AUX_DIFF_11_lag_2 = -0.0026679701308692; +h_pacman_component2_var_y_lag_2 = -0.0089540800364464; + +parameters pacman_component2_pac_growth_neutrality_correction; + +pacman_component2_pac_growth_neutrality_correction = 0.1853271645736974; diff --git a/tests/pac/var-12/example11.mod b/tests/pac/var-12/example11.mod new file mode 100644 index 000000000..68f3a88f3 --- /dev/null +++ b/tests/pac/var-12/example11.mod @@ -0,0 +1,55 @@ +// --+ options: json=compute, stochastic +-- + +var y x z; + +varexo ex ey ez ; + +parameters a_y_1 a_y_2 b_y_1 b_y_2 b_x_1 b_x_2 d_y; // VAR parameters + +parameters beta e_c_m c_z_1 c_z_2; // PAC equation parameters + +a_y_1 = .2; +a_y_2 = .3; +b_y_1 = .1; +b_y_2 = .4; +b_x_1 = -.1; +b_x_2 = -.2; +d_y = .5; + +beta = .9; +e_c_m = .1; +c_z_1 = .7; +c_z_2 = -.3; + +var_model(model_name=toto, structural, eqtags=['eq:x', 'eq:y']); + +pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman, growth=diff(x(-2))); + +model; + + [name='eq:y'] + y = a_y_1*y(-1) + a_y_2*diff(x(-1)) + b_y_1*y(-2) + b_y_2*diff(x(-2)) + ey ; + + + [name='eq:x'] + diff(x) = b_x_1*y(-2) + b_x_2*diff(x(-1)) + ex ; + + [name='eq:pac'] + diff(z) = e_c_m*(x(-1)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez; + +end; + +shocks; + var ex = 1.0; + var ey = 1.0; + var ez = 1.0; +end; + +// Initialize the PAC model (build the Companion VAR representation for the auxiliary model). +pac.initialize('pacman'); + +// Update the parameters of the PAC expectation model (h0 and h1 vectors). +pac.update.expectation('pacman'); + +// Print expanded PAC_EXPECTATION term. +pac.print('pacman', 'eq:pac'); diff --git a/tests/pac/var-12/example11/model/pac-expectations/pacman-expression.inc b/tests/pac/var-12/example11/model/pac-expectations/pacman-expression.inc new file mode 100644 index 000000000..cb2035408 --- /dev/null +++ b/tests/pac/var-12/example11/model/pac-expectations/pacman-expression.inc @@ -0,0 +1,5 @@ +// This file has been generated by dynare (14-Jan-2022 19:06:42). +h_pacman_constant + h_pacman_var_AUX_DIFF_31_lag_1*diff(x(-1)) + + h_pacman_var_y_lag_1*y(-1) + + h_pacman_var_AUX_DIFF_31_lag_2*diff(x(-2)) + + h_pacman_var_y_lag_2*y(-2) diff --git a/tests/pac/var-12/example11/model/pac-expectations/pacman-growth-neutrality-correction.inc b/tests/pac/var-12/example11/model/pac-expectations/pacman-growth-neutrality-correction.inc new file mode 100644 index 000000000..fadba9b29 --- /dev/null +++ b/tests/pac/var-12/example11/model/pac-expectations/pacman-growth-neutrality-correction.inc @@ -0,0 +1,2 @@ +// This file has been generated by dynare (14-Jan-2022 19:06:42). +pacman_pac_growth_neutrality_correction*diff(x(-2)) \ No newline at end of file diff --git a/tests/pac/var-12/example11/model/pac-expectations/pacman-parameters.inc b/tests/pac/var-12/example11/model/pac-expectations/pacman-parameters.inc new file mode 100644 index 000000000..ce7144a0b --- /dev/null +++ b/tests/pac/var-12/example11/model/pac-expectations/pacman-parameters.inc @@ -0,0 +1,13 @@ +// This file has been generated by dynare (14-Jan-2022 19:06:42). + +parameters h_pacman_constant h_pacman_var_AUX_DIFF_31_lag_1 h_pacman_var_y_lag_1 h_pacman_var_AUX_DIFF_31_lag_2 h_pacman_var_y_lag_2; + +h_pacman_constant = 0.0000000000000000; +h_pacman_var_AUX_DIFF_31_lag_1 = -0.0204386323060280; +h_pacman_var_y_lag_1 = -0.0090103235508248; +h_pacman_var_AUX_DIFF_31_lag_2 = -0.0026679701308692; +h_pacman_var_y_lag_2 = -0.0089540800364464; + +parameters pacman_pac_growth_neutrality_correction; + +pacman_pac_growth_neutrality_correction = 0.1853271645736974; diff --git a/tests/pac/var-12/example12.mod b/tests/pac/var-12/example12.mod new file mode 100644 index 000000000..9685ef6ee --- /dev/null +++ b/tests/pac/var-12/example12.mod @@ -0,0 +1,56 @@ +// --+ options: json=compute, stochastic +-- + +var y x z; + +varexo ex ey ez ; + +parameters a_y_1 a_y_2 b_y_1 b_y_2 b_x_1 b_x_2 d_y; // VAR parameters + +parameters beta e_c_m c_z_1 c_z_2; // PAC equation parameters + +a_y_1 = .2; +a_y_2 = .3; +b_y_1 = .1; +b_y_2 = .4; +b_x_1 = -.1; +b_x_2 = -.2; +d_y = .5; + + +beta = .9; +e_c_m = .1; +c_z_1 = .7; +c_z_2 = -.3; + +var_model(model_name=toto, structural, eqtags=['eq:x', 'eq:y']); + +pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman, growth=x(-2)); + +model; + + [name='eq:y'] + y = a_y_1*y(-1) + a_y_2*diff(x(-1)) + b_y_1*y(-2) + b_y_2*diff(x(-2)) + ey ; + + + [name='eq:x'] + diff(x) = b_x_1*y(-2) + b_x_2*diff(x(-1)) + ex ; + + [name='eq:pac'] + diff(z) = e_c_m*(x(-1)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez; + +end; + +shocks; + var ex = 1.0; + var ey = 1.0; + var ez = 1.0; +end; + +// Initialize the PAC model (build the Companion VAR representation for the auxiliary model). +pac.initialize('pacman'); + +// Update the parameters of the PAC expectation model (h0 and h1 vectors). +pac.update.expectation('pacman'); + +// Print expanded PAC_EXPECTATION term. +pac.print('pacman', 'eq:pac'); diff --git a/tests/pac/var-12/example12/model/pac-expectations/pacman-expression.inc b/tests/pac/var-12/example12/model/pac-expectations/pacman-expression.inc new file mode 100644 index 000000000..6cf6c9953 --- /dev/null +++ b/tests/pac/var-12/example12/model/pac-expectations/pacman-expression.inc @@ -0,0 +1,5 @@ +// This file has been generated by dynare (14-Jan-2022 19:11:08). +h_pacman_constant + h_pacman_var_AUX_DIFF_31_lag_1*diff(x(-1)) + + h_pacman_var_y_lag_1*y(-1) + + h_pacman_var_AUX_DIFF_31_lag_2*diff(x(-2)) + + h_pacman_var_y_lag_2*y(-2) diff --git a/tests/pac/var-12/example12/model/pac-expectations/pacman-growth-neutrality-correction.inc b/tests/pac/var-12/example12/model/pac-expectations/pacman-growth-neutrality-correction.inc new file mode 100644 index 000000000..a075d9045 --- /dev/null +++ b/tests/pac/var-12/example12/model/pac-expectations/pacman-growth-neutrality-correction.inc @@ -0,0 +1,2 @@ +// This file has been generated by dynare (14-Jan-2022 19:11:08). +pacman_pac_growth_neutrality_correction*x(-2) \ No newline at end of file diff --git a/tests/pac/var-12/example12/model/pac-expectations/pacman-parameters.inc b/tests/pac/var-12/example12/model/pac-expectations/pacman-parameters.inc new file mode 100644 index 000000000..9e0f5c4f5 --- /dev/null +++ b/tests/pac/var-12/example12/model/pac-expectations/pacman-parameters.inc @@ -0,0 +1,13 @@ +// This file has been generated by dynare (14-Jan-2022 19:11:08). + +parameters h_pacman_constant h_pacman_var_AUX_DIFF_31_lag_1 h_pacman_var_y_lag_1 h_pacman_var_AUX_DIFF_31_lag_2 h_pacman_var_y_lag_2; + +h_pacman_constant = 0.0000000000000000; +h_pacman_var_AUX_DIFF_31_lag_1 = -0.0204386323060280; +h_pacman_var_y_lag_1 = -0.0090103235508248; +h_pacman_var_AUX_DIFF_31_lag_2 = -0.0026679701308692; +h_pacman_var_y_lag_2 = -0.0089540800364464; + +parameters pacman_pac_growth_neutrality_correction; + +pacman_pac_growth_neutrality_correction = 0.1853271645736974; diff --git a/tests/pac/var-12/example13.mod b/tests/pac/var-12/example13.mod new file mode 100644 index 000000000..ff888b852 --- /dev/null +++ b/tests/pac/var-12/example13.mod @@ -0,0 +1,55 @@ +// --+ options: json=compute, stochastic +-- + +var y x z; + +varexo ex ey ez ; + +parameters a_y_1 a_y_2 b_y_1 b_y_2 b_x_1 b_x_2 d_y; // VAR parameters + +parameters beta e_c_m c_z_1 c_z_2; // PAC equation parameters + +a_y_1 = .2; +a_y_2 = .3; +b_y_1 = .1; +b_y_2 = .4; +b_x_1 = -.1; +b_x_2 = -.2; +d_y = .5; + +beta = .9; +e_c_m = .1; +c_z_1 = .7; +c_z_2 = -.3; + +var_model(model_name=toto, structural, eqtags=['eq:x', 'eq:y']); + +pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman, growth=diff(log(x(-2)))); + +model; + + [name='eq:y'] + y = a_y_1*y(-1) + a_y_2*diff(log(x(-1))) + b_y_1*y(-2) + b_y_2*diff(log(x(-2))) + ey ; + + + [name='eq:x'] + diff(log(x)) = b_x_1*y(-2) + b_x_2*diff(log(x(-1))) + ex ; + + [name='eq:pac'] + diff(log(z)) = e_c_m*(log(x(-1))-log(z(-1))) + c_z_1*diff(log(z(-1))) + c_z_2*diff(log(z(-2))) + pac_expectation(pacman) + ez; + +end; + +shocks; + var ex = 1.0; + var ey = 1.0; + var ez = 1.0; +end; + +// Initialize the PAC model (build the Companion VAR representation for the auxiliary model). +pac.initialize('pacman'); + +// Update the parameters of the PAC expectation model (h0 and h1 vectors). +pac.update.expectation('pacman'); + +// Print expanded PAC_EXPECTATION term. +pac.print('pacman', 'eq:pac'); diff --git a/tests/pac/var-12/example2.mod b/tests/pac/var-12/example2.mod new file mode 100644 index 000000000..b1cdee083 --- /dev/null +++ b/tests/pac/var-12/example2.mod @@ -0,0 +1,74 @@ +// --+ options: json=compute, stochastic +-- + +var y x z v; + +varexo ex ey ez ; + +parameters a_y_1 a_y_2 b_y_1 b_y_2 b_x_1 b_x_2 d_y; // VAR parameters + +parameters beta e_c_m c_z_1 c_z_2; // PAC equation parameters + +a_y_1 = .2; +a_y_2 = .3; +b_y_1 = .1; +b_y_2 = .4; +b_x_1 = -.1; +b_x_2 = -.2; +d_y = .5; + + +beta = .9; +e_c_m = .1; +c_z_1 = .7; +c_z_2 = -.3; + +var_model(model_name=toto, structural, eqtags=['eq:x', 'eq:y']); + +pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman); + +pac_target_info(pacman); + target v; + auxname_target_nonstationary vns; + + component y; + auxname pv_y_; + kind ll; + + component x; + growth x(-2); + auxname pv_dx_; + kind dd; + +end; + +model; + + [name='eq:y'] + y = a_y_1*y(-1) + a_y_2*diff(x(-1)) + b_y_1*y(-2) + b_y_2*diff(x(-2)) + ey ; + + + [name='eq:x'] + diff(x) = b_x_1*y(-2) + b_x_2*diff(x(-1)) + ex ; + + [name='eq:v'] + v = x + d_y*y ; + + [name='eq:pac'] + diff(z) = e_c_m*(pac_target_nonstationary(pacman)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez; + +end; + +shocks; + var ex = 1.0; + var ey = 1.0; + var ez = 1.0; +end; + +// Initialize the PAC model (build the Companion VAR representation for the auxiliary model). +pac.initialize('pacman'); + +// Update the parameters of the PAC expectation model (h0 and h1 vectors). +pac.update.expectation('pacman'); + +// Print expanded PAC_EXPECTATION term. +pac.print('pacman', 'eq:pac'); diff --git a/tests/pac/var-12/example2/model/pac-expectations/pacman-expression.inc b/tests/pac/var-12/example2/model/pac-expectations/pacman-expression.inc new file mode 100644 index 000000000..cddbaf496 --- /dev/null +++ b/tests/pac/var-12/example2/model/pac-expectations/pacman-expression.inc @@ -0,0 +1,5 @@ +// This file has been generated by dynare (14-Jan-2022 17:58:52). +d_y*h_pacman_component1_constant+h_pacman_component2_constant + (d_y*h_pacman_component1_var_AUX_DIFF_11_lag_1+h_pacman_component2_var_AUX_DIFF_11_lag_1)*diff(x(-1)) + + (d_y*h_pacman_component1_var_y_lag_1+h_pacman_component2_var_y_lag_1)*y(-1) + + (d_y*h_pacman_component1_var_AUX_DIFF_11_lag_2+h_pacman_component2_var_AUX_DIFF_11_lag_2)*diff(x(-2)) + + (d_y*h_pacman_component1_var_y_lag_2+h_pacman_component2_var_y_lag_2)*y(-2) diff --git a/tests/pac/var-12/example2/model/pac-expectations/pacman-growth-neutrality-correction.inc b/tests/pac/var-12/example2/model/pac-expectations/pacman-growth-neutrality-correction.inc new file mode 100644 index 000000000..07d37629b --- /dev/null +++ b/tests/pac/var-12/example2/model/pac-expectations/pacman-growth-neutrality-correction.inc @@ -0,0 +1,2 @@ +// This file has been generated by dynare (14-Jan-2022 17:58:52). +pacman_component2_pac_growth_neutrality_correction*x(-2) \ No newline at end of file diff --git a/tests/pac/var-12/example2/model/pac-expectations/pacman-parameters.inc b/tests/pac/var-12/example2/model/pac-expectations/pacman-parameters.inc new file mode 100644 index 000000000..b7fd58248 --- /dev/null +++ b/tests/pac/var-12/example2/model/pac-expectations/pacman-parameters.inc @@ -0,0 +1,18 @@ +// This file has been generated by dynare (14-Jan-2022 17:58:52). + +parameters h_pacman_component1_constant h_pacman_component1_var_AUX_DIFF_11_lag_1 h_pacman_component1_var_y_lag_1 h_pacman_component1_var_AUX_DIFF_11_lag_2 h_pacman_component1_var_y_lag_2 h_pacman_component2_constant h_pacman_component2_var_AUX_DIFF_11_lag_1 h_pacman_component2_var_y_lag_1 h_pacman_component2_var_AUX_DIFF_11_lag_2 h_pacman_component2_var_y_lag_2; + +h_pacman_component1_constant = 0.0000000000000000; +h_pacman_component1_var_AUX_DIFF_11_lag_1 = 0.0145990564819670; +h_pacman_component1_var_y_lag_1 = 0.0060141756634789; +h_pacman_component1_var_AUX_DIFF_11_lag_2 = 0.0088556033620678; +h_pacman_component1_var_y_lag_2 = 0.0007072909429702; +h_pacman_component2_constant = 0.0000000000000000; +h_pacman_component2_var_AUX_DIFF_11_lag_1 = -0.0204386323060280; +h_pacman_component2_var_y_lag_1 = -0.0090103235508248; +h_pacman_component2_var_AUX_DIFF_11_lag_2 = -0.0026679701308692; +h_pacman_component2_var_y_lag_2 = -0.0089540800364464; + +parameters pacman_component2_pac_growth_neutrality_correction; + +pacman_component2_pac_growth_neutrality_correction = 0.1853271645736974; diff --git a/tests/pac/var-12/example3.mod b/tests/pac/var-12/example3.mod new file mode 100644 index 000000000..86e47683a --- /dev/null +++ b/tests/pac/var-12/example3.mod @@ -0,0 +1,68 @@ +// --+ options: json=compute, stochastic +-- + +var y x z v; + +varexo ex ey ez ; + +parameters a_y_1 a_y_2 b_y_1 b_y_2 b_x_1 b_x_2 d_y; // VAR parameters + +parameters beta e_c_m c_z_1 c_z_2; // PAC equation parameters + +a_y_1 = .2; +a_y_2 = .3; +b_y_1 = .1; +b_y_2 = .4; +b_x_1 = -.1; +b_x_2 = -.2; +d_y = .5; + + +beta = .9; +e_c_m = .1; +c_z_1 = .7; +c_z_2 = -.3; + +var_model(model_name=toto, structural, eqtags=['eq:x', 'eq:y']); + +pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman); + +pac_target_info(pacman); + target v; + auxname_target_nonstationary vns; + + component y; + auxname pv_y_; + kind ll; + + component log(x); + growth diff(log(x(-2))); + auxname pv_dx_; + kind dd; + +end; + +model; + + [name='eq:y'] + y = a_y_1*y(-1) + a_y_2*diff(log(x(-1))) + b_y_1*y(-2) + b_y_2*diff(log(x(-2))) + ey ; + + + [name='eq:x'] + diff(log(x)) = b_x_1*y(-2) + b_x_2*diff(log(x(-1))) + ex ; + + [name='eq:v'] + v = log(x) + d_y*y ; + + [name='eq:pac'] + diff(z) = e_c_m*(pac_target_nonstationary(pacman)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez; + +end; + +// Initialize the PAC model (build the Companion VAR representation for the auxiliary model). +pac.initialize('pacman'); + +// Update the parameters of the PAC expectation model (h0 and h1 vectors). +pac.update.expectation('pacman'); + +// Print expanded PAC_EXPECTATION term. +pac.print('pacman', 'eq:pac');