Do not update a dseries object, but instantiate a new object.

time-shift
Stéphane Adjemia (Scylla) 2018-12-19 10:53:09 +01:00
parent 4775bca073
commit 351da3b865
Signed by untrusted user who does not match committer: stepan
GPG Key ID: A6D44CB9C64CE77B
2 changed files with 9 additions and 8 deletions

View File

@ -244,24 +244,25 @@ fprintf(fid, '%s', expression);
fclose(fid); fclose(fid);
% %
% Third print a routine for evaluating VAR_EXPECTATION/PAC_EXPECTATION term (updates a dseries object). % Third print a routine for evaluating VAR_EXPECTATION/PAC_EXPECTATION term (returns a dseries object).
% %
kind = strrep(expectationmodelkind, '-', '_'); kind = strrep(expectationmodelkind, '-', '_');
mkdir(sprintf('+%s/+%s', M_.fname, kind)); mkdir(sprintf('+%s/+%s', M_.fname, kind));
filename = sprintf('+%s/+%s/evaluate_%s.m', M_.fname, kind, expectationmodelname); filename = sprintf('+%s/+%s/evaluate_%s.m', M_.fname, kind, expectationmodelname);
fid = fopen(filename, 'w'); fid = fopen(filename, 'w');
fprintf(fid, 'function dbase = evaluate_%s(dbase)\n\n', expectationmodelname); fprintf(fid, 'function ds = evaluate_%s(dbase)\n\n', expectationmodelname);
fprintf(fid, '%% Evaluates %s term (%s), updating a dseries object.\n', kind, expectationmodelname); fprintf(fid, '%% Evaluates %s term (%s).\n', kind, expectationmodelname);
fprintf(fid, '%%\n'); fprintf(fid, '%%\n');
fprintf(fid, '%% INPUTS\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, '%% - dbase [dseries] databse containing all the variables appearing in the auxiliary model for the expectation.\n');
fprintf(fid, '%%\n'); fprintf(fid, '%%\n');
fprintf(fid, '%% OUTPUTS\n'); fprintf(fid, '%% OUTPUTS\n');
fprintf(fid, '%% - dbase [dseries] same databse augmented with the expectation term .\n'); fprintf(fid, '%% - ds [dseries] the expectation term .\n');
fprintf(fid, '%%\n'); fprintf(fid, '%%\n');
fprintf(fid, '%% REMARKS\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, '%% 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)); fprintf(fid, '%% This file has been generated by dynare (%s).\n\n', datestr(now));
fprintf(fid, 'ds = dseries();\n\n');
id = 0; id = 0;
@ -351,5 +352,5 @@ for i=1:maxlag
end end
end end
fprintf(fid, 'dbase.%s = %s;', expectationmodelname, expression); fprintf(fid, 'ds.%s = %s;', expectationmodelname, expression);
fclose(fid); fclose(fid);

View File

@ -56,14 +56,14 @@ verbatim;
initialconditions(1,4) = .7; % x(-3) initialconditions(1,4) = .7; % x(-3)
initialconditions = ... initialconditions = ...
dseries(initialconditions, dates('2000Q1'), {'foo', 'y','z', 'x'}); dseries(initialconditions, dates('2000Q1'), {'foo', 'y','z', 'x'});
set_dynare_seed('default'); set_dynare_seed('default');
ts = simul_backward_model(initialconditions, 15); ts = simul_backward_model(initialconditions, 15);
foo = ts.foo.data; foo = ts.foo.data;
% Evaluate the (VAR) expectation term % Evaluate the (VAR) expectation term
ts = example.var_expectations.evaluate_varexp(ts); ts{'toto'} = example.var_expectations.evaluate_varexp(ts);
% Check tthat the evaluation is correct. % Check tthat the evaluation is correct.
range = dates('2000Q4'):dates('2004Q2'); range = dates('2000Q4'):dates('2004Q2');
if max(abs(ts(range).foo.data-ts(range).varexp.data))>1e-5 if max(abs(ts(range).foo.data-ts(range).toto.data))>1e-5
error('Expectation term evaluations do not match!') error('Expectation term evaluations do not match!')
end end
end; end;