| 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 |
var_expectation_model(model_name = varexp, expression = diff(log(x)), auxiliary_model_name = toto, horizon = 1, discount = beta) ; |
| 21 |
|
| 22 |
model; |
| 23 |
[ name = 'X' ] |
| 24 |
diff(log(x)) = a*diff(log(x(-1))) + b*diff(log(x(-2))) + c*diff(z(-2)) + e_x; |
| 25 |
[ name = 'Z' ] |
| 26 |
diff(z) = f*diff(z(-1)) + e_z; |
| 27 |
[ name = 'Y' ] |
| 28 |
log(y) = d*log(y(-2)) + e*diff(z(-1)) + e_y; |
| 29 |
|
| 30 |
foo = var_expectation(varexp); |
| 31 |
end; |
| 32 |
|
| 33 |
// Initialize the VAR expectation model, will build the companion matrix of the VAR. |
| 34 |
var_expectation.initialize('varexp') |
| 35 |
|
| 36 |
// Update VAR_EXPECTATION reduced form parameters |
| 37 |
var_expectation.update('varexp'); |
| 38 |
|
| 39 |
// Print expanded VAR_EXPECTATION expression in a file (to be included in substitution.mod). |
| 40 |
var_expectation.print('varexp'); |
| 41 |
|
| 42 |
shocks; |
| 43 |
var e_x = .01; |
| 44 |
var e_y = .01; |
| 45 |
var e_z = .01; |
| 46 |
end; |
| 47 |
|
| 48 |
verbatim; |
| 49 |
initialconditions =zeros(3,4); |
| 50 |
initialconditions(3,1) = .1; % foo(-1) |
| 51 |
initialconditions(:,2) = .2; % y(-1) |
| 52 |
initialconditions(3,3) = .3; % z(-1) |
| 53 |
initialconditions(2,3) = .4; % z(-2) |
| 54 |
initialconditions(3,4) = .5; % x(-1) |
| 55 |
initialconditions(2,4) = .6; % x(-2) |
| 56 |
initialconditions(1,4) = .7; % x(-3) |
| 57 |
initialconditions = ... |
| 58 |
dseries(initialconditions, dates('2000Q1'), {'foo', 'y','z', 'x'}); |
| 59 |
set_dynare_seed('default'); |
| 60 |
ts = simul_backward_model(initialconditions, 15); |
| 61 |
foo = ts.foo.data; |
| 62 |
% Evaluate the (VAR) expectation term |
| 63 |
ts{'toto'} = example1.var_expectations.varexp.evaluate(ts); |
| 64 |
% Check tthat the evaluation is correct. |
| 65 |
range = dates('2000Q4'):dates('2004Q2'); |
| 66 |
if max(abs(ts(range).foo.data-ts(range).toto.data))>1e-5 |
| 67 |
error('Expectation term evaluations do not match!') |
| 68 |
end |
| 69 |
end; |