Do not unroll expectations in the equation where they are used...
... But create an auxiliary variable with corresponding equation (where the expectation are unrolled). Also separate the growth neutrality correction.time-shift
parent
567ca19000
commit
07a40d2df4
|
@ -64,6 +64,8 @@ elist = {};
|
|||
xlist = {};
|
||||
|
||||
for i=1:length(eqtags)
|
||||
rhs = [];
|
||||
lhs = [];
|
||||
% Get the original equation.
|
||||
[LHS, RHS] = get_lhs_and_rhs(eqtags{i}, M_, true);
|
||||
% Get the parameters, endogenous and exogenous variables in the current equation.
|
||||
|
@ -87,12 +89,40 @@ for i=1:length(eqtags)
|
|||
isvar = regexp(RHS, 'var_expectation\(model_name = (?<name>\w+)\)', 'names');
|
||||
ispac = regexp(RHS, 'pac_expectation\(model_name = (?<name>\w+)\)', 'names');
|
||||
if ~isempty(isvar)
|
||||
expression = write_expectations(eqtags{i}, isvar.name, 'var');
|
||||
RHS = strrep(RHS, sprintf('var_expectation(model_name = %s)', isvar.name), expression);
|
||||
rhs = write_expectations(eqtags{i}, isvar.name, 'var');
|
||||
lhs = sprintf('var_expectation_%s', eqtags{i});
|
||||
RHS = strrep(RHS, sprintf('var_expectation(model_name = %s)', isvar.name), lhs);
|
||||
else
|
||||
if ~isempty(ispac)
|
||||
expression = write_expectations(eqtags{i}, ispac.name, 'pac');
|
||||
RHS = strrep(RHS, sprintf('pac_expectation(model_name = %s)', ispac.name), expression);
|
||||
[rhs, growthneutralitycorrection] = write_expectations(eqtags{i}, ispac.name, 'pac');
|
||||
lhs = sprintf('pac_expectation_%s', eqtags{i});
|
||||
RHS = strrep(RHS, sprintf('pac_expectation(model_name = %s)', ispac.name), lhs);
|
||||
if ~isempty(growthneutralitycorrection)
|
||||
RHS = sprintf('%s + %s', RHS, growthneutralitycorrection);
|
||||
end
|
||||
end
|
||||
end
|
||||
% Print equation for unrolled PAC/VAR-expectation and update
|
||||
% list of parameters and endogenous variables (if any).
|
||||
if ~isempty(rhs)
|
||||
[expectation_pnames, expectation_enames] = get_variables_and_parameters_in_equation(lhs, rhs, M_);
|
||||
pnames = union(pnames, expectation_pnames);
|
||||
enames = union(enames, expectation_enames);
|
||||
fprintf(fid, '%s = %s;\n\n', lhs, rhs);
|
||||
end
|
||||
% Update pnames, enames and xnames if PAC with growth neutrality correction.
|
||||
if ~isempty(ispac) && ~isempty(growthneutralitycorrection)
|
||||
[growthneutralitycorrection_pnames, ...
|
||||
growthneutralitycorrection_enames, ...
|
||||
growthneutralitycorrection_xnames] = get_variables_and_parameters_in_equation('', growthneutralitycorrection, M_);
|
||||
if ~isempty(growthneutralitycorrection_pnames)
|
||||
pnames = union(pnames, growthneutralitycorrection_pnames);
|
||||
end
|
||||
if ~isempty(growthneutralitycorrection_enames)
|
||||
enames = union(enames, growthneutralitycorrection_enames);
|
||||
end
|
||||
if ~isempty(growthneutralitycorrection_xnames)
|
||||
xnames = union(xnames, growthneutralitycorrection_xnames);
|
||||
end
|
||||
end
|
||||
% Print equation.
|
||||
|
@ -102,7 +132,6 @@ for i=1:length(eqtags)
|
|||
elist = union(elist, enames);
|
||||
xlist = union(xlist, xnames);
|
||||
end
|
||||
|
||||
fclose(fid);
|
||||
|
||||
fid = fopen(sprintf('%s/parameters.inc', outfold), 'w');
|
||||
|
|
|
@ -39,8 +39,9 @@ rhs_ = strsplit(rhs,{'+','-','*','/','^', ...
|
|||
'sin(', 'cos(', 'tan(', 'asin(', 'acos(', 'atan(', ...
|
||||
'min(', 'max(', ...
|
||||
'normcdf(', 'normpdf(', 'erf(', ...
|
||||
'diff(', 'adl(', '(', ')'});
|
||||
'diff(', 'adl(', '(', ')', '\n', '\t', ' '});
|
||||
|
||||
% Get the tokens in the lhs member of the equation.
|
||||
lhs_ = strsplit(lhs, {'+','-','*','/','^', ...
|
||||
'log(', 'log10(', 'ln(', 'exp(', ...
|
||||
'sqrt(', 'abs(', 'sign(', ...
|
||||
|
@ -76,7 +77,9 @@ if ~isempty(id)
|
|||
end
|
||||
|
||||
% Add lhs variable in first position of enames.
|
||||
enames = [lhs_; enames];
|
||||
if ~isempty(lhs_)
|
||||
enames = [lhs_; enames];
|
||||
end
|
||||
|
||||
% Returns vector of indices for parameters endogenous and exogenous
|
||||
% variables if required.
|
||||
|
|
Loading…
Reference in New Issue