Debian Codegraph @

tests/var-expectations/3-with-time-shift/example1.mod

raw
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 ** time_shift: shifts the information set to the past, must be a non positive scalar. By default, expectations
28 ** about `variable` in period `t+horizon` are formed in period t (time_shift=0)
29 **
30 ** The `horizon` parameter can be an integer in which case the (discounted) `horizon` step ahead forecast
31 ** is computed using the VAR model `var_model_name`. Alternatively, `horizon` can be a range. In this case
32 ** VAR_EXPECTATION_MODEL returns a discounted sum of expected values. If `horizon` is set equal to the range
33 ** 0:Inf, then VAR_EXPECTATION_MODEL computes:
34 **
35 ** ∑ βʰ Eₜ[yₜ₊ₕ]
36 **
37 ** where the sum is over h=0,…,∞ and the conditional expectations are computed with VAR model `var_model_name`.
38 */
39
40 var_expectation_model(model_name = varexp, expression = x, auxiliary_model_name = toto, time_shift=-1, horizon = 0:Inf, discount = beta) ;
41
42
43 model;
44 [ name = 'X' ]
45 x = a*x(-1) + b*x(-2) + c*z(-2) + e_x;
46 [ name = 'Z' ]
47 z = f*z(-1) + e_z;
48 [ name = 'Y' ]
49 y = d*y(-2) + e*z(-1) + e_y;
50
51 foo = .5*foo(-1) + var_expectation(varexp);
52 end;
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 /*
61 ** REMARK The VAR model is such that x depends on past values of x
62 ** (xₜ₋₁ and xₜ₋₂) and on zₜ₋₂. Consequently the reduced
63 ** form parameters associated to yₜ₋₁, yₜ₋₂ have to be zero.
64 */
65
66 weights = M_.params(M_.var_expectation.varexp.param_indices);
67
68 if weights(3) || ~weights(4) || weights(6) || ~weights(2) || ~weights(5) || ~weights(7) || weights(1)
69 error('Wrong reduced form parameter for VAR_EXPECTATION_MODEL')
70 end
71
72 save('weights.mat','weights');