%
% Status : main Dynare file
%
% Warning : this file is generated automatically by Dynare
%           from model file (.mod)

if isoctave || matlab_ver_less_than('8.6')
    clear all
else
    clearvars -global
    clear_persistent_variables(fileparts(which('dynare')), false)
end
tic0 = tic;
% Define global variables.
global M_ options_ oo_ estim_params_ bayestopt_ dataset_ dataset_info estimation_info ys0_ ex0_
options_ = [];
M_.fname = 'HM';
M_.dynare_version = '5.1';
oo_.dynare_version = '5.1';
options_.dynare_version = '5.1';
%
% Some global variables initialization
%
global_initialization;
M_.exo_names = cell(1,1);
M_.exo_names_tex = cell(1,1);
M_.exo_names_long = cell(1,1);
M_.exo_names(1) = {'epsa'};
M_.exo_names_tex(1) = {'epsa'};
M_.exo_names_long(1) = {'epsa'};
M_.endo_names = cell(5,1);
M_.endo_names_tex = cell(5,1);
M_.endo_names_long = cell(5,1);
M_.endo_names(1) = {'k'};
M_.endo_names_tex(1) = {'k'};
M_.endo_names_long(1) = {'k'};
M_.endo_names(2) = {'a'};
M_.endo_names_tex(2) = {'a'};
M_.endo_names_long(2) = {'a'};
M_.endo_names(3) = {'c'};
M_.endo_names_tex(3) = {'c'};
M_.endo_names_long(3) = {'c'};
M_.endo_names(4) = {'y'};
M_.endo_names_tex(4) = {'y'};
M_.endo_names_long(4) = {'y'};
M_.endo_names(5) = {'i'};
M_.endo_names_tex(5) = {'i'};
M_.endo_names_long(5) = {'i'};
M_.endo_partitions = struct();
M_.param_names = cell(6,1);
M_.param_names_tex = cell(6,1);
M_.param_names_long = cell(6,1);
M_.param_names(1) = {'alpha'};
M_.param_names_tex(1) = {'alpha'};
M_.param_names_long(1) = {'alpha'};
M_.param_names(2) = {'beta'};
M_.param_names_tex(2) = {'beta'};
M_.param_names_long(2) = {'beta'};
M_.param_names(3) = {'rhoa'};
M_.param_names_tex(3) = {'rhoa'};
M_.param_names_long(3) = {'rhoa'};
M_.param_names(4) = {'delta'};
M_.param_names_tex(4) = {'delta'};
M_.param_names_long(4) = {'delta'};
M_.param_names(5) = {'sigma'};
M_.param_names_tex(5) = {'sigma'};
M_.param_names_long(5) = {'sigma'};
M_.param_names(6) = {'stda'};
M_.param_names_tex(6) = {'stda'};
M_.param_names_long(6) = {'stda'};
M_.param_partitions = struct();
M_.exo_det_nbr = 0;
M_.exo_nbr = 1;
M_.endo_nbr = 5;
M_.param_nbr = 6;
M_.orig_endo_nbr = 5;
M_.aux_vars = [];
M_ = setup_solvers(M_);
M_.Sigma_e = zeros(1, 1);
M_.Correlation_matrix = eye(1, 1);
M_.H = 0;
M_.Correlation_matrix_ME = 1;
M_.sigma_e_is_diagonal = true;
M_.det_shocks = [];
M_.surprise_shocks = [];
M_.heteroskedastic_shocks.Qvalue_orig = [];
M_.heteroskedastic_shocks.Qscale_orig = [];
options_.linear = false;
options_.block = false;
options_.bytecode = false;
options_.use_dll = false;
M_.orig_eq_nbr = 5;
M_.eq_nbr = 5;
M_.ramsey_eq_nbr = 0;
M_.set_auxiliary_variables = exist(['./+' M_.fname '/set_auxiliary_variables.m'], 'file') == 2;
M_.epilogue_names = {};
M_.epilogue_var_list_ = {};
M_.orig_maximum_endo_lag = 1;
M_.orig_maximum_endo_lead = 1;
M_.orig_maximum_exo_lag = 0;
M_.orig_maximum_exo_lead = 0;
M_.orig_maximum_exo_det_lag = 0;
M_.orig_maximum_exo_det_lead = 0;
M_.orig_maximum_lag = 1;
M_.orig_maximum_lead = 1;
M_.orig_maximum_lag_with_diffs_expanded = 1;
M_.lead_lag_incidence = [
 0 2 7;
 1 3 8;
 0 4 9;
 0 5 0;
 0 6 0;]';
