| 1 |
// --+ options: stochastic,transform_unary_ops,json=compute +-- |
| 2 |
|
| 3 |
var foo x1 x2 x1bar x2bar; |
| 4 |
|
| 5 |
varexo ex1 ex2 ex1bar ex2bar; |
| 6 |
|
| 7 |
parameters a_x1_0 a_x1_0_ a_x1_1 a_x1_2 a_x1_x2_1 a_x1_x2_2 |
| 8 |
a_x2_0 a_x2_1 a_x2_2 a_x2_x1_1 a_x2_x1_2 |
| 9 |
beta |
| 10 |
alpha ; |
| 11 |
|
| 12 |
a_x1_0 = -.9; |
| 13 |
a_x1_0_ = -.8; |
| 14 |
a_x1_1 = .4; |
| 15 |
a_x1_2 = .3; |
| 16 |
a_x1_x2_1 = .1; |
| 17 |
a_x1_x2_2 = .2; |
| 18 |
|
| 19 |
|
| 20 |
a_x2_0 = -.9; |
| 21 |
a_x2_1 = .2; |
| 22 |
a_x2_2 = -.1; |
| 23 |
a_x2_x1_1 = -.1; |
| 24 |
a_x2_x1_2 = .2; |
| 25 |
|
| 26 |
beta = 1/(1+.02); |
| 27 |
alpha = .5; |
| 28 |
|
| 29 |
// Define a TREND_COMPONENT model from a subset of equations in the model block. |
| 30 |
trend_component_model(model_name=toto, eqtags=['eq:x1', 'eq:x2', 'eq:x1bar', 'eq:x2bar'], targets=['eq:x1bar', 'eq:x2bar']); |
| 31 |
|
| 32 |
/* Define a VAR_EXPECTATION_MODEL |
| 33 |
** ------------------------------ |
| 34 |
** |
| 35 |
** model_name: the name of the VAR_EXPECTATION_MODEL (mandatory). |
| 36 |
** auxiliary_model_name: the name of the VAR model used for the expectations (mandatory). |
| 37 |
** variable: the name of the variable to be forecasted (mandatory). |
| 38 |
** horizon: the horizon forecast (mandatory). |
| 39 |
** discount: the discount factor, which can be a value or a declared parameter (default is 1.0, no discounting). |
| 40 |
** |
| 41 |
** |
| 42 |
** The `horizon` parameter can be an integer in which case the (discounted) `horizon` step ahead forecast |
| 43 |
** is computed using the VAR model `var_model_name`. Alternatively, `horizon` can be a range. In this case |
| 44 |
** VAR_EXPECTATION_MODEL returns a discounted sum of expected values. If `horizon` is set equal to the range |
| 45 |
** 0:Inf, then VAR_EXPECTATION_MODEL computes: |
| 46 |
** |
| 47 |
** ∑ βʰ Eₜ[yₜ₊ₕ] |
| 48 |
** |
| 49 |
** where the sum is over h=0,…,∞ and the conditional expectations are computed with VAR model `var_model_name`. |
| 50 |
*/ |
| 51 |
|
| 52 |
var_expectation_model(model_name = varexp, expression = x1/100-alpha*x2, auxiliary_model_name = toto, horizon = 15:50, discount = beta) ; |
| 53 |
|
| 54 |
|
| 55 |
model; |
| 56 |
|
| 57 |
[name='eq:x1', data_type='nonstationary'] |
| 58 |
diff(x1) = a_x1_0*(x1(-1)-x1bar(-1))+a_x1_0_*(x2(-1)-x2bar(-1)) + a_x1_1*diff(x1(-1)) + a_x1_2*diff(x1(-2)) + + a_x1_x2_1*diff(x2(-1)) + a_x1_x2_2*diff(x2(-2)) + ex1; |
| 59 |
|
| 60 |
[name='eq:x2', data_type='nonstationary'] |
| 61 |
diff(x2) = a_x2_0*(x2(-1)-x2bar(-1)) + a_x2_1*diff(x1(-1)) + a_x2_2*diff(x1(-2)) + a_x2_x1_1*diff(x2(-1)) + a_x2_x1_2*diff(x2(-2)) + ex2; |
| 62 |
|
| 63 |
[name='eq:x1bar', data_type='nonstationary'] |
| 64 |
x1bar = x1bar(-1) + ex1bar; |
| 65 |
|
| 66 |
[name='eq:x2bar', data_type='nonstationary'] |
| 67 |
x2bar = x2bar(-1) + ex2bar; |
| 68 |
|
| 69 |
foo = .5*foo(-1) + var_expectation(varexp); |
| 70 |
end; |
| 71 |
|
| 72 |
// Initialize the VAR expectation model, will build the companion matrix of the VAR. |
| 73 |
var_expectation.initialize('varexp') |
| 74 |
|
| 75 |
// Update VAR_EXPECTATION reduced form parameters |
| 76 |
var_expectation.update('varexp'); |
| 77 |
|
| 78 |
weights = M_.params(M_.var_expectation.varexp.param_indices); |
| 79 |
|
| 80 |
if ~all(weights(1:6)) || ~all(weights(9:10)) || weights(7) || weights(8) || weights(11) || weights(12) |
| 81 |
error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL') |
| 82 |
end |