Fix constant in VAR and PAC expectations...

When the VAR auxiliary model has a constant.
var-model-with-constant
Stéphane Adjemian (Ryûk) 2021-07-21 17:58:29 +02:00
parent a69f68bb7c
commit cd2ed823b6
Signed by: stepan
GPG Key ID: 295C1FE89E17EB3C
14 changed files with 72 additions and 19 deletions

View File

@ -13,7 +13,7 @@ function DynareModel = parameters(pacname, DynareModel, DynareOutput, verbose)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2018-2019 Dynare Team
% Copyright © 2018-2021 Dynare Team
%
% This file is part of Dynare.
%
@ -135,6 +135,16 @@ for e=1:number_of_pac_eq
end
% Update the parameters related to the stationary components.
if ~isempty(h0)
if isequal(pacmodel.auxiliary_model_type, 'var')
if DynareModel.var.(pacmodel.auxiliary_model_name).isconstant
DynareModel.params(equations.(eqtag).h0_param_indices) = h0;
else
DynareModel.params(equations.(eqtag).h0_param_indices(1)) = .0;
DynareModel.params(equations.(eqtag).h0_param_indices(2:end)) = h0;
end
else
DynareModel.params(equations.(eqtag).h0_param_indices) = h0;
end
DynareModel.params(pacmodel.equations.(eqtag).h0_param_indices) = h0;
else
if ~isempty(equations.(eqtag).h0_param_indices)
@ -143,7 +153,16 @@ for e=1:number_of_pac_eq
end
% Update the parameters related to the nonstationary components.
if ~isempty(h1)
DynareModel.params(equations.(eqtag).h1_param_indices) = h1;
if isequal(pacmodel.auxiliary_model_type, 'var')
if DynareModel.var.(pacmodel.auxiliary_model_name).isconstant
DynareModel.params(equations.(eqtag).h1_param_indices) = h1;
else
DynareModel.params(equations.(eqtag).h1_param_indices(1)) = .0;
DynareModel.params(equations.(eqtag).h1_param_indices(2:end)) = h1;
end
else
DynareModel.params(equations.(eqtag).h1_param_indices) = h1;
end
else
if ~isempty(equations.(eqtag).h1_param_indices)
DynareModel.params(equations.(eqtag).h1_param_indices) = .0;

View File

