Added PAC with Model Consistent Expectations.

time-shift
Stéphane Adjemian (Charybdis) 2019-02-25 17:30:28 +01:00
parent ac09ab9dbf
commit 1aa7f4a93f
Signed by untrusted user who does not match committer: stepan
GPG Key ID: A6D44CB9C64CE77B
8 changed files with 243 additions and 8 deletions

View File

@ -0,0 +1,76 @@
function parameters(pacname)
% Updates the parameters of a PAC Model Consistent Expectations.
%
% INPUTS
% - pacname [string] Name of the pac equation.
%
% OUTPUTS
% - none
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
global M_
% Check that the first input is a row character array.
if ~isrow(pacname)==1 || ~ischar(pacname)
error('Input argument must be a row character array!')
end
% Check the name of the PAC model.
if ~isfield(M_.pac, pacname)
error('PAC model %s is not defined in the model block!', pacname)
end
% Get PAC model description
pacmodel = M_.pac.(pacname);
% Check that we are dealing with PAC/MCE
if ~pacmodel.model_consistent_expectations
error('This function is to be used only for PAC Model Consistent Expectations.')
end
% Show the equations where this PAC model is used.
number_of_pac_eq = size(pacmodel.tag_map, 1);
if number_of_pac_eq==1
fprintf('PAC model %s is used in equation %s.\n', pacname, pacmodel.tag_map{1,1});
else
fprintf('PAC model %s is used in %u equation(s):\n', pacname, number_of_pac_eq);
skipline()
for i=1:number_of_pac_eq
fprintf(' - %s\n', pacmodel.tag_map{i,1});
end
end
skipline()
equations = pacmodel.equations;
for e=1:number_of_pac_eq
% Get PAC equation tag
eqtag = pacmodel.tag_map{e,2};
% Get PAC equation
pac_equation = equations.(eqtag);
% Get Error correction and autoregressive parameters in PAC equation
a = NaN(1+pac_equation.max_lag, 1);
a(1) = M_.params(pac_equation.ec.params);
a(1+(1:pac_equation.max_lag)) = M_.params(pac_equation.ar.params);
M_.params(pac_equation.mce.alpha) = a2alpha(a);
end

View File

@ -47,20 +47,20 @@ end
% Get PAC model description
pacmodel = DynareModel.pac.(pacname);
% Get the name of the associated VAR model and test its existence.
if pacmodel.model_consistent_expectations
error('This function cannot be used with Model Consistent Expectation. Try pac.mce.parameters instead.')
end
% Get the name of the associated auxiliary model (VAR or TREND_COMPONENT) model and test its existence.
if ~isfield(DynareModel.(pacmodel.auxiliary_model_type), pacmodel.auxiliary_model_name)
error('Unknown auxiliary model (%s) in PAC model (%s)!', pacmodel.auxiliary_model_name, pacname)
end
varmodel = DynareModel.(pacmodel.auxiliary_model_type).(pacmodel.auxiliary_model_name);
% Check that we have the values of the VAR matrices.
% Check that we have the values of the VAR or TREND_COMPONENT matrices.
if ~isfield(DynareOutput.(pacmodel.auxiliary_model_type), pacmodel.auxiliary_model_name)
error('Auxiliary model %s has to be estimated first!', pacmodel.auxiliary_model_name)
end
varcalib = DynareOutput.(pacmodel.auxiliary_model_type).(pacmodel.auxiliary_model_name);
if ~isfield(varcalib, 'CompanionMatrix') || any(isnan(varcalib.CompanionMatrix(:)))
error('Auxiliary model %s has to be estimated first.', pacmodel.auxiliary_model_name)
end

View File

@ -27,4 +27,9 @@ function initialize(pacmodel)
global M_
get_companion_matrix(M_.pac.(pacmodel).auxiliary_model_name, M_.pac.(pacmodel).auxiliary_model_type);
if isempty(M_.pac.(pacmodel).auxiliary_model_name)
M_.pac.(pacmodel).model_consistent_expectations = true;
else
M_.pac.(pacmodel).model_consistent_expectations = false;
get_companion_matrix(M_.pac.(pacmodel).auxiliary_model_name, M_.pac.(pacmodel).auxiliary_model_type);
end

@ -1 +1 @@
Subproject commit 8ae7f81fd990d261058de21312ff0e0c290fde90
Subproject commit abde60fbeaa36704054a23606057e4d35495b898

View File

@ -418,6 +418,8 @@ MODFILES = \
pac/trend-component-19/example1.mod \
pac/trend-component-19/example2.mod \
pac/trend-component-19/example3.mod \
pac/trend-component-1-mce/example_det.mod \
pac/trend-component-1-mce/example_sto.mod \
ecb/backward-models/irf/solow_1.mod \
ecb/backward-models/irf/solow_2.mod \
dynare-command-options/ramst.mod

View File

@ -0,0 +1,13 @@
#!/bin/sh
rm *.eps
rm -rf example_det
rm -rf +example_det
rm -f example_det*.mat
rm -f example_det.log
rm -rf example_sto
rm -rf +example_sto
rm -f example_sto*.mat
rm -f example_sto.log

