| 1 |
// --+ options: stochastic,json=compute +-- |
| 2 |
|
| 3 |
var foo z x y; |
| 4 |
varexo e_x e_y e_z; |
| 5 |
parameters a b c d e f beta ; |
| 6 |
|
| 7 |
a = .9; |
| 8 |
b = -.2; |
| 9 |
c = .3; |
| 10 |
f = .8; |
| 11 |
d = .5; |
| 12 |
e = .4; |
| 13 |
|
| 14 |
beta = 1/(1+.02); |
| 15 |
|
| 16 |
// Define a VAR model from a subset of equations in the model block. |
| 17 |
var_model(model_name = toto, eqtags = [ 'X' 'Y' 'Z' ]); |
| 18 |
|
| 19 |
/* Define a VAR_EXPECTATION_MODEL |
| 20 |
** ------------------------------ |
| 21 |
** |
| 22 |
** model_name: the name of the VAR_EXPECTATION_MODEL (mandatory). |
| 23 |
** var_model_name: the name of the VAR model used for the expectations (mandatory). |
| 24 |
** variable: the name of the variable to be forecasted (mandatory). |
| 25 |
** horizon: the horizon forecast (mandatory). |
| 26 |
** discount: the discount factor, which can be a value or a declared parameter (default is 1.0, no discounting). |
| 27 |
** |
| 28 |
** |
| 29 |
** The `horizon` parameter can be an integer in which case the (discounted) `horizon` step ahead forecast |
| 30 |
** is computed using the VAR model `var_model_name`. Alternatively, `horizon` can be a range. In this case |
| 31 |
** VAR_EXPECTATION_MODEL returns a discounted sum of expected values. If `horizon` is set equal to the range |
| 32 |
** 0:Inf, then VAR_EXPECTATION_MODEL computes: |
| 33 |
** |
| 34 |
** ∑ βʰ Eₜ[yₜ₊ₕ] |
| 35 |
** |
| 36 |
** where the sum is over h=0,…,∞ and the conditional expectations are computed with VAR model `var_model_name`. |
| 37 |
*/ |
| 38 |
|
| 39 |
var_expectation_model(model_name = varexp, expression = x, auxiliary_model_name = toto, horizon = 2, discount = beta) ; |
| 40 |
|
| 41 |
|
| 42 |
model; |
| 43 |
[ name = 'X' ] |
| 44 |
x = a*x(-1) + b*x(-2) + c*z(-2) + e_x; |
| 45 |
[ name = 'Z' ] |
| 46 |
z = f*z(-1) + e_z; |
| 47 |
[ name = 'Y' ] |
| 48 |
y = d*y(-2) + e*z(-1) + e_y; |
| 49 |
|
| 50 |
foo = .5*foo(-1) + var_expectation(varexp); |
| 51 |
end; |
| 52 |
|
| 53 |
|
| 54 |
// Initialize the VAR expectation model, will build the companion matrix of the VAR. |
| 55 |
var_expectation.initialize('varexp') |
| 56 |
|
| 57 |
// Update VAR_EXPECTATION reduced form parameters |
| 58 |
var_expectation.update('varexp'); |
| 59 |
|
| 60 |
// Print equations where the variable appears in |
| 61 |
search('x') |
| 62 |
search('y', 'withparamvalues') |
| 63 |
|
| 64 |
/* |
| 65 |
** REMARK The VAR model is such that x depends on past values of x |
| 66 |
** (xₜ₋₁ and xₜ₋₂) and on zₜ₋₂ ⇒ yₜ₋₁, yₜ₋₂ and zₜ₋₁ do not bring any |
| 67 |
** useful information for predicting xₜ₊₁. Consequently the reduced |
| 68 |
** form parameters associated to yₜ₋₁, yₜ₋₂ and zₜ₋₁ have to be zero. |
| 69 |
*/ |
| 70 |
|
| 71 |
weights = M_.params(M_.var_expectation.varexp.param_indices); |
| 72 |
|
| 73 |
if weights(3) || ~weights(4) || weights(6) || ~weights(2) || ~weights(5) || ~weights(7) || weights(1) |
| 74 |
error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL') |
| 75 |
end |