2014-12-13 12:18:45 +01:00
|
|
|
function oo_recursive_=dynare_estimation(var_list,dname)
|
2015-04-27 11:07:52 +02:00
|
|
|
% function dynare_estimation(var_list, dname)
|
2009-01-22 22:34:15 +01:00
|
|
|
% runs the estimation of the model
|
2011-09-17 15:38:49 +02:00
|
|
|
%
|
2009-01-22 22:34:15 +01:00
|
|
|
% INPUTS
|
|
|
|
% var_list: selected endogenous variables vector
|
2015-04-27 11:07:52 +02:00
|
|
|
% dname: alternative directory name
|
2011-09-17 15:38:49 +02:00
|
|
|
%
|
2009-01-22 22:34:15 +01:00
|
|
|
% OUTPUTS
|
2014-12-13 12:18:45 +01:00
|
|
|
% oo_recursive_: cell array containing the results structures from recursive estimation
|
2009-01-22 22:34:15 +01:00
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
2015-04-27 11:07:52 +02:00
|
|
|
% Copyright (C) 2003-2015 Dynare Team
|
2009-01-22 22:34:15 +01:00
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
|
|
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-04-11 08:56:59 +02:00
|
|
|
global options_ oo_ M_ dataset_
|
2014-12-13 12:18:45 +01:00
|
|
|
|
|
|
|
oo_recursive_={};
|
2009-01-22 22:34:15 +01:00
|
|
|
|
2013-11-28 10:57:54 +01:00
|
|
|
% Test if the order of approximation is nonzero (the preprocessor tests if order is non negative).
|
2013-11-28 10:54:15 +01:00
|
|
|
if isequal(options_.order,0)
|
|
|
|
error('Estimation:: The order of the Taylor approximation cannot be 0!')
|
|
|
|
end
|
|
|
|
|
2013-11-28 10:57:54 +01:00
|
|
|
% Decide if a DSGE or DSGE-VAR has to be estimated.
|
2009-03-21 23:36:18 +01:00
|
|
|
if ~isempty(strmatch('dsge_prior_weight',M_.param_names))
|
2010-06-24 12:53:10 +02:00
|
|
|
options_.dsge_var = 1;
|
2009-03-21 23:36:18 +01:00
|
|
|
end
|
|
|
|
|
2009-01-22 22:34:15 +01:00
|
|
|
var_list = check_list_of_variables(options_, M_, var_list);
|
|
|
|
options_.varlist = var_list;
|
|
|
|
|
2009-01-26 19:10:49 +01:00
|
|
|
if isfield(options_,'nobs')
|
2013-06-09 10:56:58 +02:00
|
|
|
nobs = sort(options_.nobs);
|
2009-01-26 19:10:49 +01:00
|
|
|
else
|
|
|
|
nobs = [];
|
|
|
|
end
|
|
|
|
|
2009-01-22 22:34:15 +01:00
|
|
|
nnobs = length(nobs);
|
|
|
|
horizon = options_.forecast;
|
|
|
|
|
2011-09-17 15:38:49 +02:00
|
|
|
if nargin<2 || ~exist(dname) || isempty(dname)
|
2015-04-27 11:50:25 +02:00
|
|
|
dname = options_.dirname;
|
2011-09-17 15:38:49 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
M_.dname = dname;
|
|
|
|
|
2013-10-27 10:56:11 +01:00
|
|
|
if (isnumeric(options_.mode_compute) && options_.mode_compute && options_.analytic_derivation) ... %no user supplied function
|
|
|
|
|| (~isnumeric(options_.mode_compute) && options_.analytic_derivation) % user supplied function
|
2012-04-27 15:57:58 +02:00
|
|
|
analytic_derivation0=options_.analytic_derivation;
|
|
|
|
options_.analytic_derivation=1;
|
|
|
|
end
|
2014-01-30 08:53:58 +01:00
|
|
|
|
|
|
|
if options_.logged_steady_state
|
|
|
|
oo_.dr.ys=exp(oo_.dr.ys);
|
|
|
|
oo_.steady_state=exp(oo_.steady_state);
|
|
|
|
end
|
|
|
|
|
2012-04-27 15:57:58 +02:00
|
|
|
|
2009-01-22 22:34:15 +01:00
|
|
|
if nnobs > 1
|
|
|
|
for i=1:nnobs
|
|
|
|
options_.nobs = nobs(i);
|
2011-10-21 22:06:09 +02:00
|
|
|
M_.dname = [dname '_' int2str(nobs(i))];
|
|
|
|
dynare_estimation_1(var_list,M_.dname);
|
2012-09-06 14:13:29 +02:00
|
|
|
if isequal(i,1)
|
|
|
|
options_.mode_file = [M_.fname '_mode'];
|
|
|
|
end
|
|
|
|
if options_.recursive_estimation_restart
|
|
|
|
for j=1:options_.recursive_estimation_restart
|
|
|
|
dynare_estimation_1(var_list,M_.dname);
|
|
|
|
end
|
|
|
|
end
|
2009-01-22 22:34:15 +01:00
|
|
|
oo_recursive_{nobs(i)} = oo_;
|
|
|
|
end
|
|
|
|
else
|
2011-09-17 15:38:49 +02:00
|
|
|
dynare_estimation_1(var_list,dname);
|
2009-01-22 22:34:15 +01:00
|
|
|
end
|
|
|
|
|
2015-04-06 11:24:42 +02:00
|
|
|
if isnumeric(options_.mode_compute) && options_.mode_compute && options_.analytic_derivation,
|
2012-04-27 15:57:58 +02:00
|
|
|
options_.analytic_derivation=analytic_derivation0;
|
|
|
|
end
|
|
|
|
|
2011-02-10 15:54:23 +01:00
|
|
|
if nnobs > 1 && horizon > 0
|
2009-01-22 22:34:15 +01:00
|
|
|
mh_replic = options_.mh_replic;
|
|
|
|
|
|
|
|
endo_names = M_.endo_names;
|
2013-05-21 16:38:17 +02:00
|
|
|
n_varobs = length(options_.varobs);
|
2011-09-17 15:38:49 +02:00
|
|
|
|
2009-01-22 22:34:15 +01:00
|
|
|
if isempty(var_list)
|
|
|
|
var_list = endo_names;
|
|
|
|
nvar = size(endo_names,1);
|
|
|
|
SelecVariables = transpose(1:nvar);
|
|
|
|
else
|
|
|
|
nvar = size(var_list,1);
|
|
|
|
SelecVariables = [];
|
|
|
|
for i=1:nvar
|
|
|
|
if ~isempty(strmatch(var_list(i,:),endo_names,'exact'))
|
2013-11-28 10:57:54 +01:00
|
|
|
SelecVariables = [SelecVariables;strmatch(var_list(i,:),endo_names, 'exact')];
|
2009-01-22 22:34:15 +01:00
|
|
|
else
|
2013-11-28 10:57:54 +01:00
|
|
|
error(['Estimation:: ' var_list(i,:) ' isn''t an endogenous variable'])
|
2011-09-17 15:38:49 +02:00
|
|
|
end
|
2009-01-22 22:34:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
IdObs = zeros(n_varobs,1);
|
|
|
|
for j=1:n_varobs
|
2013-05-21 16:38:17 +02:00
|
|
|
iobs = strmatch(options_.varobs{j},var_list,'exact');
|
2009-01-22 22:34:15 +01:00
|
|
|
if ~isempty(iobs)
|
|
|
|
IdObs(j,1) = iobs;
|
2011-09-17 15:38:49 +02:00
|
|
|
end
|
|
|
|
end
|
2015-04-11 08:56:59 +02:00
|
|
|
|
|
|
|
gend = dataset_.nobs;
|
2013-06-09 10:55:52 +02:00
|
|
|
time_offset=min(3,gend-1); %for observables, plot 3 previous periods unless data is shorter
|
|
|
|
k = time_offset+min(nobs(end)-nobs(1)+horizon, ...
|
2015-04-11 08:56:59 +02:00
|
|
|
size(dataset_.data,1)-nobs(1));
|
|
|
|
data2 = dataset_.data(end-k+1:end,:);
|
2009-01-22 22:34:15 +01:00
|
|
|
[nbplt,nr,nc,lr,lc,nstar] = pltorg(nvar);
|
|
|
|
m = 1;
|
2013-06-09 10:55:52 +02:00
|
|
|
plot_index=0;
|
|
|
|
OutputDirectoryName = CheckPath('graphs',M_.fname);
|
2009-01-22 22:34:15 +01:00
|
|
|
for i = 1:size(var_list,1)
|
|
|
|
if mod(i,nstar) == 1
|
2013-06-09 10:55:52 +02:00
|
|
|
plot_index=plot_index+1;
|
|
|
|
hfig = dyn_figure(options_,'Name',['Out of sample forecasts (',num2str(plot_index),')']);
|
2009-01-22 22:34:15 +01:00
|
|
|
m = 1;
|
|
|
|
end
|
|
|
|
subplot(nr,nc,m)
|
|
|
|
hold on
|
|
|
|
if any(i==IdObs)
|
|
|
|
k2 = find(i==IdObs);
|
|
|
|
offsetx = 3;
|
2013-06-09 10:55:52 +02:00
|
|
|
plot(nobs(1)-offsetx+1:nobs(1)-offsetx+k,data2(end-k+1:end,k2)','-k','linewidth',2);
|
2009-01-22 22:34:15 +01:00
|
|
|
else
|
|
|
|
offsetx = 0;
|
2011-09-17 15:38:49 +02:00
|
|
|
end
|
2009-01-22 22:34:15 +01:00
|
|
|
vname = deblank(var_list(i,:));
|
|
|
|
for j=1:nnobs
|
|
|
|
if mh_replic > 0
|
2014-11-11 11:42:19 +01:00
|
|
|
oo_.RecursiveForecast.Mean.(vname)(j,:) = ...
|
|
|
|
oo_recursive_{nobs(j)}.MeanForecast.Mean.(vname);
|
|
|
|
oo_.RecursiveForecast.HPDinf.(vname)(j,:) = ...
|
|
|
|
oo_recursive_{nobs(j)}.MeanForecast.HPDinf.(vname);
|
|
|
|
oo_.RecursiveForecast.HPDsup.(vname)(j,:) = ...
|
|
|
|
oo_recursive_{nobs(j)}.MeanForecast.HPDsup.(vname);
|
|
|
|
oo_.RecursiveForecast.HPDTotalinf.(vname)(j,:) = ...
|
|
|
|
oo_recursive_{nobs(j)}.PointForecast.HPDinf.(vname);
|
|
|
|
oo_.RecursiveForecast.HPDTotalsup.(vname)(j,:) = ...
|
|
|
|
oo_recursive_{nobs(j)}.PointForecast.HPDsup.(vname);
|
2009-01-22 22:34:15 +01:00
|
|
|
else
|
2014-11-11 11:42:19 +01:00
|
|
|
oo_.RecursiveForecast.Mean.(vname)(j,:) =...
|
|
|
|
oo_recursive_{nobs(j)}.forecast.Mean.(vname);
|
|
|
|
oo_.RecursiveForecast.HPDinf.(vname)(j,:) =...
|
|
|
|
oo_recursive_{nobs(j)}.forecast.HPDinf.(vname);
|
|
|
|
oo_.RecursiveForecast.HPDsup.(vname)(j,:) =...
|
|
|
|
oo_recursive_{nobs(j)}.forecast.HPDsup.(vname);
|
|
|
|
end
|
2013-06-09 10:55:52 +02:00
|
|
|
x = nobs(1)+nobs(j)-nobs(1)+(1:horizon);
|
|
|
|
|
2014-11-11 11:42:19 +01:00
|
|
|
y = oo_.RecursiveForecast.Mean.(vname)(j,:);
|
|
|
|
y1 = oo_.RecursiveForecast.HPDinf.(vname)(j,:);
|
|
|
|
y2 = oo_.RecursiveForecast.HPDsup.(vname)(j,:);
|
2009-01-22 22:34:15 +01:00
|
|
|
plot(x,y,'-b','linewidth',2)
|
|
|
|
plot(x,y1,'--g', ...
|
|
|
|
'linewidth',1.5)
|
|
|
|
plot(x,y2,'--g', ...
|
|
|
|
'linewidth',1.5)
|
|
|
|
if mh_replic
|
2014-11-11 11:42:19 +01:00
|
|
|
y3 = oo_.RecursiveForecast.HPDTotalinf.(vname)(j,:);
|
|
|
|
y4 = oo_.RecursiveForecast.HPDTotalsup.(vname)(j,:);
|
2009-01-22 22:34:15 +01:00
|
|
|
plot(x,y3,'--r', ...
|
|
|
|
'linewidth',1.5)
|
|
|
|
plot(x,y4,'--r','linewidth',1.5)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
box on
|
|
|
|
title(vname,'Interpreter','none')
|
|
|
|
hold off
|
2013-06-09 10:55:52 +02:00
|
|
|
xlim([nobs(1)-offsetx nobs(end)+horizon])
|
2009-01-22 22:34:15 +01:00
|
|
|
m = m + 1;
|
2013-06-09 10:55:52 +02:00
|
|
|
if mod(i+1,nstar) == 1 || i ==size(var_list,1)
|
|
|
|
dyn_saveas(hfig,[M_.fname,filesep,'graphs',filesep M_.fname '_RecursiveForecasts_' int2str(plot_index)],options_);
|
|
|
|
end
|
2009-01-22 22:34:15 +01:00
|
|
|
end
|
|
|
|
end
|
2015-07-23 16:52:21 +02:00
|
|
|
options_.mode_file = ''; %delete stored mode-file so that it is not reaccessed in later calls (and in case it was only set by the recursive estimation)
|