From 349cd25b8a8d23df4969372560b9d739821b8cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=28Charybdis=29?= Date: Thu, 9 Aug 2018 09:05:39 +0200 Subject: [PATCH] Added an integration test for VAR_EXPECTATION_MODEL. + small cosmetic changes. --- tests/Makefile.am | 1 + tests/var-expectations/1/example.mod | 6 +-- tests/var-expectations/2/example.mod | 6 +-- tests/var-expectations/3/example.mod | 6 +-- tests/var-expectations/4/example.mod | 6 +-- tests/var-expectations/5/example.mod | 71 ++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 tests/var-expectations/5/example.mod diff --git a/tests/Makefile.am b/tests/Makefile.am index 46af90c33..7407dfeb3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -357,6 +357,7 @@ MODFILES = \ var-expectations/2/example.mod \ var-expectations/3/example.mod \ var-expectations/4/example.mod \ + var-expectations/5/example.mod \ dynare-command-options/ramst.mod PARTICLEFILES = \ diff --git a/tests/var-expectations/1/example.mod b/tests/var-expectations/1/example.mod index 28181f71f..bc3e84a92 100644 --- a/tests/var-expectations/1/example.mod +++ b/tests/var-expectations/1/example.mod @@ -31,7 +31,7 @@ var_model(model_name = toto, eqtags = [ 'X' 'Y' 'Z' ]); ** VAR_EXPECTATION_MODEL returns a discounted sum of expected values. If `horizon` is set equal to the range ** 0:Inf, then VAR_EXPECTATION_MODEL computes: ** -** ∑ βʰ Eₜ[yₜ₊ₕ] +** ∑ βʰ Eₜ[yₜ₊ₕ] ** ** where the sum is over h=0,…,∞ and the conditional expectations are computed with VAR model `var_model_name`. */ @@ -58,7 +58,7 @@ get_companion_matrix('toto'); // Update VAR_EXPECTATION reduced form parameters var_expectation.update('varexp'); -/* +/* ** REMARK The VAR model is such that x depends on past values of x ** (xₜ₋₁ and xₜ₋₂) and on zₜ₋₂ ⇒ yₜ₋₁, yₜ₋₂ and zₜ₋₁ do not bring any ** useful information for predicting xₜ₊₁. Consequently the reduced @@ -67,6 +67,6 @@ var_expectation.update('varexp'); weights = M_.params(M_.var_expectation.varexp.param_indices); -if weights(2) || weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6) +if weights(2) || weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6) error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL') end \ No newline at end of file diff --git a/tests/var-expectations/2/example.mod b/tests/var-expectations/2/example.mod index 57cfd1df6..34bbd3269 100644 --- a/tests/var-expectations/2/example.mod +++ b/tests/var-expectations/2/example.mod @@ -31,7 +31,7 @@ var_model(model_name = toto, eqtags = [ 'X' 'Y' 'Z' ]); ** VAR_EXPECTATION_MODEL returns a discounted sum of expected values. If `horizon` is set equal to the range ** 0:Inf, then VAR_EXPECTATION_MODEL computes: ** -** ∑ βʰ Eₜ[yₜ₊ₕ] +** ∑ βʰ Eₜ[yₜ₊ₕ] ** ** where the sum is over h=0,…,∞ and the conditional expectations are computed with VAR model `var_model_name`. */ @@ -58,7 +58,7 @@ get_companion_matrix('toto'); // Update VAR_EXPECTATION reduced form parameters var_expectation.update('varexp'); -/* +/* ** REMARK The VAR model is such that x depends on past values of x ** (xₜ₋₁ and xₜ₋₂) and on zₜ₋₂ ⇒ yₜ₋₁, yₜ₋₂ and zₜ₋₁ do not bring any ** useful information for predicting xₜ₊₁. Consequently the reduced @@ -67,6 +67,6 @@ var_expectation.update('varexp'); weights = M_.params(M_.var_expectation.varexp.param_indices); -if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6) +if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6) error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL') end \ No newline at end of file diff --git a/tests/var-expectations/3/example.mod b/tests/var-expectations/3/example.mod index 83119fd14..0bc3bfd2a 100644 --- a/tests/var-expectations/3/example.mod +++ b/tests/var-expectations/3/example.mod @@ -31,7 +31,7 @@ var_model(model_name = toto, eqtags = [ 'X' 'Y' 'Z' ]); ** VAR_EXPECTATION_MODEL returns a discounted sum of expected values. If `horizon` is set equal to the range ** 0:Inf, then VAR_EXPECTATION_MODEL computes: ** -** ∑ βʰ Eₜ[yₜ₊ₕ] +** ∑ βʰ Eₜ[yₜ₊ₕ] ** ** where the sum is over h=0,…,∞ and the conditional expectations are computed with VAR model `var_model_name`. */ @@ -58,7 +58,7 @@ get_companion_matrix('toto'); // Update VAR_EXPECTATION reduced form parameters var_expectation.update('varexp'); -/* +/* ** REMARK The VAR model is such that x depends on past values of x ** (xₜ₋₁ and xₜ₋₂) and on zₜ₋₂. Consequently the reduced ** form parameters associated to yₜ₋₁, yₜ₋₂ have to be zero. @@ -66,7 +66,7 @@ var_expectation.update('varexp'); weights = M_.params(M_.var_expectation.varexp.param_indices); -if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6) +if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6) error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL') end diff --git a/tests/var-expectations/4/example.mod b/tests/var-expectations/4/example.mod index a38f88ac0..415197aab 100644 --- a/tests/var-expectations/4/example.mod +++ b/tests/var-expectations/4/example.mod @@ -31,7 +31,7 @@ var_model(model_name = toto, eqtags = [ 'X' 'Y' 'Z' ]); ** VAR_EXPECTATION_MODEL returns a discounted sum of expected values. If `horizon` is set equal to the range ** 0:Inf, then VAR_EXPECTATION_MODEL computes: ** -** ∑ βʰ Eₜ[yₜ₊ₕ] +** ∑ βʰ Eₜ[yₜ₊ₕ] ** ** where the sum is over h=0,…,∞ and the conditional expectations are computed with VAR model `var_model_name`. */ @@ -58,7 +58,7 @@ get_companion_matrix('toto'); // Update VAR_EXPECTATION reduced form parameters var_expectation.update('varexp'); -/* +/* ** REMARK The VAR model is such that x depends on past values of x ** (xₜ₋₁ and xₜ₋₂) and on zₜ₋₂. Consequently the reduced ** form parameters associated to yₜ₋₁, yₜ₋₂ have to be zero. @@ -66,7 +66,7 @@ var_expectation.update('varexp'); weights = M_.params(M_.var_expectation.varexp.param_indices); -if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6) +if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6) error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL') end diff --git a/tests/var-expectations/5/example.mod b/tests/var-expectations/5/example.mod new file mode 100644 index 000000000..3e4f620c6 --- /dev/null +++ b/tests/var-expectations/5/example.mod @@ -0,0 +1,71 @@ +// --+ options: stochastic,json=compute +-- + +var foo z x y; +varexo e_x e_y e_z; +parameters a b c d e f beta ; + +a = .9; +b = -.2; +c = .3; +f = .8; +d = .5; +e = .4; + +beta = 1/(1+.02); + +// Define a VAR model from a subset of equations in the model block. +var_model(model_name = toto, eqtags = [ 'X' 'Y' 'Z' ]); + +/* Define a VAR_EXPECTATION_MODEL +** ------------------------------ +** +** model_name: the name of the VAR_EXPECTATION_MODEL (mandatory). +** var_model_name: the name of the VAR model used for the expectations (mandatory). +** variable: the name of the variable to be forecasted (mandatory). +** horizon: the horizon forecast (mandatory). +** discount: the discount factor, which can be a value or a declared parameter (default is 1.0, no discounting). +** +** +** The `horizon` parameter can be an integer in which case the (discounted) `horizon` step ahead forecast +** is computed using the VAR model `var_model_name`. Alternatively, `horizon` can be a range. In this case +** VAR_EXPECTATION_MODEL returns a discounted sum of expected values. If `horizon` is set equal to the range +** 0:Inf, then VAR_EXPECTATION_MODEL computes: +** +** ∑ βʰ Eₜ[yₜ₊ₕ] +** +** where the sum is over h=0,…,∞ and the conditional expectations are computed with VAR model `var_model_name`. +*/ + +var_expectation_model(model_name = varexp, variable = x, var_model_name = toto, horizon = 15:50, discount = beta) ; + + +model; +[ name = 'X' ] +x = a*x(-1) + b*x(-2) + c*z(-2) + e_x; +[ name = 'Z' ] +z = f*z(-1) + e_z; +[ name = 'Y' ] +y = d*y(-2) + e*z(-1) + e_y; + +foo = .5*foo(-1) + var_expectation(varexp); +end; + + +// Build the companion matrix of the VAR model (toto). +get_companion_matrix('toto'); + + +// Update VAR_EXPECTATION reduced form parameters +var_expectation.update('varexp'); + +/* +** REMARK The VAR model is such that x depends on past values of x +** (xₜ₋₁ and xₜ₋₂) and on zₜ₋₂. Consequently the reduced +** form parameters associated to yₜ₋₁, yₜ₋₂ have to be zero. +*/ + +weights = M_.params(M_.var_expectation.varexp.param_indices); + +if weights(2) || ~weights(3) || weights(5) || ~weights(1) || ~weights(4) || ~weights(6) + error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL') +end \ No newline at end of file