| 1 |
// --+ options: json=compute, stochastic +-- |
| 2 |
|
| 3 |
PLOTS = true; |
| 4 |
|
| 5 |
var x1 x2 x3 x1bar x2bar z y x u v s; |
| 6 |
|
| 7 |
varexo ex1 |
| 8 |
ex2 |
| 9 |
ex1bar (used='estimationonly') |
| 10 |
ex2bar (used='estimationonly') |
| 11 |
ez |
| 12 |
ey |
| 13 |
ex |
| 14 |
eu |
| 15 |
ev |
| 16 |
es; |
| 17 |
|
| 18 |
parameters |
| 19 |
rho_1 rho_2 rho_3 rho_4 |
| 20 |
a_x1_0 a_x1_1 a_x1_2 a_x1_x2_1 a_x1_x2_2 |
| 21 |
a_x2_0 a_x2_1 a_x2_2 a_x2_x1_1 a_x2_x1_2 |
| 22 |
e_c_m c_z_1 c_z_2 c_z_dx2 c_z_u c_z_dv c_z_s cx cy beta |
| 23 |
lambda; |
| 24 |
|
| 25 |
rho_1 = .9; |
| 26 |
rho_2 = -.2; |
| 27 |
rho_3 = .4; |
| 28 |
rho_4 = -.3; |
| 29 |
|
| 30 |
|
| 31 |
a_x1_0 = -.9; |
| 32 |
a_x1_1 = .4; |
| 33 |
a_x1_2 = .3; |
| 34 |
a_x1_x2_1 = .1; |
| 35 |
a_x1_x2_2 = .2; |
| 36 |
|
| 37 |
a_x2_0 = -.9; |
| 38 |
a_x2_1 = .2; |
| 39 |
a_x2_2 = -.1; |
| 40 |
a_x2_x1_1 = -.1; |
| 41 |
a_x2_x1_2 = .2; |
| 42 |
|
| 43 |
beta = .2; |
| 44 |
e_c_m = .5; |
| 45 |
c_z_1 = .2; |
| 46 |
c_z_2 = -.1; |
| 47 |
c_z_dx2 = .3; |
| 48 |
c_z_u = .3; |
| 49 |
c_z_dv = .4; |
| 50 |
c_z_s = -.2; |
| 51 |
cx = 1.0; |
| 52 |
cy = 1.0; |
| 53 |
|
| 54 |
|
| 55 |
lambda = 0.5; // Share of optimizing agents. |
| 56 |
|
| 57 |
trend_component_model(model_name=toto, eqtags=['eq:x1', 'eq:x2', 'eq:x1bar', 'eq:x2bar'], targets=['eq:x1bar', 'eq:x2bar']); |
| 58 |
|
| 59 |
pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman); |
| 60 |
|
| 61 |
model; |
| 62 |
|
| 63 |
[name='eq:s'] |
| 64 |
s = .3*s(-1) - .1*s(-2) + es; |
| 65 |
|
| 66 |
[name='eq:diff(v)'] |
| 67 |
diff(v) = .5*diff(v(-1)) + ev; |
| 68 |
|
| 69 |
[name='eq:u'] |
| 70 |
u = .5*u(-1) - .2*u(-2) + eu; |
| 71 |
|
| 72 |
[name='eq:y'] |
| 73 |
y = rho_1*y(-1) + rho_2*y(-2) + ey; |
| 74 |
|
| 75 |
[name='eq:x'] |
| 76 |
x = rho_3*x(-1) + rho_4*x(-2) + ex; |
| 77 |
|
| 78 |
[name='eq:x1'] |
| 79 |
diff(x1) = a_x1_0*(x1(-1)-x1bar(-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; |
| 80 |
|
| 81 |
[name='eq:x2'] |
| 82 |
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; |
| 83 |
|
| 84 |
[name='eq:x3'] |
| 85 |
diff(log(x3)) = x ; |
| 86 |
|
| 87 |
[name='eq:x1bar'] |
| 88 |
x1bar = x1bar(-1) + ex1bar; |
| 89 |
|
| 90 |
[name='eq:x2bar'] |
| 91 |
x2bar = x2bar(-1) + ex2bar; |
| 92 |
|
| 93 |
[name='zpac'] |
| 94 |
diff(z) = lambda*(e_c_m*(x1(-1)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + c_z_s*s + c_z_dv*diff(v) ) + (1-lambda)*( cy*y + cx*x) + c_z_u*u + c_z_dx2*diff(x2) + ez; |
| 95 |
|
| 96 |
end; |
| 97 |
|
| 98 |
shocks; |
| 99 |
var ex1 = 1.0; |
| 100 |
var ex2 = 1.0; |
| 101 |
var ex1bar = 1.0; |
| 102 |
var ex2bar = 1.0; |
| 103 |
var ez = 1.0; |
| 104 |
var ey = 0.1; |
| 105 |
var ex = 0.01; |
| 106 |
var eu = 0.05; |
| 107 |
var ev = 0.05; |
| 108 |
var es = 0.07; |
| 109 |
end; |
| 110 |
|
| 111 |
// Initialize the PAC model (build the Companion VAR representation for the auxiliary model). |
| 112 |
pac.initialize('pacman'); |
| 113 |
|
| 114 |
// Update the parameters of the PAC expectation model (h0 and h1 vectors). |
| 115 |
pac.update.expectation('pacman'); |
| 116 |
|
| 117 |
// Set initial conditions to zero for non logged variables, and one for logged variables |
| 118 |
init = ones(10, M_.endo_nbr+M_.exo_nbr); |
| 119 |
initialconditions = dseries(init, 2000Q1, vertcat(M_.endo_names,M_.exo_names)); |
| 120 |
|
| 121 |
// Simulate the model for 500 periods |
| 122 |
options_.dynatol.f = 1e-9; |
| 123 |
TrueData = simul_backward_model(initialconditions, 5000); |
| 124 |
TrueData_ = copy(TrueData); |
| 125 |
|
| 126 |
TrueData = equation.evaluate(TrueData, 'eq:x3', 2004Q1); |
| 127 |
|
| 128 |
if PLOTS |
| 129 |
|
| 130 |
figure(1) |
| 131 |
plot(TrueData_.x.data(12:end), TrueData_.x3.data(12:end)-TrueData.x3.data(12:end), '.k', 'linewidth', 2); |
| 132 |
|
| 133 |
figure(2) |
| 134 |
plot(TrueData_.x.data(12:end), '-k', 'linewidth', 2); |
| 135 |
|
| 136 |
figure(3) |
| 137 |
plot([TrueData_.x3.data(12:end)-TrueData.x3.data(12:end)], '-k', 'linewidth', 2); |
| 138 |
|
| 139 |
end |
| 140 |
|
| 141 |
fprintf('Max. abs. error is %s.\n', num2str(max(abs(TrueData.x3.data(12:end)-TrueData_.x3.data(12:end))), 16)); |
| 142 |
|
| 143 |
if max(abs(TrueData.x3.data(12:end)-TrueData_.x3.data(12:end)))>1e-5 |
| 144 |
error('equation.evaluate() returned wrong values.') |
| 145 |
end |