From 63a116fb2840ed8300fd7c88532e8d4fe355bdaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Tue, 3 May 2022 17:46:59 +0200 Subject: [PATCH] =?UTF-8?q?New=20+=3D=20and=20*=3D=20syntaxes=20in=20?= =?UTF-8?q?=E2=80=9Cendval(learnt=5Fin=3D=E2=80=A6)=E2=80=9D=20blocks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/manual/source/the-model-file.rst | 30 +++++++++++++++---- ..._foresight_with_expectation_errors_setup.m | 12 +++++++- preprocessor | 2 +- .../pfwee_learnt_in.mod | 8 ++--- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/doc/manual/source/the-model-file.rst b/doc/manual/source/the-model-file.rst index 4fe506aeb9..0c41bd2b55 100644 --- a/doc/manual/source/the-model-file.rst +++ b/doc/manual/source/the-model-file.rst @@ -3915,6 +3915,7 @@ and ``endval`` blocks which are given a special ``learnt_in`` option. end; This syntax means that: + - from the perspective of period 1, ``x`` is expected to be equal to 1 in periods 1 and 2, to 1.2 in periods 3 and 4, and to 1.4 in period 5; - from the perspective of periods 2 (and 3), ``x`` is expected to be @@ -3925,23 +3926,40 @@ and ``endval`` blocks which are given a special ``learnt_in`` option. .. block:: endval(learnt_in=INTEGER) ; - |br| The ``endval(learnt_in=INTEGER)`` can be used to specify temporary - shocks that are learnt in a specific period. + |br| The ``endval(learnt_in=INTEGER)`` can be used to specify terminal + conditions that are learnt in a specific period. Note that an ``endval(learnt_in=1)`` block is equivalent to a regular :bck:`endval` block. + It is possible to express the terminal condition by specifying the level of + the exogenous variable (using an equal symbol, as in a regular + :bck:`endval` blocks without the ``learnt_in`` option). But it is also + possible to express the terminal condition as an addition to the value + expected from the perspective of the previous previous period (using the + ``+=`` operator), or as a multiplicative factor over that previously + expected value (using the ``*=`` operator). + *Example* :: - endval(learnt_in = 2); + endval(learnt_in = 3); x = 1.1; + y += 0.1; + z *= 2; end; - This syntax means that, in period 2, the agents learn that the terminal - condition for ``x`` will be 1.1. This value will be the realized one, - unless there is another ``endval(learnt_in=p)`` block with ``p>2``. + This syntax means that, in period 3, the agents learn that: + + - the terminal condition for ``x`` will be 1.1; + - the terminal condition for ``y`` will be 0.1 above the terminal + condition for ``y`` that was expected from the perspective of period 2; + - the terminal condition for ``z`` will be 2 times the terminal condition + for ``z`` that was expected from the perspective of period 2. + + Those values will be the realized ones, unless there is another + ``endval(learnt_in=p)`` block with ``p>3``. .. command:: perfect_foresight_with_expectation_errors_setup ; perfect_foresight_with_expectation_errors_setup (OPTIONS...); diff --git a/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m b/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m index 4664d627d1..2e7ad0b599 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m +++ b/matlab/perfect-foresight-models/perfect_foresight_with_expectation_errors_setup.m @@ -90,7 +90,17 @@ else idx = find([M_.learnt_endval.learnt_in] == p); for i = 1:length(idx) j = idx(i); - oo_.pfwee.terminal_info(M_.learnt_endval(j).exo_id, p) = M_.learnt_endval(j).value; + exo_id = M_.learnt_endval(j).exo_id; + switch M_.learnt_endval(j).type + case 'level' + oo_.pfwee.terminal_info(exo_id, p) = M_.learnt_endval(j).value; + case 'add' + oo_.pfwee.terminal_info(exo_id, p) = oo_.pfwee.terminal_info(exo_id, p) + M_.learnt_endval(j).value; + case 'multiply' + oo_.pfwee.terminal_info(exo_id, p) = oo_.pfwee.terminal_info(exo_id, p) * M_.learnt_endval(j).value; + otherwise + error('Unknown type in M_.learnt_endval') + end end end oo_.pfwee.shocks_info(:, :, p) = oo_.pfwee.shocks_info(:, :, p-1); diff --git a/preprocessor b/preprocessor index 8c07fb5e43..3a820fffa2 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit 8c07fb5e4310b2ec2988dc62256e1cf0971c05dd +Subproject commit 3a820fffa2f7291be5732c33bde552526eab1602 diff --git a/tests/deterministic_simulations/pfwee_learnt_in.mod b/tests/deterministic_simulations/pfwee_learnt_in.mod index 878beb00b7..5c7e396ddb 100644 --- a/tests/deterministic_simulations/pfwee_learnt_in.mod +++ b/tests/deterministic_simulations/pfwee_learnt_in.mod @@ -50,7 +50,7 @@ shocks(learnt_in = 3); end; endval(learnt_in = 3); - x = 1.2; + x += 0.1; end; // Dummy block, that will be overwritten by the next one @@ -67,7 +67,7 @@ shocks(learnt_in = 6, overwrite); end; endval(learnt_in = 6); - x = 1.1; + x *= 0.75; end; perfect_foresight_with_expectation_errors_setup(periods = 7); @@ -106,7 +106,7 @@ oo_.exo_simul = [ saved_exo; oo_.exo_simul ]; // Information arriving in period 3 (temp shocks + permanent shock in future) oo_.exo_simul(4,1) = 1.4; oo_.exo_simul(8,1) = 1.5; -oo_.exo_steady_state = 1.2; +oo_.exo_steady_state = 1.1+0.1; oo_.exo_simul(end, 1) = oo_.exo_steady_state; oo_.steady_state = evaluate_steady_state(oo_.steady_state, M_, options_, oo_, true); oo_.endo_simul(:, end) = oo_.steady_state; @@ -122,7 +122,7 @@ oo_.exo_simul = [ saved_exo; oo_.exo_simul ]; // Information arriving in period 6 (temp shocks + permanent shock) oo_.exo_simul(7,1) = 1*0.8; oo_.exo_simul(8,1) = 1.5*0.8; -oo_.exo_steady_state = 1.1; +oo_.exo_steady_state = (1.1+0.1)*0.75; oo_.exo_simul(end, 1) = oo_.exo_steady_state; oo_.steady_state = evaluate_steady_state(oo_.steady_state, M_, options_, oo_, true); oo_.endo_simul(:, end) = oo_.steady_state; -- GitLab