M_.nstatic = 2;
M_.nfwrd   = 2;
M_.npred   = 0;
M_.nboth   = 1;
M_.nsfwrd   = 3;
M_.nspred   = 1;
M_.ndynamic   = 3;
M_.dynamic_tmp_nbr = [0; 0; 0; 0; ];
M_.model_local_variables_dynamic_tt_idxs = {
};
M_.equations_tags = {
  1 , 'name' , '1' ;
  2 , 'name' , '2' ;
  3 , 'name' , 'a' ;
  4 , 'name' , '4' ;
  5 , 'name' , '5' ;
};
M_.mapping.k.eqidx = [1 2 4 ];
M_.mapping.a.eqidx = [1 3 4 ];
M_.mapping.c.eqidx = [1 2 5 ];
M_.mapping.y.eqidx = [2 4 5 ];
M_.mapping.i.eqidx = [5 ];
M_.mapping.epsa.eqidx = [3 ];
M_.static_and_dynamic_models_differ = false;
M_.has_external_function = false;
M_.state_var = [2 ];
M_.exo_names_orig_ord = [1:1];
M_.maximum_lag = 1;
M_.maximum_lead = 1;
M_.maximum_endo_lag = 1;
M_.maximum_endo_lead = 1;
oo_.steady_state = zeros(5, 1);
M_.maximum_exo_lag = 0;
M_.maximum_exo_lead = 0;
oo_.exo_steady_state = zeros(1, 1);
M_.params = NaN(6, 1);
M_.endo_trends = struct('deflator', cell(5, 1), 'log_deflator', cell(5, 1), 'growth_factor', cell(5, 1), 'log_growth_factor', cell(5, 1));
M_.NNZDerivatives = [17; -1; -1; ];
M_.static_tmp_nbr = [0; 0; 0; 0; ];
M_.model_local_variables_static_tt_idxs = {
};
close all; 
clear all;
M_.params(1) = 0.3333333333333333;
alpha = M_.params(1);
M_.params(5) = 1;
sigma = M_.params(5);
M_.params(4) = 0.025;
delta = M_.params(4);
M_.params(2) = 0.99;
beta = M_.params(2);
M_.params(3) = 0.99;
rhoa = M_.params(3);
sigmae = 0.01;  
%
% INITVAL instructions
%
options_.initval_file = false;
oo_.steady_state(1) = 3.367295829986474;
oo_.steady_state(4) = 1.09861228866811;
oo_.steady_state(2) = 0;
oo_.steady_state(3) = 0.9162907318741551;
oo_.steady_state(5) = 0.4054651081081644;
if M_.exo_nbr > 0
	oo_.exo_simul = ones(M_.maximum_lag,1)*oo_.exo_steady_state';
end
if M_.exo_det_nbr > 0
	oo_.exo_det_simul = ones(M_.maximum_lag,1)*oo_.exo_det_steady_state';
end
steady;
%
% SHOCKS instructions
%
M_.exo_det_length = 0;
M_.Sigma_e(1, 1) = sigmae^2;
options_.irf = 40;
options_.order = 1;
options_.irf_shocks = {'epsa'};
var_list_ = {'k';'a';'c';'y';'i'};
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);
options_.irf = 60;
options_.nograph = true;
options_.order = 1;
options_.irf_shocks = {'epsa'};
var_list_ = {'k';'a';'c';'y';'i'};
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);
irf1 = oo_.irfs;
figure();
set(gcf,'numbertitle','off','name','Technology shock - High Persistence','Position', [250, 250, 1000,500]) 
subplot(2,3,1)
hold on
plot(1:options_.irf,irf1.a_epsa,'k*-')
hline(0,'r--')
title('a_t - productivity')
grid on;
hold off;
subplot(2,3,2)
hold on;
plot(1:options_.irf,irf1.y_epsa,'k*-')
hline(0,'r--')
title('y_t - output')
grid on;
hold off;
subplot(2,3,3)
hold on;
plot(1:options_.irf,irf1.k_epsa,'k*-')
hline(0,'r--')
title('k_t - capital')
grid on;
hold off;
subplot(2,3,4)
hold on;
plot(1:options_.irf,irf1.n_epsa,'k*-')
hline(0,'r--')
title('n_t - hours')
grid on;
hold off;
subplot(2,3,5)
hold on;
plot(1:options_.irf,irf1.c_epsa,'k*-')
hline(0,'r--')
title('c_t - consumption')
grid on;
hold off;


oo_.time = toc(tic0);
disp(['Total computing time : ' dynsec2hms(oo_.time) ]);
if ~exist([M_.dname filesep 'Output'],'dir')
    mkdir(M_.dname,'Output');
end
save([M_.dname filesep 'Output' filesep 'HM_results.mat'], 'oo_', 'M_', 'options_');
if exist('estim_params_', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'HM_results.mat'], 'estim_params_', '-append');
end
if exist('bayestopt_', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'HM_results.mat'], 'bayestopt_', '-append');
end
if exist('dataset_', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'HM_results.mat'], 'dataset_', '-append');
end
if exist('estimation_info', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'HM_results.mat'], 'estimation_info', '-append');
end
if exist('dataset_info', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'HM_results.mat'], 'dataset_info', '-append');
end
if exist('oo_recursive_', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'HM_results.mat'], 'oo_recursive_', '-append');
end
if ~isempty(lastwarn)
  disp('Note: warning(s) encountered in MATLAB/Octave code')
end
