2019-02-22 17:58:24 +01:00
|
|
|
function print_expectations(eqname, expectationmodelname, expectationmodelkind, withcalibration)
|
2018-10-14 16:48:29 +02:00
|
|
|
|
|
|
|
% Prints the exansion of the VAR_EXPECTATION or PAC_EXPECTATION term in files.
|
|
|
|
%
|
|
|
|
% INPUTS
|
2019-02-22 17:58:24 +01:00
|
|
|
% - eqname [string] Name of the equation.
|
2018-10-14 16:48:29 +02:00
|
|
|
% - epxpectationmodelname [string] Name of the expectation model.
|
|
|
|
% - expectationmodelkind [string] Kind of the expectation model.
|
|
|
|
% - withcalibration [logical] Prints calibration if true.
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% None
|
|
|
|
%
|
|
|
|
% REMARKS
|
2021-10-24 19:11:52 +02:00
|
|
|
% print_expectations creates two text files
|
2018-10-14 16:48:29 +02:00
|
|
|
%
|
|
|
|
% - {expectationmodelname}-parameters.inc which contains the declaration of the parameters specific to the expectation model kind term.
|
|
|
|
% - {expectationmodelname}-expression.inc which contains the expanded version of the expectation model kind term.
|
|
|
|
%
|
|
|
|
% These routines are saved under the {modfilename}/model/{expectationmodelkind} subfolder, and can be
|
|
|
|
% used after in another mod file (ie included with the macro directive @#include).
|
|
|
|
%
|
2021-10-24 19:11:52 +02:00
|
|
|
% print_expectations also creates a matlab routine to evaluate the expectations (returning a dseries object).
|
|
|
|
%
|
2019-03-14 11:04:10 +01:00
|
|
|
% The variable expectationmodelkind can take two values 'var' or 'pac'.
|
2018-10-14 16:48:29 +02:00
|
|
|
|
2021-07-21 17:58:29 +02:00
|
|
|
% Copyright © 2018-2021 Dynare Team
|
2018-10-14 16:48:29 +02:00
|
|
|
%
|
|
|
|
% 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
|
2021-06-09 17:33:48 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2018-10-14 16:48:29 +02:00
|
|
|
|
|
|
|
global M_
|
|
|
|
|
2019-02-22 17:58:24 +01:00
|
|
|
if nargin<4 || isempty(withcalibration)
|
2018-10-14 16:48:29 +02:00
|
|
|
withcalibration = true;
|
|
|
|
end
|
|
|
|
|
|
|
|
% Check that the first input is a row character array.
|
2019-02-22 17:58:24 +01:00
|
|
|
if ~isrow(eqname)==1 || ~ischar(eqname)
|
2018-10-14 16:48:29 +02:00
|
|
|
error('First input argument must be a row character array.')
|
|
|
|
end
|
|
|
|
|
|
|
|
% Check that the second input is a row character array.
|
2019-02-22 17:58:24 +01:00
|
|
|
if ~isrow(expectationmodelname)==1 || ~ischar(expectationmodelname)
|
2018-10-14 16:48:29 +02:00
|
|
|
error('Second input argument must be a row character array.')
|
|
|
|
end
|
|
|
|
|
2019-02-22 17:58:24 +01:00
|
|
|
% Check that the third input is a row character array.
|
|
|
|
if ~isrow(expectationmodelkind)==1 || ~ischar(expectationmodelkind)
|
|
|
|
error('Third input argument must be a row character array.')
|
|
|
|
end
|
|
|
|
|
2018-10-14 16:48:29 +02:00
|
|
|
% Check that the value of the second input is correct.
|
2019-03-14 11:04:10 +01:00
|
|
|
if ~ismember(expectationmodelkind, {'var', 'pac'})
|
2019-02-22 17:58:24 +01:00
|
|
|
error('Wrong value for the second input argument.')
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
% Check that the model exists.
|
|
|
|
switch expectationmodelkind
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'var'
|
2018-10-14 16:48:29 +02:00
|
|
|
if ~isfield(M_.var_expectation, expectationmodelname)
|
|
|
|
error('VAR_EXPECTATION_MODEL %s is not defined.', expectationmodelname)
|
|
|
|
else
|
|
|
|
expectationmodelfield = 'var_expectation';
|
|
|
|
end
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'pac'
|
2018-10-14 16:48:29 +02:00
|
|
|
if ~isfield(M_.pac, expectationmodelname)
|
|
|
|
error('PAC_EXPECTATION_MODEL %s is not defined.', expectationmodelname)
|
|
|
|
else
|
|
|
|
expectationmodelfield = 'pac';
|
|
|
|
end
|
|
|
|
otherwise
|
|
|
|
end
|
|
|
|
|
|
|
|
% Get the expectation model description
|
|
|
|
expectationmodel = M_.(expectationmodelfield).(expectationmodelname);
|
|
|
|
|
|
|
|
% Get the name of the associated VAR model and test its existence.
|
2021-10-26 10:24:19 +02:00
|
|
|
if isfield(expectationmodel, 'auxiliary_model_name') && ~isfield(M_.(expectationmodel.auxiliary_model_type), expectationmodel.auxiliary_model_name)
|
|
|
|
switch expectationmodelkind
|
|
|
|
case 'var'
|
|
|
|
error('Unknown VAR/TREND_COMPONENT model (%s) in VAR_EXPECTATION_MODEL (%s)!', expectationmodel.auxiliary_model_name, expectationmodelname)
|
|
|
|
case 'pac'
|
|
|
|
error('Unknown VAR/TREND_COMPONENT model (%s) in PAC_EXPECTATION_MODEL (%s)!', expectationmodel.auxiliary_model_name, expectationmodelname)
|
|
|
|
otherwise
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
2021-10-26 10:24:19 +02:00
|
|
|
elseif isequal(expectationmodelkind, 'pac') && ~isfield(expectationmodel, 'auxiliary_model_name')
|
2021-10-25 19:23:51 +02:00
|
|
|
error('print method does not work in PAC/MCE.')
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
auxmodel = M_.(expectationmodel.auxiliary_model_type).(expectationmodel.auxiliary_model_name);
|
|
|
|
|
2018-12-03 15:07:43 +01:00
|
|
|
%
|
|
|
|
% First print the list of parameters appearing in the VAR_EXPECTATION/PAC_EXPECTATION term.
|
|
|
|
%
|
2019-03-14 11:04:10 +01:00
|
|
|
if ~exist(sprintf('%s/model/%s', M_.fname, [expectationmodelkind '-expectations']), 'dir')
|
|
|
|
mkdir(sprintf('%s/model/%s', M_.fname, [expectationmodelkind '-expectations']))
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
|
2021-11-18 12:24:23 +01:00
|
|
|
filename = sprintf('%s/model/%s/%s-parameters.inc', M_.fname, [expectationmodelkind '-expectations'], expectationmodelname);
|
2018-10-14 16:48:29 +02:00
|
|
|
fid = fopen(filename, 'w');
|
|
|
|
fprintf(fid, '// This file has been generated by dynare (%s).\n\n', datestr(now));
|
|
|
|
|
|
|
|
switch expectationmodelkind
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'var'
|
2018-10-14 16:48:29 +02:00
|
|
|
parameter_declaration = 'parameters';
|
|
|
|
for i=1:length(expectationmodel.param_indices)
|
|
|
|
parameter_declaration = sprintf('%s %s', parameter_declaration, M_.param_names{expectationmodel.param_indices(i)});
|
|
|
|
end
|
|
|
|
fprintf(fid, '%s;\n\n', parameter_declaration);
|
|
|
|
if withcalibration
|
|
|
|
for i=1:length(expectationmodel.param_indices)
|
2019-10-07 16:45:24 +02:00
|
|
|
fprintf(fid, '%s = %1.16f;\n', M_.param_names{expectationmodel.param_indices(i)}, M_.params(expectationmodel.param_indices(i)));
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
end
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'pac'
|
2021-11-18 12:24:23 +01:00
|
|
|
parameter_declaration = 'parameters';
|
2021-11-25 16:16:42 +01:00
|
|
|
if isfield(expectationmodel, 'h_param_indices')
|
|
|
|
for i=1:length(expectationmodel.h_param_indices)
|
|
|
|
parameter_declaration = sprintf('%s %s', parameter_declaration, M_.param_names{expectationmodel.h_param_indices(i)});
|
|
|
|
end
|
|
|
|
else
|
|
|
|
for j=1:length(expectationmodel.components)
|
|
|
|
for i=1:length(expectationmodel.components(j).h_param_indices)
|
|
|
|
parameter_declaration = sprintf('%s %s', parameter_declaration, M_.param_names{expectationmodel.components(j).h_param_indices(i)});
|
|
|
|
end
|
|
|
|
end
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
2021-11-18 12:24:23 +01:00
|
|
|
fprintf(fid, '%s;\n\n', parameter_declaration);
|
|
|
|
if withcalibration
|
2021-11-25 16:16:42 +01:00
|
|
|
if isfield(expectationmodel, 'h_param_indices')
|
|
|
|
for i=1:length(expectationmodel.h_param_indices)
|
|
|
|
fprintf(fid, '%s = %1.16f;\n', M_.param_names{expectationmodel.h_param_indices(i)}, M_.params(expectationmodel.h_param_indices(i)));
|
|
|
|
end
|
|
|
|
else
|
|
|
|
for j=1:length(expectationmodel.components)
|
|
|
|
for i=1:length(expectationmodel.components(j).h_param_indices)
|
|
|
|
fprintf(fid, '%s = %1.16f;\n', M_.param_names{expectationmodel.components(j).h_param_indices(i)}, M_.params(expectationmodel.components(j).h_param_indices(i)));
|
|
|
|
end
|
|
|
|
end
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if isfield(expectationmodel, 'growth_neutrality_param_index')
|
|
|
|
fprintf(fid, '\n');
|
|
|
|
fprintf(fid, 'parameters %s;\n\n', M_.param_names{expectationmodel.growth_neutrality_param_index});
|
|
|
|
if withcalibration
|
2019-10-07 16:45:24 +02:00
|
|
|
fprintf(fid, '%s = %1.16f;\n', M_.param_names{expectationmodel.growth_neutrality_param_index}, M_.params(expectationmodel.growth_neutrality_param_index));
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
growth_correction = true;
|
|
|
|
else
|
|
|
|
growth_correction = false;
|
2021-11-25 16:16:42 +01:00
|
|
|
if isfield(expectationmodel, 'components')
|
|
|
|
for j=1:length(expectationmodel.components)
|
|
|
|
if isfield(expectationmodel.components(j), 'growth_neutrality_param_index') && ~isempty(expectationmodel.components(j).growth_neutrality_param_index)
|
|
|
|
fprintf(fid, '\n');
|
|
|
|
fprintf(fid, 'parameters %s;\n\n', M_.param_names{expectationmodel.components(j).growth_neutrality_param_index});
|
|
|
|
if withcalibration
|
|
|
|
fprintf(fid, '%s = %1.16f;\n', M_.param_names{expectationmodel.components(j).growth_neutrality_param_index}, M_.params(expectationmodel.components(j).growth_neutrality_param_index));
|
|
|
|
end
|
|
|
|
growth_correction = true;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
fclose(fid);
|
|
|
|
|
2019-03-07 17:09:56 +01:00
|
|
|
skipline()
|
2019-02-22 17:58:24 +01:00
|
|
|
fprintf('Parameters declarations and calibrations are saved in %s.\n', filename);
|
|
|
|
|
2018-12-03 15:07:43 +01:00
|
|
|
%
|
|
|
|
% Second print the expanded VAR_EXPECTATION/PAC_EXPECTATION term.
|
|
|
|
%
|
2019-02-22 17:58:24 +01:00
|
|
|
|
2021-11-18 12:24:23 +01:00
|
|
|
filename = sprintf('%s/model/%s/%s-expression.inc', M_.fname, [expectationmodelkind '-expectations'], expectationmodelname);
|
2018-10-14 16:48:29 +02:00
|
|
|
fid = fopen(filename, 'w');
|
|
|
|
fprintf(fid, '// This file has been generated by dynare (%s).\n', datestr(now));
|
|
|
|
|
2019-03-14 11:04:10 +01:00
|
|
|
switch expectationmodelkind
|
|
|
|
case 'var'
|
2021-11-18 12:24:23 +01:00
|
|
|
expression = write_expectations(expectationmodelname, expectationmodelkind, true);
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'pac'
|
2021-11-18 12:24:23 +01:00
|
|
|
[expression, growthneutralitycorrection] = write_expectations(expectationmodelname, expectationmodelkind, true);
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
fprintf(fid, '%s', expression);
|
2018-12-03 15:07:43 +01:00
|
|
|
fclose(fid);
|
|
|
|
|
2019-02-22 17:58:24 +01:00
|
|
|
fprintf('Expectation unrolled expression is saved in %s.\n', filename);
|
|
|
|
|
2019-02-27 22:26:07 +01:00
|
|
|
%
|
|
|
|
% Second bis print the PAC growth neutrality correction term (if any).
|
|
|
|
%
|
|
|
|
|
2019-03-14 11:04:10 +01:00
|
|
|
if isequal(expectationmodelkind, 'pac') && growth_correction
|
2021-11-18 12:24:23 +01:00
|
|
|
filename = sprintf('%s/model/%s/%s-growth-neutrality-correction.inc', M_.fname, [expectationmodelkind '-expectations'], expectationmodelname);
|
2019-02-27 22:26:07 +01:00
|
|
|
fid = fopen(filename, 'w');
|
|
|
|
fprintf(fid, '// This file has been generated by dynare (%s).\n', datestr(now));
|
2019-03-14 11:04:10 +01:00
|
|
|
fprintf(fid, '%s', growthneutralitycorrection);
|
2019-02-27 22:26:07 +01:00
|
|
|
fclose(fid);
|
|
|
|
fprintf('Growth neutrality correction is saved in %s.\n', filename);
|
|
|
|
end
|
|
|
|
|
2018-12-03 15:07:43 +01:00
|
|
|
%
|
2018-12-19 10:53:09 +01:00
|
|
|
% Third print a routine for evaluating VAR_EXPECTATION/PAC_EXPECTATION term (returns a dseries object).
|
2018-12-03 15:07:43 +01:00
|
|
|
%
|
2019-03-14 11:04:10 +01:00
|
|
|
kind = [expectationmodelkind '_expectations'];
|
2021-12-20 20:38:58 +01:00
|
|
|
ndir = sprintf('+%s/+%s/+%s', M_.fname, kind, expectationmodelname);
|
|
|
|
if ~exist(ndir, 'dir')
|
|
|
|
mkdir(sprintf('+%s/+%s/+%s', M_.fname, kind, expectationmodelname));
|
|
|
|
end
|
2021-11-18 12:24:23 +01:00
|
|
|
filename = sprintf('+%s/+%s/+%s/evaluate.m', M_.fname, kind, expectationmodelname);
|
2018-12-03 15:07:43 +01:00
|
|
|
fid = fopen(filename, 'w');
|
2021-11-18 12:24:23 +01:00
|
|
|
|
|
|
|
fprintf(fid, 'function ds = evaluate(dbase)\n\n');
|
|
|
|
fprintf(fid, '%% Evaluates %s term (%s).\n', kind, expectationmodelname);
|
2018-12-03 15:07:43 +01:00
|
|
|
fprintf(fid, '%%\n');
|
|
|
|
fprintf(fid, '%% INPUTS\n');
|
|
|
|
fprintf(fid, '%% - dbase [dseries] databse containing all the variables appearing in the auxiliary model for the expectation.\n');
|
|
|
|
fprintf(fid, '%%\n');
|
|
|
|
fprintf(fid, '%% OUTPUTS\n');
|
2018-12-19 10:53:09 +01:00
|
|
|
fprintf(fid, '%% - ds [dseries] the expectation term .\n');
|
2018-12-03 15:07:43 +01:00
|
|
|
fprintf(fid, '%%\n');
|
|
|
|
fprintf(fid, '%% REMARKS\n');
|
|
|
|
fprintf(fid, '%% The name of the appended variable in dbase is the declared name for the (PAC/VAR) expectation model.\n\n');
|
|
|
|
fprintf(fid, '%% This file has been generated by dynare (%s).\n\n', datestr(now));
|
2018-12-19 10:53:09 +01:00
|
|
|
fprintf(fid, 'ds = dseries();\n\n');
|
2018-12-03 15:07:43 +01:00
|
|
|
|
|
|
|
id = 0;
|
|
|
|
|
2021-12-20 20:38:58 +01:00
|
|
|
if isfield(expectationmodel, 'h_param_indices')
|
|
|
|
decompose = false;
|
|
|
|
else
|
2022-01-03 22:24:32 +01:00
|
|
|
if isequal(expectationmodelkind, 'pac')
|
|
|
|
decompose = true;
|
|
|
|
else
|
|
|
|
decompose = false;
|
|
|
|
end
|
2021-12-20 20:38:58 +01:00
|
|
|
end
|
|
|
|
|
2021-11-25 16:16:42 +01:00
|
|
|
clear('expression');
|
|
|
|
|
|
|
|
% Get coefficient values in the target (if any)
|
|
|
|
if exist(sprintf('+%s/pac_target_coefficients.m', M_.fname), 'file')
|
|
|
|
targetcoefficients = feval(sprintf('%s.pac_target_coefficients', M_.fname), expectationmodelname, M_.params);
|
|
|
|
end
|
|
|
|
|
2018-12-03 15:07:43 +01:00
|
|
|
maxlag = max(auxmodel.max_lag);
|
|
|
|
if isequal(expectationmodel.auxiliary_model_type, 'trend_component')
|
|
|
|
% Need to add a lag since the error correction equations are rewritten in levels.
|
|
|
|
maxlag = maxlag+1;
|
|
|
|
end
|
|
|
|
|
2021-10-24 19:29:31 +02:00
|
|
|
if isequal(expectationmodelkind, 'var')
|
|
|
|
timeindices = (0:(maxlag-1))+abs(expectationmodel.time_shift);
|
|
|
|
end
|
|
|
|
|
2021-07-21 17:58:29 +02:00
|
|
|
if isequal(expectationmodelkind, 'var') && isequal(expectationmodel.auxiliary_model_type, 'var')
|
2021-11-25 16:16:42 +01:00
|
|
|
% Constant in the VAR auxiliary model
|
2021-07-21 17:58:29 +02:00
|
|
|
id = id+1;
|
|
|
|
expression = sprintf('%1.16f', M_.params(expectationmodel.param_indices(id)));
|
|
|
|
end
|
|
|
|
|
|
|
|
if isequal(expectationmodelkind, 'pac') && isequal(expectationmodel.auxiliary_model_type, 'var')
|
2021-11-25 16:16:42 +01:00
|
|
|
% Constant in the VAR auxiliary model
|
2021-07-21 17:58:29 +02:00
|
|
|
id = id+1;
|
2021-11-25 16:16:42 +01:00
|
|
|
if isfield(expectationmodel, 'h_param_indices')
|
|
|
|
constant = M_.params(expectationmodel.h_param_indices(id));
|
|
|
|
else
|
2021-12-20 20:38:58 +01:00
|
|
|
if decompose
|
|
|
|
expressions = cell(length(expectationmodel.components), 1);
|
|
|
|
for j=1:length(expectationmodel.components)
|
|
|
|
expressions{j} = sprintf('%1.16f', M_.params(expectationmodel.components(j).h_param_indices(id)));
|
|
|
|
end
|
|
|
|
end
|
2021-11-25 16:16:42 +01:00
|
|
|
constant = 0;
|
|
|
|
for j=1:length(expectationmodel.components)
|
|
|
|
constant = constant + targetcoefficients(j)*M_.params(expectationmodel.components(j).h_param_indices(id));
|
|
|
|
end
|
|
|
|
end
|
2021-12-20 20:38:58 +01:00
|
|
|
if isfield(expectationmodel, 'h_param_indices')
|
|
|
|
expression = sprintf('%1.16f', constant);
|
|
|
|
end
|
2021-07-21 17:58:29 +02:00
|
|
|
end
|
|
|
|
|
2018-12-03 15:07:43 +01:00
|
|
|
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};
|
2022-01-13 19:09:18 +01:00
|
|
|
[variable, transformations] = rewrite_aux_variable(variable, M_);
|
2019-02-28 09:41:35 +01:00
|
|
|
switch expectationmodelkind
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'var'
|
2018-12-03 15:07:43 +01:00
|
|
|
parameter = M_.params(expectationmodel.param_indices(id));
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'pac'
|
2021-11-25 16:16:42 +01:00
|
|
|
if isfield(expectationmodel, 'h_param_indices')
|
|
|
|
parameter = M_.params(expectationmodel.h_param_indices(id));
|
|
|
|
else
|
|
|
|
parameter = 0;
|
|
|
|
for k=1:length(expectationmodel.components)
|
|
|
|
parameter = parameter+targetcoefficients(k)*M_.params(expectationmodel.components(k).h_param_indices(id));
|
|
|
|
end
|
|
|
|
end
|
2018-12-03 15:07:43 +01:00
|
|
|
otherwise
|
|
|
|
end
|
|
|
|
switch expectationmodelkind
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'var'
|
2021-10-24 19:29:31 +02:00
|
|
|
if timeindices(i)>0
|
|
|
|
variable = sprintf('dbase.%s(-%d)', variable, timeindices(i));
|
2018-12-03 15:07:43 +01:00
|
|
|
else
|
|
|
|
variable = sprintf('dbase.%s', variable);
|
|
|
|
end
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'pac'
|
2018-12-03 15:07:43 +01:00
|
|
|
variable = sprintf('dbase.%s(-%d)', variable, i);
|
|
|
|
otherwise
|
|
|
|
end
|
|
|
|
if ~isempty(transformations)
|
|
|
|
for k=length(transformations):-1:1
|
|
|
|
variable = sprintf('%s.%s()', variable, transformations{k});
|
|
|
|
end
|
|
|
|
end
|
2021-11-25 16:16:42 +01:00
|
|
|
if exist('expression','var')
|
|
|
|
if parameter>=0
|
|
|
|
expression = sprintf('%s+%1.16f*%s', expression, parameter, variable);
|
|
|
|
elseif parameter<0
|
|
|
|
expression = sprintf('%s-%1.16f*%s', expression, -parameter, variable);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if parameter>=0
|
|
|
|
expression = sprintf('%1.16f*%s', parameter, variable);
|
|
|
|
elseif parameter<0
|
|
|
|
expression = sprintf('-%1.16f*%s', -parameter, variable);
|
|
|
|
end
|
|
|
|
end
|
2021-12-20 20:38:58 +01:00
|
|
|
if decompose
|
|
|
|
for k=1:length(expectationmodel.components)
|
|
|
|
parameter = M_.params(expectationmodel.components(k).h_param_indices(id));
|
|
|
|
if parameter>=0
|
|
|
|
expressions{k} = sprintf('%s+%1.16f*%s', expressions{k}, parameter, variable);;
|
|
|
|
else
|
|
|
|
expressions{k} = sprintf('%s-%1.16f*%s', expressions{k}, -parameter, variable);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-11-25 16:16:42 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if isequal(expectationmodelkind, 'pac') && growth_correction
|
|
|
|
if isfield(expectationmodel, 'growth_neutrality_param_index')
|
|
|
|
pgrowth = M_.params(expectationmodel.growth_neutrality_param_index);
|
|
|
|
for iter = 1:numel(expectationmodel.growth_linear_comb)
|
|
|
|
vgrowth='';
|
2022-01-17 16:52:28 +01:00
|
|
|
variable = [];
|
2021-11-25 16:16:42 +01:00
|
|
|
if expectationmodel.growth_linear_comb(iter).exo_id > 0
|
2022-01-13 19:09:18 +01:00
|
|
|
variable = M_.exo_names{expectationmodel.growth_linear_comb(iter).exo_id};
|
2021-11-25 16:16:42 +01:00
|
|
|
elseif expectationmodel.growth_linear_comb(iter).endo_id > 0
|
2022-01-13 19:09:18 +01:00
|
|
|
variable = M_.endo_names{expectationmodel.growth_linear_comb(iter).endo_id};
|
2021-11-25 16:16:42 +01:00
|
|
|
end
|
2022-01-17 16:52:28 +01:00
|
|
|
if ~isempty(variable)
|
|
|
|
[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})
|
2022-01-19 09:20:22 +01:00
|
|
|
variable = sprintf('%s.diff()', variable);
|
2022-01-17 16:52:28 +01:00
|
|
|
else
|
2022-01-19 09:20:22 +01:00
|
|
|
variable = sprintf('%s.lag(%u).diff()', variable, transformations{k,2});
|
2022-01-17 16:52:28 +01:00
|
|
|
end
|
2022-01-13 19:09:18 +01:00
|
|
|
else
|
2022-01-17 16:52:28 +01:00
|
|
|
variable = sprintf('%s.%s()', variable, transformations{k});
|
2022-01-13 19:09:18 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-01-17 16:52:28 +01:00
|
|
|
vgrowth = strcat('dbase.', variable);
|
2021-11-25 16:16:42 +01:00
|
|
|
end
|
|
|
|
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);
|
|
|
|
else
|
|
|
|
vgrowth = num2str(M_.params(expectationmodel.growth_linear_comb(iter).param_id), '%1.16f');
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if abs(expectationmodel.growth_linear_comb(iter).constant) ~= 1
|
|
|
|
if ~isempty(vgrowth)
|
|
|
|
vgrowth = sprintf('%1.16f*%s', expectationmodel.growth_linear_comb(iter).constant, vgrowth);
|
|
|
|
else
|
|
|
|
vgrowth = num2str(expectationmodel.growth_linear_comb(iter).constant, '%1.16f');
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if iter > 1
|
|
|
|
if expectationmodel.growth_linear_comb(iter).constant > 0
|
|
|
|
linearCombination = sprintf('%s+%s', linearCombination, vgrowth);
|
|
|
|
else
|
|
|
|
linearCombination = sprintf('%s-%s', linearCombination, vgrowth);
|
|
|
|
end
|
|
|
|
else
|
2022-01-17 16:52:28 +01:00
|
|
|
linearCombination = vgrowth;
|
|
|
|
end
|
2021-11-25 16:16:42 +01:00
|
|
|
end % loop over growth linear combination elements
|
|
|
|
growthcorrection = sprintf('%1.16f*(%s)', pgrowth, linearCombination);
|
|
|
|
else
|
|
|
|
first = true;
|
|
|
|
for i=1:length(expectationmodel.components)
|
2021-12-20 20:38:58 +01:00
|
|
|
if ~isequal(expectationmodel.components(i).kind, 'll') && isfield(expectationmodel.components(i), 'growth_neutrality_param_index') && isfield(expectationmodel.components(i), 'growth_linear_comb') && ~isempty(expectationmodel.components(i).growth_linear_comb)
|
2021-11-25 16:16:42 +01:00
|
|
|
pgrowth = targetcoefficients(i)*M_.params(expectationmodel.components(i).growth_neutrality_param_index);
|
|
|
|
for iter = 1:numel(expectationmodel.components(i).growth_linear_comb)
|
2019-10-07 16:45:24 +02:00
|
|
|
vgrowth='';
|
2022-01-17 16:52:28 +01:00
|
|
|
variable=[];
|
2021-11-25 16:16:42 +01:00
|
|
|
if expectationmodel.components(i).growth_linear_comb(iter).exo_id > 0
|
2022-01-13 19:09:18 +01:00
|
|
|
variable = M_.exo_names{expectationmodel.components(i).growth_linear_comb(iter).exo_id};
|
2021-11-25 16:16:42 +01:00
|
|
|
elseif expectationmodel.components(i).growth_linear_comb(iter).endo_id > 0
|
2022-01-13 19:09:18 +01:00
|
|
|
variable = M_.endo_names{expectationmodel.components(i).growth_linear_comb(iter).endo_id};
|
2019-03-02 22:36:13 +01:00
|
|
|
end
|
2022-01-17 16:52:28 +01:00
|
|
|
if ~isempty(variable)
|
|
|
|
[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})
|
2022-01-19 09:20:22 +01:00
|
|
|
variable = sprintf('%s.diff()', variable);
|
2022-01-17 16:52:28 +01:00
|
|
|
else
|
2022-01-19 09:20:22 +01:00
|
|
|
variable = sprintf('%s.lag(%u).diff()', variable, transformations{k,2});
|
2022-01-17 16:52:28 +01:00
|
|
|
end
|
2022-01-13 19:09:18 +01:00
|
|
|
else
|
2022-01-17 16:52:28 +01:00
|
|
|
variable = sprintf('%s.%s()', variable, transformations{k});
|
2022-01-13 19:09:18 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-01-17 16:52:28 +01:00
|
|
|
vgrowth = strcat('dbase.', variable);
|
2019-10-07 16:45:24 +02:00
|
|
|
end
|
2021-11-25 16:16:42 +01:00
|
|
|
if expectationmodel.components(i).growth_linear_comb(iter).param_id > 0
|
2019-10-07 16:45:24 +02:00
|
|
|
if ~isempty(vgrowth)
|
2021-11-25 16:16:42 +01:00
|
|
|
vgrowth = sprintf('%1.16f*%s',M_.params(expectationmodel.components(i).growth_linear_comb(iter).param_id), vgrowth);
|
2019-10-07 16:45:24 +02:00
|
|
|
else
|
2021-11-25 16:16:42 +01:00
|
|
|
vgrowth = num2str(M_.params(expectationmodel.components(i).growth_linear_comb(iter).param_id), '%1.16f');
|
2019-10-07 16:45:24 +02:00
|
|
|
end
|
2019-03-02 22:36:13 +01:00
|
|
|
end
|
2021-11-25 16:16:42 +01:00
|
|
|
if abs(expectationmodel.components(i).growth_linear_comb(iter).constant) ~= 1
|
2019-10-07 16:45:24 +02:00
|
|
|
if ~isempty(vgrowth)
|
2021-11-25 16:16:42 +01:00
|
|
|
vgrowth = sprintf('%1.16f*%s', expectationmodel.components(i).growth_linear_comb(iter).constant, vgrowth);
|
2019-10-07 16:45:24 +02:00
|
|
|
else
|
2021-11-25 16:16:42 +01:00
|
|
|
vgrowth = num2str(expectationmodel.components(i).growth_linear_comb(iter).constant, '%1.16f');
|
2019-10-07 16:45:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if iter > 1
|
2021-11-25 16:16:42 +01:00
|
|
|
if expectationmodel.components(i).growth_linear_comb(iter).constant > 0
|
2019-10-07 16:45:24 +02:00
|
|
|
linearCombination = sprintf('%s+%s', linearCombination, vgrowth);
|
|
|
|
else
|
|
|
|
linearCombination = sprintf('%s-%s', linearCombination, vgrowth);
|
|
|
|
end
|
|
|
|
else
|
2021-11-25 16:16:42 +01:00
|
|
|
linearCombination = vgrowth;
|
2019-10-07 16:45:24 +02:00
|
|
|
end
|
2021-11-25 16:16:42 +01:00
|
|
|
end % loop over growth linear combination elements
|
|
|
|
if first
|
|
|
|
growthcorrection = sprintf('%1.16f*(%s)', pgrowth, linearCombination);
|
|
|
|
first = false;
|
2019-10-07 16:45:24 +02:00
|
|
|
else
|
2021-11-25 16:16:42 +01:00
|
|
|
if pgrowth>0
|
|
|
|
growthcorrection = sprintf('%s+%1.16f*(%s)', growthcorrection, pgrowth, linearCombination);
|
|
|
|
elseif pgrowth<0
|
|
|
|
growthcorrection = sprintf('%s-%1.16f*(%s)', growthcorrection, -pgrowth, linearCombination);
|
|
|
|
end
|
2018-12-03 15:07:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-11-25 16:16:42 +01:00
|
|
|
expression = sprintf('%s+%s', expression, growthcorrection);
|
|
|
|
end % growth_correction
|
2018-12-03 15:07:43 +01:00
|
|
|
|
2021-12-20 20:38:58 +01:00
|
|
|
fprintf(fid, 'ds.%s = %s;\n', expectationmodelname, expression);
|
|
|
|
if exist('expressions', 'var')
|
|
|
|
for i=1:length(expressions)
|
|
|
|
fprintf(fid, 'ds.%s = %s;\n', M_.lhs{expectationmodel.components(i).aux_id}, expressions{i});
|
|
|
|
end
|
|
|
|
end
|
2019-02-22 17:58:24 +01:00
|
|
|
fclose(fid);
|
|
|
|
|
|
|
|
fprintf('Expectation dseries expression is saved in %s.\n', filename);
|
|
|
|
|
2019-09-24 18:09:42 +02:00
|
|
|
skipline();
|
2021-10-21 09:58:09 +02:00
|
|
|
|
2021-12-20 20:38:58 +01:00
|
|
|
rehash
|