From 3e2a75d33a53b070665b2ac7740c01462b2fd77b Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 24 Jul 2013 23:36:46 +0200 Subject: [PATCH 1/3] Fix bug in simult_ for purely forward looking models simult_ simulated one period too much, thinking there was a lag. This resulted in a crash trying to plot irfs. --- matlab/simult_.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matlab/simult_.m b/matlab/simult_.m index 86c38cc92..73f0959f3 100644 --- a/matlab/simult_.m +++ b/matlab/simult_.m @@ -54,7 +54,7 @@ if ~options_.k_order_solver || (options_.k_order_solver && options_.pruning) %if end if options_.k_order_solver && ~options_.pruning % Call dynare++ routines. - ex_ = [zeros(1,exo_nbr); ex_]; + ex_ = [zeros(M_.maximum_lag,M_.exo_nbr); ex_]; switch options_.order case 1 [err, y_] = dynare_simul_(1,M_.nstatic,M_.npred,M_.nboth,M_.nfwrd,exo_nbr, ... From 18664da6fecb1f3420af975dd79c47c490d78166 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 24 Jul 2013 23:38:37 +0200 Subject: [PATCH 2/3] Fix for theoretical autocovariances for purely forward looking models In this case, Ex will by empty, leading to non-conformable empty matrices. Solution: compute correction term without using non-existent states. --- matlab/th_autocovariances.m | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/matlab/th_autocovariances.m b/matlab/th_autocovariances.m index f89d6f609..eff41b89d 100644 --- a/matlab/th_autocovariances.m +++ b/matlab/th_autocovariances.m @@ -126,11 +126,16 @@ if options_.order == 2 || options_.hp_filter == 0 aa = ghx(iky,:); bb = ghu(iky,:); if options_.order == 2 % mean correction for 2nd order - Ex = (dr.ghs2(ikx)+dr.ghxx(ikx,:)*vx(:)+dr.ghuu(ikx,:)*M_.Sigma_e(:))/2; - Ex = (eye(n0)-AS(ikx,:))\Ex; - Gamma_y{nar+3} = NaN*ones(nvar, 1); - Gamma_y{nar+3}(stationary_vars) = AS(iky,:)*Ex+(dr.ghs2(iky)+dr.ghxx(iky,:)*vx(:)+... - dr.ghuu(iky,:)*M_.Sigma_e(:))/2; + if ~isempty(ikx) + Ex = (dr.ghs2(ikx)+dr.ghxx(ikx,:)*vx(:)+dr.ghuu(ikx,:)*M_.Sigma_e(:))/2; + Ex = (eye(n0)-AS(ikx,:))\Ex; + Gamma_y{nar+3} = NaN*ones(nvar, 1); + Gamma_y{nar+3}(stationary_vars) = AS(iky,:)*Ex+(dr.ghs2(iky)+dr.ghxx(iky,:)*vx(:)+... + dr.ghuu(iky,:)*M_.Sigma_e(:))/2; + else %no static and no predetermined + Gamma_y{nar+3} = NaN*ones(nvar, 1); + Gamma_y{nar+3}(stationary_vars) = (dr.ghs2(iky)+ dr.ghuu(iky,:)*M_.Sigma_e(:))/2; + end end end if options_.hp_filter == 0 From 07a05d554e7bdce96bb7c33d7d4142afeeeb1a2b Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 24 Jul 2013 23:39:39 +0200 Subject: [PATCH 3/3] Add unit tests for stochastic simulations of purely forward looking models Adds one for purely forward looking models and one for purely forward looking model with additional static variable --- .../stochastic_purely_forward.mod | 37 +++++++++++++++++++ .../stochastic_purely_forward_with_static.mod | 36 ++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 tests/stochastic_purely_forward/stochastic_purely_forward.mod create mode 100644 tests/stochastic_purely_forward/stochastic_purely_forward_with_static.mod diff --git a/tests/stochastic_purely_forward/stochastic_purely_forward.mod b/tests/stochastic_purely_forward/stochastic_purely_forward.mod new file mode 100644 index 000000000..388070d4e --- /dev/null +++ b/tests/stochastic_purely_forward/stochastic_purely_forward.mod @@ -0,0 +1,37 @@ +var a; +varexo epsil ; +parameters betta; +betta = 0.97; + +model; +a = betta*a(+1)+epsil; +end; + +initval; +a=0; +end; +steady; + +shocks; +var epsil; stderr .2; +end; + +steady; +check; + +stoch_simul(periods=0, irf=30, order=1); +stoch_simul(periods=2000, irf=30, order=1); +stoch_simul(periods=0, irf=30, order=2); +stoch_simul(periods=2000, irf=30, order=2); +stoch_simul(periods=0, irf=30, order=3); +stoch_simul(periods=2000, irf=30, order=3); + + +stoch_simul(periods=0, irf=30, order=1,hp_filter=1600); +stoch_simul(periods=2000, irf=30, order=1,hp_filter=1600); +stoch_simul(periods=0, irf=30, order=2,hp_filter=1600); +stoch_simul(periods=2000, irf=30, order=2,hp_filter=1600); +stoch_simul(periods=0, irf=30, order=3,hp_filter=1600); +stoch_simul(periods=2000, irf=30, order=3,hp_filter=1600); + + diff --git a/tests/stochastic_purely_forward/stochastic_purely_forward_with_static.mod b/tests/stochastic_purely_forward/stochastic_purely_forward_with_static.mod new file mode 100644 index 000000000..22b5bf7ba --- /dev/null +++ b/tests/stochastic_purely_forward/stochastic_purely_forward_with_static.mod @@ -0,0 +1,36 @@ +var a b; +varexo epsil ; +parameters betta; +betta = 0.97; + +model; +a = betta*a(+1)+epsil; +b = a; +end; + +initval; +a=0; +end; +steady; + +shocks; +var epsil; stderr .2; +end; + +steady; +check; + +stoch_simul(periods=0, irf=30, order=1); +stoch_simul(periods=2000, irf=30, order=1); +stoch_simul(periods=0, irf=30, order=2); +stoch_simul(periods=2000, irf=30, order=2); +stoch_simul(periods=0, irf=30, order=3); +stoch_simul(periods=2000, irf=30, order=3); + + +stoch_simul(periods=0, irf=30, order=1,hp_filter=1600); +stoch_simul(periods=2000, irf=30, order=1,hp_filter=1600); +stoch_simul(periods=0, irf=30, order=2,hp_filter=1600); +stoch_simul(periods=2000, irf=30, order=2,hp_filter=1600); +stoch_simul(periods=0, irf=30, order=3,hp_filter=1600); +stoch_simul(periods=2000, irf=30, order=3,hp_filter=1600);