| 1 |
// Uses autonomous system from sim_base.mod, but adds separate system where exogenous variables have several leads and lags |
| 2 |
// Lags and leads on exogenous variables are substituted out by auxiliary variables |
| 3 |
|
| 4 |
data1 = repmat([1.2, 1.2, 12, 1, 1, 1], 208, 1); |
| 5 |
data1(6, 6) = 0.9; //shock to x in period 2 |
| 6 |
ds = dseries(data1, '1Y', {'c', 'cmav', 'k', 'z_backward', 'z_forward', 'x'}); |
| 7 |
|
| 8 |
var c cmav k z_backward z_forward; |
| 9 |
varexo x; |
| 10 |
|
| 11 |
parameters alph gam delt bet aa; |
| 12 |
alph=0.5; |
| 13 |
gam=0.5; |
| 14 |
delt=0.02; |
| 15 |
bet=0.05; |
| 16 |
aa=0.5; |
| 17 |
|
| 18 |
model; |
| 19 |
c + k - aa*x*k(-1)^alph - (1-delt)*k(-1); |
| 20 |
c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam); |
| 21 |
z_backward=0.1*1+0.9*z_backward(-1) + (x(-4) - 1); |
| 22 |
z_forward=0.2*1+0.8*z_forward(+1) + (x(+4) - 1); |
| 23 |
cmav = 0.2*(c(-2) + c(-1) + c + c(+1) + c(+2)); |
| 24 |
end; |
| 25 |
|
| 26 |
initval_file(series = ds); |
| 27 |
if oo_.initval_series.dates(1) ~= dates('1Y'); |
| 28 |
error('Wrong initial date in oo_.initval_series'); |
| 29 |
end; |
| 30 |
if oo_.initval_series{'x'}.data(6) ~= 0.9; |
| 31 |
error('Wrong value for x'); |
| 32 |
end; |
| 33 |
|
| 34 |
perfect_foresight_setup(periods=200); |
| 35 |
perfect_foresight_solver(maxit=100); |
| 36 |
|
| 37 |
if ~oo_.deterministic_simulation.status |
| 38 |
error('Perfect foresight simulation failed'); |
| 39 |
end |
| 40 |
|
| 41 |
base_results=load(['sim_exo_lead_lag' filesep 'Output' filesep 'sim_exo_lead_lag_results.mat']); |
| 42 |
if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8 |
| 43 |
error('Simulation with leads and lags doesn''t match the one with auxiliary variables') |
| 44 |
end |
| 45 |
|
| 46 |
data1 = repmat([1.2, 1.2, 12, 1, 1, 1], 212, 1); |
| 47 |
data1(8, 6) = 0.9; //shock to x in period 2 |
| 48 |
ds1 = dseries(data1, '1Y', {'c', 'cmav', 'k', 'z_backward', 'z_forward', 'x'}); |
| 49 |
|
| 50 |
initval_file(series = ds1, first_obs = 3, last_obs = 210, nobs = 208); |
| 51 |
if oo_.initval_series.dates(1) ~= dates('3Y'); |
| 52 |
error('Wrong initial date in oo_.initval_series'); |
| 53 |
end; |
| 54 |
if oo_.initval_series{'x'}.data(6) ~= 0.9; |
| 55 |
error('Wrong value for x'); |
| 56 |
end; |
| 57 |
|
| 58 |
|
| 59 |
perfect_foresight_setup(periods=200); |
| 60 |
perfect_foresight_solver(maxit=100); |
| 61 |
|
| 62 |
if ~oo_.deterministic_simulation.status |
| 63 |
error('Perfect foresight simulation failed'); |
| 64 |
end |
| 65 |
|
| 66 |
base_results=load(['sim_exo_lead_lag' filesep 'Output' filesep 'sim_exo_lead_lag_results.mat']); |
| 67 |
if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8 |
| 68 |
error('Simulation with leads and lags doesn''t match the one with auxiliary variables') |
| 69 |
end |
| 70 |
|
| 71 |
initval_file(series = ds1, first_obs = 3Y, last_obs = 210Y, nobs = 208); |
| 72 |
if oo_.initval_series.dates(1) ~= dates('3Y'); |
| 73 |
error('Wrong initial date in oo_.initval_series'); |
| 74 |
end; |
| 75 |
if oo_.initval_series{'x'}.data(6) ~= 0.9; |
| 76 |
error('Wrong value for x'); |
| 77 |
end; |
| 78 |
|
| 79 |
|
| 80 |
perfect_foresight_setup(periods=200); |
| 81 |
perfect_foresight_solver(maxit=100); |
| 82 |
|
| 83 |
if ~oo_.deterministic_simulation.status |
| 84 |
error('Perfect foresight simulation failed'); |
| 85 |
end |
| 86 |
|
| 87 |
base_results=load(['sim_exo_lead_lag' filesep 'Output' filesep 'sim_exo_lead_lag_results.mat']); |
| 88 |
if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8 |
| 89 |
error('Simulation with leads and lags doesn''t match the one with auxiliary variables') |
| 90 |
end |
| 91 |
|
| 92 |
initval_file(series = ds1, first_simulation_period = 7); |
| 93 |
if oo_.initval_series.dates(1) ~= dates('3Y'); |
| 94 |
error('Wrong initial date in oo_.initval_series'); |
| 95 |
end; |
| 96 |
if oo_.initval_series{'x'}.data(6) ~= 0.9; |
| 97 |
error('Wrong value for x'); |
| 98 |
end; |
| 99 |
|
| 100 |
|
| 101 |
perfect_foresight_setup(periods=200); |
| 102 |
perfect_foresight_solver(maxit=100); |
| 103 |
|
| 104 |
if ~oo_.deterministic_simulation.status |
| 105 |
error('Perfect foresight simulation failed'); |
| 106 |
end |
| 107 |
|
| 108 |
base_results=load(['sim_exo_lead_lag' filesep 'Output' filesep 'sim_exo_lead_lag_results.mat']); |
| 109 |
if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8 |
| 110 |
error('Simulation with leads and lags doesn''t match the one with auxiliary variables') |
| 111 |
end |
| 112 |
|
| 113 |
initval_file(series = ds1, first_simulation_period = 7Y); |
| 114 |
if oo_.initval_series.dates(1) ~= dates('3Y'); |
| 115 |
error('Wrong initial date in oo_.initval_series'); |
| 116 |
end; |
| 117 |
if oo_.initval_series{'x'}.data(6) ~= 0.9; |
| 118 |
error('Wrong value for x'); |
| 119 |
end; |
| 120 |
|
| 121 |
|
| 122 |
perfect_foresight_setup(periods=200); |
| 123 |
perfect_foresight_solver(maxit=100); |
| 124 |
|
| 125 |
if ~oo_.deterministic_simulation.status |
| 126 |
error('Perfect foresight simulation failed'); |
| 127 |
end |
| 128 |
|
| 129 |
base_results=load(['sim_exo_lead_lag' filesep 'Output' filesep 'sim_exo_lead_lag_results.mat']); |
| 130 |
if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8 |
| 131 |
error('Simulation with leads and lags doesn''t match the one with auxiliary variables') |
| 132 |
end |
| 133 |
|