Debian Codegraph @

tests/occbin/filter/NKM.mod

raw
1 @#include "NKM_common.inc"
2
3 options_.TeX=1;
4
5 // -----------------Occbin ----------------------------------------------//
6 options_.occbin.smoother.debug=1;
7 occbin_setup(likelihood_piecewise_kalman_filter);
8
9 // use PKF
10 estimation(
11 datafile=dataobsfile, mode_file=NKM_mh_mode_saved,
12 mode_compute=0, nobs=120, first_obs=1,
13 mh_replic=0, plot_priors=0, smoother,
14 consider_all_endogenous,filter_step_ahead=[1:8],smoothed_state_uncertainty);
15
16 // plot regimes
17 occbin.plot_regimes(oo_.occbin.smoother.regime_history,M_,options_)
18
19 // forecast starting from period 42, zero shocks (default)
20 smoother2histval(period=42);
21 [forecast, error_flag] = occbin.forecast(options_,M_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state,8);
22 // forecast with stochastic shocks
23 options_.occbin.forecast.qmc=true;
24 options_.occbin.forecast.replic=127;
25 [forecast1, error_flag] = occbin.forecast(options_,M_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state,8);
26
27 figure('Name','OccBin: Forecasts')
28 subplot(2,1,1)
29 plot(1:8,forecast.piecewise.Mean.inom,'b-',1:8,forecast1.piecewise.Mean.inom,'r--')
30 subplot(2,1,2)
31 plot(1:8,forecast.piecewise.Mean.y,'b-',1:8,forecast1.piecewise.Mean.y,'r--')
32
33 // GIRF given states in 42 and shocks in 43
34 t0=42;
35 options_.occbin.irf.exo_names=M_.exo_names;
36 options_.occbin.irf.t0=t0;
37 oo_.occbin.irfs = occbin.irf(M_,oo_,options_);
38
39 var_list_ = {'c','n','y','pigap','inom','inomnot'};
40
41 // if you want to scale ...
42 // options_occbin_.plot_irf.endo_scaling_factor = vars_irf(:,3);
43 options_.occbin.plot_irf.simulname = ['t0_' int2str(t0)];
44 options_.irf=40;
45 occbin.plot_irfs(M_,oo_.occbin.irfs,options_,var_list_);
46 var_list_={};
47 options_.occbin.plot_irf.simulname = ['t0_' int2str(t0) '_full'];
48 occbin.plot_irfs(M_,oo_.occbin.irfs,options_,var_list_);
49 oo0=oo_;
50 // use smoother_redux
51 estimation(
52 datafile=dataobsfile, mode_file=NKM_mh_mode_saved,
53 mode_compute=0, nobs=120, first_obs=1,
54 mh_replic=0, plot_priors=0, smoother, smoother_redux,
55 consider_all_endogenous,filter_step_ahead=[1:8],smoothed_state_uncertainty);
56
57 // check consistency of smoother_redux
58 for k=1:M_.endo_nbr,
59 mer(k)=max(abs(oo_.SmoothedVariables.(M_.endo_names{k})-oo0.SmoothedVariables.(M_.endo_names{k})));
60 end
61 if max(mer)>1.e-10
62 error('smoother redux does not recover full smoother results!')
63 else
64 disp('smoother redux successfully recovers full smoother results!')
65 end
66
67 for k=1:M_.endo_nbr,
68 mer(k)=max(abs(oo_.UpdatedVariables.(M_.endo_names{k})-oo0.UpdatedVariables.(M_.endo_names{k})));
69 end
70 if max(mer)>1.e-10
71 error('smoother redux does not recover full updated variables results!')
72 else
73 disp('smoother redux successfully recovers full updated variables results!')
74 end
75
76
77 for k=1:M_.endo_nbr,
78 mer(k)=max(abs(oo_.FilteredVariables.(M_.endo_names{k})-oo0.FilteredVariables.(M_.endo_names{k})));
79 end
80 if max(mer)>1.e-10
81 error('smoother redux does not recover full filtered variables results!')
82 else
83 disp('smoother redux successfully recovers full filtered variables results!')
84 end
85
86 for k=1:M_.endo_nbr,
87 mer(k)=max(max(max(abs(oo_.FilteredVariablesKStepAhead(:,k,:)-oo0.FilteredVariablesKStepAhead(:,k,:)))));
88 end
89 if max(mer)>1.e-10
90 error('smoother redux does not recover full k-step ahead variables results!')
91 else
92 disp('smoother redux successfully recovers full k-step ahead variables results!')
93 end
94
95 //run PKF with MCMC
96 options_.smoother_redux=false;
97 estimation(
98 datafile=dataobsfile, mode_file=NKM_mh_mode_saved,
99 mode_compute=0, nobs=120, first_obs=1,
100 mh_replic=50, plot_priors=0, smoother,
101 consider_all_endogenous,filter_step_ahead=[1:8],smoothed_state_uncertainty);
102
103 // use inversion filter (note that IF provides smoother together with likelihood)
104 occbin_setup(likelihood_inversion_filter,smoother_inversion_filter);
105
106 estimation(
107 datafile=dataobsfile, mode_file=NKM_mh_mode_saved,
108 mode_compute=0, nobs=120, first_obs=1,
109 mh_replic=50, plot_priors=0, smoother,
110 consider_all_endogenous,filter_step_ahead=[1:8],smoothed_state_uncertainty);
111
112 // show initial condition effect of IF
113 figure('Name','OccBin: Smoothed shocks')
114 subplot(221)
115 plot([oo0.SmoothedShocks.epsg oo_.SmoothedShocks.epsg]), title('epsg')
116 subplot(222)
117 plot([oo0.SmoothedShocks.epsi oo_.SmoothedShocks.epsi]), title('epsi')
118 subplot(223)
119 plot([oo0.SmoothedShocks.epss oo_.SmoothedShocks.epss]), title('epss')
120 legend('PKF','IF')
121 figure('Name','OccBin: Smoothed Variables')
122 subplot(221)
123 plot([oo0.SmoothedVariables.inom oo_.SmoothedVariables.inom]), title('inom')
124 subplot(222)
125 plot([oo0.SmoothedVariables.yg oo_.SmoothedVariables.yg]), title('yg')
126 subplot(223)
127 plot([oo0.SmoothedVariables.pi oo_.SmoothedVariables.pi]), title('pi')
128 legend('PKF','IF')
129 occbin_write_regimes(smoother);
130
131 estimation(
132 datafile=dataobsfile, mode_file=NKM_mh_mode_saved,
133 mode_compute=0, nobs=120, first_obs=1,
134 mh_replic=50, plot_priors=0, smoother,
135 consider_all_endogenous,filter_step_ahead=[1:8],smoothed_state_uncertainty);
136
137 write_latex_dynamic_model;
138 collect_latex_files;
139 [status, cmdout]=system(['pdflatex -halt-on-error -interaction=nonstopmode ' M_.fname '_TeX_binder.tex']);
140 if status
141 cmdout
142 error('TeX-File did not compile.')
143 end