| 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 |
|
| 11 |
a_x1_0 = -.9; |
| 12 |
a_x1_0_ = -.8; |
| 13 |
a_x1_1 = .4; |
| 14 |
a_x1_2 = .3; |
| 15 |
a_x1_x2_1 = .1; |
| 16 |
a_x1_x2_2 = .2; |
| 17 |
|
| 18 |
|
| 19 |
a_x2_0 = -.9; |
| 20 |
a_x2_1 = .2; |
| 21 |
a_x2_2 = -.1; |
| 22 |
a_x2_x1_1 = -.1; |
| 23 |
a_x2_x1_2 = .2; |
| 24 |
|
| 25 |
beta = 1/(1+.02); |
| 26 |
|
| 27 |
// Define a TREND_COMPONENT model from a subset of equations in the model block. |
| 28 |
trend_component_model(model_name=toto, eqtags=['eq:x1', 'eq:x2', 'eq:x1bar', 'eq:x2bar'], targets=['eq:x1bar', 'eq:x2bar']); |
| 29 |
|
| 30 |
/* Define a VAR_EXPECTATION_MODEL |
| 31 |
** ------------------------------ |
| 32 |
** |
| 33 |
** model_name: the name of the VAR_EXPECTATION_MODEL (mandatory). |
| 34 |
** auxiliary_model_name: the name of the VAR model used for the expectations (mandatory). |
| 35 |
** variable: the name of the variable to be forecasted (mandatory). |
| 36 |
** horizon: the horizon forecast (mandatory). |
| 37 |
** discount: the discount factor, which can be a value or a declared parameter (default is 1.0, no discounting). |
| 38 |
** |
| 39 |
** |
| 40 |
** The `horizon` parameter can be an integer in which case the (discounted) `horizon` step ahead forecast |
| 41 |
** is computed using the VAR model `var_model_name`. Alternatively, `horizon` can be a range. In this case |
| 42 |
** VAR_EXPECTATION_MODEL returns a discounted sum of expected values. If `horizon` is set equal to the range |
| 43 |
** 0:Inf, then VAR_EXPECTATION_MODEL computes: |
| 44 |
** |
| 45 |
** ∑ βʰ Eₜ[yₜ₊ₕ] |
| 46 |
** |
| 47 |
** where the sum is over h=0,…,∞ and the conditional expectations are computed with VAR model `var_model_name`. |
| 48 |
*/ |
| 49 |
|
| 50 |
var_expectation_model(model_name = varexp, expression = x1, auxiliary_model_name = toto, time_shift=-1, horizon = 15:50, discount = beta) ; |
| 51 |
|
| 52 |
|
| 53 |
model; |
| 54 |
|
| 55 |
[name='eq:x1', data_type='nonstationary'] |
| 56 |
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; |
| 57 |
|
| 58 |
[name='eq:x2', data_type='nonstationary'] |
| 59 |
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; |
| 60 |
|
| 61 |
[name='eq:x1bar', data_type='nonstationary'] |
| 62 |
x1bar = x1bar(-1) + ex1bar; |
| 63 |
|
| 64 |
[name='eq:x2bar', data_type='nonstationary'] |
| 65 |
x2bar = x2bar(-1) + ex2bar; |
| 66 |
|
| 67 |
foo = .5*foo(-1) + var_expectation(varexp); |
| 68 |
end; |
| 69 |
|
| 70 |
// Initialize the VAR expectation model, will build the companion matrix of the VAR. |
| 71 |
var_expectation.initialize('varexp') |
| 72 |
|
| 73 |
// Update VAR_EXPECTATION reduced form parameters |
| 74 |
var_expectation.update('varexp'); |
| 75 |
|
| 76 |
weights = M_.params(M_.var_expectation.varexp.param_indices); |
| 77 |
|
| 78 |
if ~all(weights(1:6)) || ~all(weights(9:10)) || weights(7) || weights(8) || weights(11) || weights(12) |
| 79 |
error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL') |
| 80 |
end |
| 81 |
|
| 82 |
var_expectation.print('varexp'); |
| 83 |
|
| 84 |
shocks; |
| 85 |
var ex1 = .01; |
| 86 |
var ex2 = .01; |
| 87 |
var ex1bar = .02; |
| 88 |
var ex2bar = .02; |
| 89 |
end; |
| 90 |
|
| 91 |
|
| 92 |
verbatim; |
| 93 |
initialconditions =zeros(4,5); |
| 94 |
initialconditions(4,1) = .10; % foo(-1) |
| 95 |
initialconditions(4,2) = .20; % x1(-1) |
| 96 |
initialconditions(3,2) = .22; % x1(-2) |
| 97 |
initialconditions(2,2) = .24; % x1(-3) |
| 98 |
initialconditions(4,3) = .30; % x2(-1) |
| 99 |
initialconditions(3,3) = .32; % x2(-2) |
| 100 |
initialconditions(2,3) = .34; % x2(-3) |
| 101 |
initialconditions(4,4) = .25; % x1bar(-1) |
| 102 |
initialconditions(4,5) = .25; % x2bar(-1) |
| 103 |
initialconditions = ... |
| 104 |
dseries(initialconditions, dates('2000Q1'), {'foo', 'x1','x2', 'x1bar', 'x2bar'}); |
| 105 |
set_dynare_seed('default'); |
| 106 |
ts = simul_backward_model(initialconditions, 100); |
| 107 |
foo = ts.foo.data; |
| 108 |
save('example1.mat', 'foo'); |
| 109 |
end; |