From 351da3b865e750217eaaa09138afe91684927ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemia=20=28Scylla=29?= Date: Wed, 19 Dec 2018 10:53:09 +0100 Subject: [PATCH] Do not update a dseries object, but instantiate a new object. --- matlab/print_expectations.m | 11 ++++++----- tests/var-expectations/10/example.mod | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/matlab/print_expectations.m b/matlab/print_expectations.m index d0b1024cd..80756c4e9 100644 --- a/matlab/print_expectations.m +++ b/matlab/print_expectations.m @@ -244,24 +244,25 @@ fprintf(fid, '%s', expression); 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, '-', '_'); mkdir(sprintf('+%s/+%s', M_.fname, kind)); filename = sprintf('+%s/+%s/evaluate_%s.m', M_.fname, kind, expectationmodelname); fid = fopen(filename, 'w'); -fprintf(fid, 'function dbase = evaluate_%s(dbase)\n\n', expectationmodelname); -fprintf(fid, '%% Evaluates %s term (%s), updating a dseries object.\n', kind, expectationmodelname); +fprintf(fid, 'function ds = evaluate_%s(dbase)\n\n', expectationmodelname); +fprintf(fid, '%% Evaluates %s term (%s).\n', kind, expectationmodelname); 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'); -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, '%% 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)); +fprintf(fid, 'ds = dseries();\n\n'); id = 0; @@ -351,5 +352,5 @@ for i=1:maxlag end end -fprintf(fid, 'dbase.%s = %s;', expectationmodelname, expression); +fprintf(fid, 'ds.%s = %s;', expectationmodelname, expression); fclose(fid); \ No newline at end of file diff --git a/tests/var-expectations/10/example.mod b/tests/var-expectations/10/example.mod index bbb715e57..23246fb82 100644 --- a/tests/var-expectations/10/example.mod +++ b/tests/var-expectations/10/example.mod @@ -56,14 +56,14 @@ verbatim; initialconditions(1,4) = .7; % x(-3) initialconditions = ... dseries(initialconditions, dates('2000Q1'), {'foo', 'y','z', 'x'}); - set_dynare_seed('default'); + set_dynare_seed('default'); ts = simul_backward_model(initialconditions, 15); foo = ts.foo.data; % 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. 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!') end end; \ No newline at end of file