Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Johannes Pfeifer
dynare
Commits
cd2ed823
Verified
Commit
cd2ed823
authored
Jul 21, 2021
by
Stéphane Adjemian
Browse files
Fix constant in VAR and PAC expectations...
When the VAR auxiliary model has a constant.
parent
a69f68bb
Changes
14
Hide whitespace changes
Inline
Side-by-side
matlab/+pac/+update/parameters.m
View file @
cd2ed823
...
...
@@ -13,7 +13,7 @@ function DynareModel = parameters(pacname, DynareModel, DynareOutput, verbose)
% SPECIAL REQUIREMENTS
% none
% Copyright
(C)
2018-201
9
Dynare Team
% Copyright
©
2018-20
2
1 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
;
...
...
matlab/+var_expectation/update_parameters.m
View file @
cd2ed823
...
...
@@ -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
matlab/get_companion_matrix.m
View file @
cd2ed823
...
...
@@ -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
...
...
matlab/print_expectations.m
View file @
cd2ed823
...
...
@@ -22,7 +22,7 @@ function print_expectations(eqname, expectationmodelname, expectationmodelkind,
%
% The variable expectationmodelkind can take two values 'var' or 'pac'.
% Copyright
(C)
2018-201
9
Dynare Team
% Copyright
©
2018-20
2
1 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
;
...
...
matlab/write_expectations.m
View file @
cd2ed823
...
...
@@ -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
;
...
...
tests/var-expectations/1/example1.mod
View file @
cd2ed823
...
...
@@ -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
\ No newline at end of file
end
tests/var-expectations/2-with-time-shift/example1.mod
View file @
cd2ed823
...
...
@@ -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
tests/var-expectations/2/example1.mod
View file @
cd2ed823
...
...
@@ -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
\ No newline at end of file
end
tests/var-expectations/3-with-time-shift/example1.mod
View file @
cd2ed823
...
...
@@ -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
...
...
tests/var-expectations/3/example1.mod
View file @
cd2ed823
...
...
@@ -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
...
...
tests/var-expectations/4-with-time-shift/example1.mod
View file @
cd2ed823
...
...
@@ -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
...
...
tests/var-expectations/4/example1.mod
View file @
cd2ed823
...
...
@@ -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')
\ No newline at end of file
delete('../3/weights.mat')
tests/var-expectations/5-with-time-shift/example1.mod
View file @
cd2ed823
...
...
@@ -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
tests/var-expectations/5/example1.mod
View file @
cd2ed823
...
...
@@ -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
\ No newline at end of file
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment