| 1 |
steady_state_model; |
| 2 |
kss = ((1/BETA-1+DELTAK)/ALPHA)^(1/(ALPHA-1)); |
| 3 |
css = -DELTAK*kss +kss^ALPHA; |
| 4 |
iss = DELTAK*kss; |
| 5 |
|
| 6 |
|
| 7 |
k = log(kss); |
| 8 |
c = log(css); |
| 9 |
i = log(iss); |
| 10 |
lambdak = 0; |
| 11 |
a=0; |
| 12 |
end; |
| 13 |
|
| 14 |
BETA=0.96; |
| 15 |
ALPHA=0.33; |
| 16 |
DELTAK=0.10; |
| 17 |
GAMMAC=2; |
| 18 |
RHOA = 0.9; |
| 19 |
PHI = 0.975; |
| 20 |
PSI = 5; % adjustment cost for capital if investment is negative |
| 21 |
|
| 22 |
shocks; |
| 23 |
var erra; stderr 0.015; |
| 24 |
end; |
| 25 |
|
| 26 |
steady; |
| 27 |
|
| 28 |
// run occbin simulations |
| 29 |
% Option=1: impulse responses |
| 30 |
% Option=2: random simulation |
| 31 |
|
| 32 |
@#for option_val in [1, 2] |
| 33 |
|
| 34 |
option=@{option_val}; |
| 35 |
|
| 36 |
%%%%%%%%%%%%%%%% Inputs stop here %%%%%%%%%%%%%%%%%%%%% |
| 37 |
|
| 38 |
if option==1 |
| 39 |
shocks(surprise,overwrite); |
| 40 |
var erra; |
| 41 |
periods 1:9, 10, 50, 90, 130, 131:169; |
| 42 |
values -0.0001, -0.01,-0.02, 0.01, 0.02, 0; |
| 43 |
end; |
| 44 |
|
| 45 |
|
| 46 |
elseif option==2 |
| 47 |
nperiods = 40; |
| 48 |
randn('seed',1); |
| 49 |
shockssequence = 1*randn(nperiods,1)*0.02 ; |
| 50 |
|
| 51 |
shocks(surprise,overwrite); |
| 52 |
var erra; |
| 53 |
periods 1:40; |
| 54 |
values (shockssequence); |
| 55 |
end; |
| 56 |
|
| 57 |
end |
| 58 |
|
| 59 |
% set inputs |
| 60 |
|
| 61 |
occbin_setup(smoother_debug); |
| 62 |
occbin_solver(simul_debug,simul_periodic_solution,simul_periods=200,simul_maxit=300,simul_curb_retrench,simul_check_ahead_periods=300); |
| 63 |
occbin_write_regimes(filename='test',periods=[1:40]); |
| 64 |
occbin.plot_regimes(oo_.occbin.simul.regime_history,M_,options_) |
| 65 |
|
| 66 |
%% Modify to plot IRFs |
| 67 |
titlelist = char('c','lambdak','k','i','a'); |
| 68 |
percent = 'Percent'; |
| 69 |
value = 'value'; |
| 70 |
ylabels = char(percent,value,percent,percent,percent); |
| 71 |
figtitle = 'Simulated variables'; |
| 72 |
legendlist = cellstr(char('Piecewise Linear','Linear')); |
| 73 |
|
| 74 |
oo_= occbin.unpack_simulations(M_,oo_,options_); |
| 75 |
|
| 76 |
line1=100*[oo_.occbin.endo_piecewise.c-oo_.occbin.endo_ss.c,oo_.occbin.endo_piecewise.lambdak/100,oo_.occbin.endo_piecewise.k-oo_.occbin.endo_ss.k,oo_.occbin.endo_piecewise.i-oo_.occbin.endo_ss.i,oo_.occbin.endo_piecewise.a-oo_.occbin.endo_ss.a]; |
| 77 |
line2=100*[oo_.occbin.endo_linear.c-oo_.occbin.endo_ss.c,oo_.occbin.endo_linear.lambdak/100,oo_.occbin.endo_linear.k-oo_.occbin.endo_ss.k,oo_.occbin.endo_linear.i-oo_.occbin.endo_ss.i,oo_.occbin.endo_linear.a-oo_.occbin.endo_ss.a]; |
| 78 |
|
| 79 |
occbin.make_chart(titlelist,legendlist,figtitle,ylabels,cat(3,line1,line2)); |
| 80 |
|
| 81 |
occbin_graph(noconstant) c erra lambdak k i a k; |
| 82 |
|
| 83 |
@#if option_val==1 |
| 84 |
verbatim; |
| 85 |
c=oo_.occbin.endo_piecewise.c; |
| 86 |
end; |
| 87 |
save('datasim.mat','c'); |
| 88 |
varobs c; |
| 89 |
|
| 90 |
occbin_solver(simul_periods=200,simul_maxit=200,simul_curb_retrench,simul_check_ahead_periods=200); |
| 91 |
occbin_setup(smoother_periods=200,smoother_maxit=200,smoother_curb_retrench,smoother_check_ahead_periods=200); |
| 92 |
calib_smoother(datafile=datasim); |
| 93 |
oo_= occbin.unpack_simulations(M_,oo_,options_); |
| 94 |
|
| 95 |
titlelist = char('c','lambdak','k','i','a','erra'); |
| 96 |
percent = 'Percent'; |
| 97 |
value = 'value'; |
| 98 |
ylabels = char(percent,value,percent,percent,percent, value); |
| 99 |
figtitle = 'Smoothed variables (piecewise)'; |
| 100 |
legendlist = cellstr(char('Simulated','Piecewise smoother')); |
| 101 |
|
| 102 |
shock_vector=[oo_.occbin.simul.shocks_sequence./100; zeros(length(oo_.occbin.endo_piecewise.c)-size(oo_.occbin.simul.shocks_sequence,1),size(oo_.occbin.simul.shocks_sequence,2))]; |
| 103 |
line1=100*[oo_.occbin.endo_piecewise.c-oo_.occbin.endo_ss.c,oo_.occbin.endo_piecewise.lambdak/100,oo_.occbin.endo_piecewise.k-oo_.occbin.endo_ss.k,oo_.occbin.endo_piecewise.i-oo_.occbin.endo_ss.i,oo_.occbin.endo_piecewise.a-oo_.occbin.endo_ss.a, shock_vector]; |
| 104 |
line2=100*[oo_.occbin.smoother.SmoothedVariables.c-oo_.occbin.endo_ss.c,oo_.occbin.smoother.SmoothedVariables.lambdak/100,oo_.occbin.smoother.SmoothedVariables.k-oo_.occbin.endo_ss.k,oo_.occbin.smoother.SmoothedVariables.i-oo_.occbin.endo_ss.i,oo_.occbin.smoother.SmoothedVariables.a-oo_.occbin.endo_ss.a, oo_.occbin.smoother.SmoothedShocks.erra/100]; |
| 105 |
occbin.make_chart(titlelist,legendlist,figtitle,ylabels,cat(3,line1,line2)); |
| 106 |
|
| 107 |
figtitle = 'Smoothed variables (linear)'; |
| 108 |
legendlist = cellstr(char('Simulated','Linear smoother')); |
| 109 |
|
| 110 |
line1=100*[oo_.occbin.endo_piecewise.c-oo_.occbin.endo_ss.c,oo_.occbin.endo_piecewise.lambdak/100,oo_.occbin.endo_piecewise.k-oo_.occbin.endo_ss.k,oo_.occbin.endo_piecewise.i-oo_.occbin.endo_ss.i,oo_.occbin.endo_piecewise.a-oo_.occbin.endo_ss.a, shock_vector]; |
| 111 |
line2=100*[oo_.occbin.linear_smoother.SmoothedVariables.c-oo_.occbin.endo_ss.c,oo_.occbin.linear_smoother.SmoothedVariables.lambdak/100,oo_.occbin.linear_smoother.SmoothedVariables.k-oo_.occbin.endo_ss.k,oo_.occbin.linear_smoother.SmoothedVariables.i-oo_.occbin.endo_ss.i,oo_.occbin.linear_smoother.SmoothedVariables.a-oo_.occbin.endo_ss.a, oo_.occbin.linear_smoother.SmoothedShocks.erra/100]; |
| 112 |
occbin.make_chart(titlelist,legendlist,figtitle,ylabels,cat(3,line1,line2)); |
| 113 |
|
| 114 |
occbin.plot_regimes(oo_.occbin.smoother.regime_history(1:169),M_,options_) |
| 115 |
@#endif |
| 116 |
@#endfor |