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
|
|
|
|
% The routine creates two text files
|
|
|
|
%
|
|
|
|
% - {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).
|
|
|
|
%
|
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
|
|
|
|
|
2019-03-14 11:04:10 +01:00
|
|
|
if isequal(expectationmodelkind, 'pac')
|
2019-02-22 17:58:24 +01:00
|
|
|
% Get the equation tag (in M_.pac.(pacmodl).equations)
|
|
|
|
eqtag = M_.pac.(expectationmodelname).tag_map{strcmp(M_.pac.(expectationmodelname).tag_map(:,1), eqname),2};
|
|
|
|
end
|
|
|
|
|
2018-10-14 16:48:29 +02:00
|
|
|
% Get the expectation model description
|
|
|
|
expectationmodel = M_.(expectationmodelfield).(expectationmodelname);
|
|
|
|
|
|
|
|
% Get the name of the associated VAR model and test its existence.
|
|
|
|
if ~isfield(M_.(expectationmodel.auxiliary_model_type), expectationmodel.auxiliary_model_name)
|
|
|
|
switch expectationmodelkind
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'var'
|
2018-10-14 16:48:29 +02:00
|
|
|
error('Unknown VAR/TREND_COMPONENT model (%s) in VAR_EXPECTATION_MODEL (%s)!', expectationmodel.auxiliary_model_name, expectationmodelname)
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'pac'
|
2018-10-14 16:48:29 +02:00
|
|
|
error('Unknown VAR/TREND_COMPONENT model (%s) in PAC_EXPECTATION_MODEL (%s)!', expectationmodel.auxiliary_model_name, expectationmodelname)
|
|
|
|
otherwise
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
2019-03-14 11:04:10 +01:00
|
|
|
if isequal(expectationmodelkind, 'pac')
|
|
|
|
filename = sprintf('%s/model/%s/%s-%s-parameters.inc', M_.fname, [expectationmodelkind '-expectations'], eqtag, expectationmodelname);
|
2019-02-22 17:58:24 +01:00
|
|
|
else
|
2019-03-14 11:04:10 +01:00
|
|
|
filename = sprintf('%s/model/%s/%s-parameters.inc', M_.fname, [expectationmodelkind '-expectations'], expectationmodelname);
|
2019-02-22 17:58:24 +01:00
|
|
|
end
|
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'
|
2019-02-22 17:58:24 +01:00
|
|
|
if ~isempty(expectationmodel.equations.(eqtag).h0_param_indices)
|
2018-10-14 16:48:29 +02:00
|
|
|
parameter_declaration = 'parameters';
|
2019-02-22 17:58:24 +01:00
|
|
|
for i=1:length(expectationmodel.equations.(eqtag).h0_param_indices)
|
|
|
|
parameter_declaration = sprintf('%s %s', parameter_declaration, M_.param_names{expectationmodel.equations.(eqtag).h0_param_indices(i)});
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
fprintf(fid, '%s;\n\n', parameter_declaration);
|
|
|
|
if withcalibration
|
2019-02-22 17:58:24 +01:00
|
|
|
for i=1:length(expectationmodel.equations.(eqtag).h0_param_indices)
|
2019-10-07 16:45:24 +02:00
|
|
|
fprintf(fid, '%s = %1.16f;\n', M_.param_names{expectationmodel.equations.(eqtag).h0_param_indices(i)}, M_.params(expectationmodel.equations.(eqtag).h0_param_indices(i)));
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-22 17:58:24 +01:00
|
|
|
if ~isempty(expectationmodel.equations.(eqtag).h1_param_indices)
|
2018-10-14 16:48:29 +02:00
|
|
|
parameter_declaration = 'parameters';
|
2019-02-22 17:58:24 +01:00
|
|
|
for i=1:length(expectationmodel.equations.(eqtag).h1_param_indices)
|
|
|
|
parameter_declaration = sprintf('%s %s', parameter_declaration, M_.param_names{expectationmodel.equations.(eqtag).h1_param_indices(i)});
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
fprintf(fid, '%s;\n\n', parameter_declaration);
|
|
|
|
if withcalibration
|
2019-02-22 17:58:24 +01:00
|
|
|
for i=1:length(expectationmodel.equations.(eqtag).h1_param_indices)
|
2019-10-07 16:45:24 +02:00
|
|
|
fprintf(fid, '%s = %1.16f;\n', M_.param_names{expectationmodel.equations.(eqtag).h1_param_indices(i)}, M_.params(expectationmodel.equations.(eqtag).h1_param_indices(i)));
|
2018-10-14 16:48:29 +02:00
|
|
|
end
|
|
|
|
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;
|
|
|
|
end
|
|
|
|
otherwise
|
|
|
|
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
|
|
|
|
2019-03-14 11:04:10 +01:00
|
|
|
if isequal(expectationmodelkind, 'pac')
|
|
|
|
filename = sprintf('%s/model/%s/%s-%s-expression.inc', M_.fname, [expectationmodelkind '-expectations'], eqtag, expectationmodelname);
|
2019-02-22 17:58:24 +01:00
|
|
|
else
|
2019-03-14 11:04:10 +01:00
|
|
|
filename = sprintf('%s/model/%s/%s-expression.inc', M_.fname, [expectationmodelkind '-expectations'], expectationmodelname);
|
2019-02-22 17:58:24 +01:00
|
|
|
end
|
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'
|
|
|
|
expression = write_expectations(eqname, expectationmodelname, expectationmodelkind, true);
|
|
|
|
case 'pac'
|
|
|
|
[expression, growthneutralitycorrection] = write_expectations(eqname, 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
|
|
|
|
filename = sprintf('%s/model/%s/%s-%s-growth-neutrality-correction.inc', M_.fname, [expectationmodelkind '-expectations'], eqtag, 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'];
|
2018-12-19 11:43:26 +01:00
|
|
|
mkdir(sprintf('+%s/+%s/+%s', M_.fname, kind, expectationmodelname));
|
2019-03-14 11:04:10 +01:00
|
|
|
if isequal(expectationmodelkind, 'pac')
|
2019-02-22 17:58:24 +01:00
|
|
|
filename = sprintf('+%s/+%s/+%s/%s_evaluate.m', M_.fname, kind, expectationmodelname, eqtag);
|
|
|
|
else
|
|
|
|
filename = sprintf('+%s/+%s/+%s/evaluate.m', M_.fname, kind, expectationmodelname);
|
|
|
|
end
|
2018-12-03 15:07:43 +01:00
|
|
|
fid = fopen(filename, 'w');
|
2019-03-14 11:04:10 +01:00
|
|
|
if isequal(expectationmodelkind, 'pac')
|
2019-02-22 17:58:24 +01:00
|
|
|
fprintf(fid, 'function ds = %s_evaluate(dbase)\n\n', eqtag);
|
|
|
|
else
|
|
|
|
fprintf(fid, 'function ds = evaluate(dbase)\n\n');
|
|
|
|
end
|
2019-03-14 11:04:10 +01:00
|
|
|
if isequal(expectationmodelkind, 'pac')
|
2019-02-22 17:58:24 +01:00
|
|
|
fprintf(fid, '%% Evaluates %s term (%s in %s).\n', kind, expectationmodelname, eqname);
|
|
|
|
else
|
|
|
|
fprintf(fid, '%% Evaluates %s term (%s).\n', kind, expectationmodelname);
|
|
|
|
end
|
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;
|
|
|
|
|
|
|
|
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-07-21 17:58:29 +02:00
|
|
|
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
|
|
|
|
|
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};
|
|
|
|
transformations = {};
|
|
|
|
ida = get_aux_variable_id(variable);
|
2019-02-28 09:41:35 +01:00
|
|
|
op = 0;
|
2018-12-03 15:07:43 +01:00
|
|
|
while ida
|
2019-02-28 09:41:35 +01:00
|
|
|
op = op+1;
|
2018-12-03 15:07:43 +01:00
|
|
|
if isequal(M_.aux_vars(ida).type, 8)
|
2019-02-28 09:41:35 +01:00
|
|
|
transformations(op) = {'diff'};
|
2018-12-03 15:07:43 +01:00
|
|
|
variable = M_.endo_names{M_.aux_vars(ida).orig_index};
|
|
|
|
ida = get_aux_variable_id(variable);
|
|
|
|
elseif isequal(M_.aux_vars(ida).type, 10)
|
2019-02-28 09:41:35 +01:00
|
|
|
transformations(op) = {M_.aux_vars(ida).unary_op};
|
2018-12-03 15:07:43 +01:00
|
|
|
variable = M_.endo_names{M_.aux_vars(ida).orig_index};
|
|
|
|
ida = get_aux_variable_id(variable);
|
2019-02-28 09:24:12 +01:00
|
|
|
else
|
|
|
|
error('This case is not implemented.')
|
2018-12-03 15:07:43 +01:00
|
|
|
end
|
|
|
|
end
|
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'
|
2018-12-03 15:07:43 +01:00
|
|
|
parameter = 0;
|
2019-02-22 17:58:24 +01:00
|
|
|
if ~isempty(expectationmodel.equations.(eqtag).h0_param_indices)
|
|
|
|
parameter = M_.params(expectationmodel.equations.(eqtag).h0_param_indices(id));
|
2018-12-03 15:07:43 +01:00
|
|
|
end
|
2019-02-22 17:58:24 +01:00
|
|
|
if ~isempty(expectationmodel.equations.(eqtag).h1_param_indices)
|
2018-12-03 15:07:43 +01:00
|
|
|
if ~parameter
|
2019-02-22 17:58:24 +01:00
|
|
|
parameter = M_.params(expectationmodel.equations.(eqtag).h1_param_indices(id));
|
2018-12-03 15:07:43 +01:00
|
|
|
else
|
2019-02-22 17:58:24 +01:00
|
|
|
parameter = parameter+M_.params(expectationmodel.equations.(eqtag).h1_param_indices(id));
|
2018-12-03 15:07:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
otherwise
|
|
|
|
end
|
|
|
|
switch expectationmodelkind
|
2019-03-14 11:04:10 +01:00
|
|
|
case 'var'
|
2018-12-03 15:07:43 +01:00
|
|
|
if i>1
|
|
|
|
variable = sprintf('dbase.%s(-%d)', variable, i-1);
|
|
|
|
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
|
|
|
|
if isequal(id, 1)
|
2019-03-14 11:04:10 +01:00
|
|
|
if isequal(expectationmodelkind, 'pac') && growth_correction
|
2018-12-14 17:29:46 +01:00
|
|
|
pgrowth = M_.params(expectationmodel.growth_neutrality_param_index);
|
2019-10-07 16:45:24 +02:00
|
|
|
linearCombination = '';
|
|
|
|
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});
|
|
|
|
elseif expectationmodel.growth_linear_comb(iter).endo_id > 0
|
|
|
|
vgrowth = strcat('dbase.', M_.endo_names{expectationmodel.growth_linear_comb(iter).endo_id});
|
2019-03-02 22:36:13 +01:00
|
|
|
end
|
2019-10-07 16:45:24 +02:00
|
|
|
if expectationmodel.growth_linear_comb(iter).lag ~= 0
|
|
|
|
vgrowth = sprintf('%s(%d)', vgrowth, expectationmodel.growth_linear_comb(iter).lag);
|
|
|
|
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
|
2019-03-02 22:36:13 +01:00
|
|
|
end
|
2019-10-07 16:45:24 +02:00
|
|
|
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
|
|
|
|
linearCombination=vgrowth;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if parameter >= 0
|
|
|
|
expression = sprintf('%1.16f*(%s)+%1.16f*%s', pgrowth, linearCombination, parameter, variable);
|
|
|
|
else
|
|
|
|
expression = sprintf('%1.16f*(%s)-%1.16f*%s', pgrowth, linearCombination, -parameter, variable);
|
2018-12-03 15:07:43 +01:00
|
|
|
end
|
|
|
|
else
|
2019-10-07 16:45:24 +02:00
|
|
|
expression = sprintf('%1.16f*%s', parameter, variable);
|
2018-12-03 15:07:43 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if parameter>=0
|
2019-10-07 16:45:24 +02:00
|
|
|
expression = sprintf('%s+%1.16f*%s', expression, parameter, variable);
|
2018-12-03 15:07:43 +01:00
|
|
|
else
|
2019-10-07 16:45:24 +02:00
|
|
|
expression = sprintf('%s-%1.16f*%s', expression, -parameter, variable);
|
2018-12-03 15:07:43 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-19 10:53:09 +01:00
|
|
|
fprintf(fid, 'ds.%s = %s;', expectationmodelname, expression);
|
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();
|