@ -13,7 +13,7 @@ function DynareModel = update_parameters(varexpectationmodelname, DynareModel, D
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2018-2021 Dynare Team
% Copyright © 2018-2021 Dynare Team
%
% This file is part of Dynare.
%
@ -205,4 +205,13 @@ else
end
% Update reduced form parameters in M_.params.
DynareModel.params(varexpectationmodel.param_indices) = parameters;
if isequal(varexpectationmodel.auxiliary_model_type, 'var')
if DynareModel.var.(varexpectationmodel.auxiliary_model_name).isconstant
DynareModel.params(varexpectationmodel.param_indices) = parameters;
else
DynareModel.params(varexpectationmodel.param_indices(1)) = .0;
DynareModel.params(varexpectationmodel.param_indices(2:end)) = parameters;
end
else
DynareModel.params(varexpectationmodel.param_indices) = parameters;
end

View File

@ -44,6 +44,7 @@ end
if strcmp(auxiliary_model_type, 'var')
[AR, ~, Constant] = feval(sprintf('%s.varmatrices', M_.fname), auxiliary_model_name, M_.params, M_.var.(auxiliary_model_name).structural);
isconstant = any(abs(Constant)>0);
M_.var.(auxiliary_model_name).isconstant = isconstant; % FIXME Could be done by preprocessor instead…
elseif strcmp(auxiliary_model_type, 'trend_component')
[AR, A0, A0star] = feval(sprintf('%s.trend_component_ar_a0', M_.fname), auxiliary_model_name, M_.params);
else

View File

@ -22,7 +22,7 @@ function print_expectations(eqname, expectationmodelname, expectationmodelkind,
%
% The variable expectationmodelkind can take two values 'var' or 'pac'.
% Copyright (C) 2018-2019 Dynare Team
% Copyright © 2018-2021 Dynare Team
%
% This file is part of Dynare.
%
@ -251,6 +251,17 @@ if isequal(expectationmodel.auxiliary_model_type, 'trend_component')
maxlag = maxlag+1;
end
if isequal(expectationmodelkind, 'var') && isequal(expectationmodel.auxiliary_model_type, 'var')
id = id+1;
expression = sprintf('%1.16f', M_.params(expectationmodel.param_indices(id)));
end
if isequal(expectationmodelkind, 'pac') && isequal(expectationmodel.auxiliary_model_type, 'var')
id = id+1;
expression = sprintf('%1.16f', M_.params(expectationmodel.equations.(eqtag).h0_param_indices(id))+ ...
M_.params(expectationmodel.equations.(eqtag).h1_param_indices(id)));
end
for i=1:maxlag
for j=1:length(auxmodel.list_of_variables_in_companion_var)
id = id+1;

View File

@ -12,7 +12,7 @@ function [expression, growthneutralitycorrection] = write_expectations(eqname, e
% - expression [string] Unrolled expectation expression.
% - growthneutralitycorrection [string]
% Copyright (C) 2019 Dynare Team
% Copyright © 2019-2021 Dynare Team
%
% This file is part of Dynare.
%
@ -78,6 +78,17 @@ if isequal(expectationmodelkind, 'var')
timeindices = (0:(maxlag-1))+abs(expectationmodel.time_shift);
end
if isequal(expectationmodelkind, 'var') && isequal(expectationmodel.auxiliary_model_type, 'var')
id = id+1;
expression = sprintf('%s', M_.param_names{expectationmodel.param_indices(id)});
end
if isequal(expectationmodelkind, 'pac') && isequal(expectationmodel.auxiliary_model_type, 'var')
id = id+1;
expression = sprintf('%s+%s', M_.param_names{expectationmodel.equations.(eqtag).h0_param_indices(id)}, ...
M_.param_names{expectationmodel.equations.(eqtag).h1_param_indices(id)});
end
for i=1:maxlag
for j=1:length(auxmodel.list_of_variables_in_companion_var)
id = id+1;

View File

@ -50,8 +50,8 @@ y = d*y(-2) + e*z(-1) + e_y;
foo = .5*foo(-1) + var_expectation(varexp);
end;
// Initialize the VAR expectation model, will build the companion matrix of the VAR.
var_expectation.initialize('varexp')
// Update VAR_EXPECTATION reduced form parameters
@ -66,6 +66,6 @@ var_expectation.update('varexp');
weights = M_.params(M_.var_expectation.varexp.param_indices);
if weights(2) || weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6)
if weights(3) || weights(4) || weights(6) || ~weights(2) || ~weights(5) || ~weights(7) || weights(1)
error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL')
end
end

View File

@ -74,6 +74,7 @@ if ~isfield(M_.var_expectation.varexp, 'time_shift') || ~isequal(M_.var_expectat
end
str = strrep(str, 'foo = .5*foo(-1)', '');
str = strrep(str, '+ var_expectation_model_varexp_constant', '');
str = strrep(str, '+ var_expectation_model_varexp_x_0*x(-2)', '');
str = strrep(str, '+ var_expectation_model_varexp_y_0*y(-2)', '');
str = strrep(str, '+ var_expectation_model_varexp_z_0*z(-2)', '');
@ -81,6 +82,7 @@ str = strrep(str, '+ var_expectation_model_varexp_x_1*x(-3)', '');
str = strrep(str, '+ var_expectation_model_varexp_y_1*y(-3)', '');
str = strrep(str, '+ var_expectation_model_varexp_z_1*z(-3)', '');
str = strrep(str, ';', '');
if ~isempty(strtrim(str))
error('Printed equation is wrong.')
end

View File

@ -75,6 +75,6 @@ fprintf('\n')
weights = M_.params(M_.var_expectation.varexp.param_indices);
if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6)
if weights(3) || ~weights(4) || weights(6) || ~weights(2) || ~weights(5) || ~weights(7) || weights(1)
error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL')
end
end

View File

@ -65,7 +65,7 @@ var_expectation.update('varexp');
weights = M_.params(M_.var_expectation.varexp.param_indices);
if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6)
if weights(3) || ~weights(4) || weights(6) || ~weights(2) || ~weights(5) || ~weights(7) || weights(1)
error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL')
end

View File

@ -64,7 +64,7 @@ var_expectation.update('varexp');
weights = M_.params(M_.var_expectation.varexp.param_indices);
if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6)
if weights(3) || ~weights(4) || weights(6) || ~weights(2) || ~weights(5) || ~weights(7) || weights(1)
error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL')
end

View File

@ -65,7 +65,7 @@ var_expectation.update('varexp');
weights = M_.params(M_.var_expectation.varexp.param_indices);
if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6)
if weights(3) || ~weights(4) || weights(6) || ~weights(2) || ~weights(5) || ~weights(7) || weights(1)
error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL')
end

View File

@ -64,7 +64,7 @@ var_expectation.update('varexp');
weights = M_.params(M_.var_expectation.varexp.param_indices);
if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6)
if weights(3) || ~weights(4) || weights(6) || ~weights(2) || ~weights(5) || ~weights(7) || weights(1)
error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL')
end
@ -74,4 +74,4 @@ if max(abs(weights-WEIGHTS.weights))>1e-12
error('Inconsistent results in var-expectations/3 and var-expectations/4.')
end
delete('../3/weights.mat')
delete('../3/weights.mat')

View File

@ -64,6 +64,6 @@ var_expectation.update('varexp');
weights = M_.params(M_.var_expectation.varexp.param_indices);
if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6)
if weights(3) || ~weights(4) || weights(6) || ~weights(2) || ~weights(5) || ~weights(7) || weights(1)
error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL')
end

View File

@ -63,6 +63,6 @@ var_expectation.update('varexp');
weights = M_.params(M_.var_expectation.varexp.param_indices);
if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6)
if weights(3) || ~weights(4) || weights(6) || ~weights(2) || ~weights(5) || ~weights(7) || weights(1)
error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL')
end
end