View File

@ -0,0 +1,68 @@
// --+ options: json=compute +--
var x1 x2 x1bar x2bar z ;
varexo ex1 ex2 ex1bar ex2bar ez;
parameters a_x1_0 a_x1_1 a_x1_2 a_x1_x2_1 a_x1_x2_2
a_x2_0 a_x2_1 a_x2_2 a_x2_x1_1 a_x2_x1_2
e_c_m c_z_1 c_z_2 gamma beta ;
a_x1_0 = -.9;
a_x1_1 = .4;
a_x1_2 = .3;
a_x1_x2_1 = .1;
a_x1_x2_2 = .2;
a_x2_0 = -.9;
a_x2_1 = .2;
a_x2_2 = -.1;
a_x2_x1_1 = -.1;
a_x2_x1_2 = .2;
beta = .2;
e_c_m = .5;
c_z_1 = .2;
c_z_2 = -.1;
gamma = .7;
trend_component_model(model_name=toto, eqtags=['eq:x1', 'eq:x2', 'eq:x1bar', 'eq:x2bar'], targets=['eq:x1bar', 'eq:x2bar']);
pac_model(discount=beta, model_name=pacman, steady_state_growth=.0);
model;
[name='eq:x1']
diff(x1) = a_x1_0*(x1(-1)-x1bar(-1)) + a_x1_1*diff(x1(-1)) + a_x1_2*diff(x1(-2)) + a_x1_x2_1*diff(x2(-1)) + a_x1_x2_2*diff(x2(-2)) + ex1;
[name='eq:x2']
diff(x2) = a_x2_0*(x2(-1)-x2bar(-1)) + a_x2_1*diff(x1(-1)) + a_x2_2*diff(x1(-2)) + a_x2_x1_1*diff(x2(-1)) + a_x2_x1_2*diff(x2(-2)) + ex2;
[name='eq:x1bar']
x1bar = x1bar(-1) + ex1bar;
[name='eq:x2bar']
x2bar = x2bar(-1) + ex2bar;
[name='eq:pac']
diff(z) = e_c_m*(x1(-1)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez;
end;
// Initialize the PAC model.
pac.initialize('pacman');
// Update the PAC/MCE parameters (α in M_.params).
pac.mce.parameters('pacman');
// Setup a scenario for the shocks.
shocks;
var ex1;
periods 1;
values .2;
end;
perfect_foresight_setup(periods=50);
perfect_foresight_solver;

View File

@ -0,0 +1,71 @@
// --+ options: json=compute, stochastic +--
var x1 x2 x1bar x2bar z ;
varexo ex1 ex2 ex1bar ex2bar ez;
parameters a_x1_0 a_x1_1 a_x1_2 a_x1_x2_1 a_x1_x2_2
a_x2_0 a_x2_1 a_x2_2 a_x2_x1_1 a_x2_x1_2
e_c_m c_z_1 c_z_2 gamma beta g;
a_x1_0 = -.9;
a_x1_1 = .4;
a_x1_2 = .3;
a_x1_x2_1 = .1;
a_x1_x2_2 = .2;
a_x2_0 = -.9;
a_x2_1 = .2;
a_x2_2 = -.1;
a_x2_x1_1 = -.1;
a_x2_x1_2 = .2;
beta = .2;
e_c_m = .5;
c_z_1 = .2;
c_z_2 = -.1;
gamma = .7;
g = .02;
trend_component_model(model_name=toto, eqtags=['eq:x1', 'eq:x2', 'eq:x1bar', 'eq:x2bar'], targets=['eq:x1bar', 'eq:x2bar']);
pac_model(discount=beta, model_name=pacman);
model(linear);
[name='eq:x1']
diff(x1) = a_x1_0*(x1(-1)-x1bar(-1)) + a_x1_1*diff(x1(-1)) + a_x1_2*diff(x1(-2)) + a_x1_x2_1*diff(x2(-1)) + a_x1_x2_2*diff(x2(-2)) + ex1;
[name='eq:x2']
diff(x2) = a_x2_0*(x2(-1)-x2bar(-1)) + a_x2_1*diff(x1(-1)) + a_x2_2*diff(x1(-2)) + a_x2_x1_1*diff(x2(-1)) + a_x2_x1_2*diff(x2(-2)) + ex2;
[name='eq:x1bar']
x1bar = x1bar(-1) + ex1bar;
[name='eq:x2bar']
x2bar = x2bar(-1) + ex2bar;
[name='eq:pac']
diff(z) = e_c_m*(x1(-1)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez;
end;
// Initialize the PAC model.
pac.initialize('pacman');
// Update the PAC/MCE parameters (α in M_.params).
pac.mce.parameters('pacman');
// Setup a scenario for the shocks.
shocks;
var ex1 = .01;
var ex2 = .01;
var ex1bar = .0;
var ex2bar = .0;
var ez = .02;
end;
stoch_simul(periods=1000);