Commit 105100c7 authored by MichelJuillard's avatar MichelJuillard

remove global in dyn_forecast() and change input and output arguments

parent eb3d0cd2
function info = dyn_forecast(var_list,task)
function [forecast,info] = dyn_forecast(var_list,M,options,oo,task)
% function dyn_forecast(var_list,task)
% computes mean forecast for a given value of the parameters
% computes also confidence band for the forecast
......@@ -33,17 +33,15 @@ function info = dyn_forecast(var_list,task)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
global options_ oo_ M_
info = 0;
make_ex_;
maximum_lag = M_.maximum_lag;
maximum_lag = M.maximum_lag;
endo_names = M_.endo_names;
endo_names = M.endo_names;
if isempty(var_list)
var_list = endo_names(1:M_.orig_endo_nbr, :);
var_list = endo_names(1:M.orig_endo_nbr, :);
end
i_var = [];
for i = 1:size(var_list)
......@@ -59,64 +57,64 @@ n_var = length(i_var);
trend = 0;
switch task
case 'simul'
horizon = options_.periods;
horizon = options.periods;
if horizon == 0
horizon = 5;
end
if isempty(M_.endo_histval)
y0 = repmat(oo_.dr.ys,1,maximum_lag);
if isempty(M.endo_histval)
y0 = repmat(oo.dr.ys,1,maximum_lag);
else
y0 = M_.endo_histval;
y0 = M.endo_histval;
end
case 'smoother'
horizon = options_.forecast;
y_smoothed = oo_.SmoothedVariables;
y0 = zeros(M_.endo_nbr,maximum_lag);
for i = 1:M_.endo_nbr
v_name = deblank(M_.endo_names(i,:));
y0(i,:) = y_smoothed.(v_name)(end-maximum_lag+1:end)+oo_.dr.ys(i);
horizon = options.forecast;
y_smoothed = oo.SmoothedVariables;
y0 = zeros(M.endo_nbr,maximum_lag);
for i = 1:M.endo_nbr
v_name = deblank(M.endo_names(i,:));
y0(i,:) = y_smoothed.(v_name)(end-maximum_lag+1:end)+oo.dr.ys(i);
end
gend = options_.nobs;
if isfield(oo_.Smoother,'TrendCoeffs')
var_obs = options_.varobs;
endo_names = M_.endo_names;
order_var = oo_.dr.order_var;
gend = options.nobs;
if isfield(oo.Smoother,'TrendCoeffs')
var_obs = options.varobs;
endo_names = M.endo_names;
order_var = oo.dr.order_var;
i_var_obs = [];
trend_coeffs = [];
for i=1:length(var_obs)
tmp = strmatch(var_obs{i},endo_names(i_var,:),'exact');
if ~isempty(tmp)
i_var_obs = [ i_var_obs; tmp];
trend_coeffs = [trend_coeffs; oo_.Smoother.TrendCoeffs(i)];
trend_coeffs = [trend_coeffs; oo.Smoother.TrendCoeffs(i)];
end
end
if ~isempty(trend_coeffs)
trend = trend_coeffs*(gend+(1-M_.maximum_lag:horizon));
trend = trend_coeffs*(gend+(1-M.maximum_lag:horizon));
end
end
global bayestopt_
if isfield(bayestopt_,'mean_varobs')
trend = trend + repmat(bayestopt_.mean_varobs,1,horizon+M_.maximum_lag);
trend = trend + repmat(bayestopt_.mean_varobs,1,horizon+M.maximum_lag);
end
otherwise
error('Wrong flag value')
end
if M_.exo_det_nbr == 0
[yf,int_width] = forcst(oo_.dr,y0,horizon,var_list);
if M.exo_det_nbr == 0
[yf,int_width] = forcst(oo.dr,y0,horizon,var_list);
else
exo_det_length = size(oo_.exo_det_simul,1)-M_.maximum_lag;
exo_det_length = size(oo.exo_det_simul,1)-M.maximum_lag;
if horizon > exo_det_length
ex = zeros(horizon,M_.exo_nbr);
oo_.exo_det_simul = [ oo_.exo_det_simul;...
repmat(oo_.exo_det_steady_state',...
ex = zeros(horizon,M.exo_nbr);
oo.exo_det_simul = [ oo.exo_det_simul;...
repmat(oo.exo_det_steady_state',...
horizon- ...
exo_det_length,1)];
elseif horizon < exo_det_length
ex = zeros(exo_det_length,M_.exo_nbr);
ex = zeros(exo_det_length,M.exo_nbr);
end
[yf,int_width] = simultxdet(y0,ex,oo_.exo_det_simul,...
options_.order,var_list,M_,oo_,options_);
[yf,int_width] = simultxdet(y0,ex,oo.exo_det_simul,...
options.order,var_list,M,oo,options);
end
if ~isscalar(trend)
......@@ -124,17 +122,16 @@ if ~isscalar(trend)
end
for i=1:n_var
eval(['oo_.forecast.Mean.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+(1:horizon))'';']);
eval(['oo_.forecast.HPDinf.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+(1:horizon))''-' ...
' int_width(1:horizon,' int2str(i) ');']);
eval(['oo_.forecast.HPDsup.' var_list(i,:) '= yf(' int2str(i) ',maximum_lag+(1:horizon))''+' ...
' int_width(1:horizon,' int2str(i) ');']);
vname = deblank(var_list(i,:));
forecast.Mean.(vname) = yf(i,maximum_lag+(1:horizon))';
forecast.HPDinf.(vname)= yf(i,maximum_lag+(1:horizon))' - int_width(1:horizon,i);
forecast.HPDsup.(vname) = yf(i,maximum_lag+(1:horizon))' + int_width(1:horizon,i);
end
for i=1:M_.exo_det_nbr
eval(['oo_.forecast.Exogenous.' M_.exo_det_names(i,:) '= oo_.exo_det_simul(maximum_lag+(1:horizon),' int2str(i) ');']);
for i=1:M.exo_det_nbr
forecast.Exogenous.(deblank(M.exo_det_names(i,:))) = oo.exo_det_simul(maximum_lag+(1:horizon),i);
end
if options_.nograph == 0
forecast_graphs(var_list,M_, oo_,options_)
if options.nograph == 0
forecast_graphs(var_list,M, oo,options)
end
......@@ -773,7 +773,7 @@ if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.psha
end
if options_.forecast > 0 && options_.mh_replic == 0 && ~options_.load_mh_file
dyn_forecast(var_list_,'smoother');
oo_.forecast = dyn_forecast(var_list_,M_,options_,oo_,'smoother');
end
if np > 0
......
......@@ -239,7 +239,7 @@ ForecastStatement::writeOutput(ostream &output, const string &basename, bool min
{
options_list.writeOutput(output);
symbol_list.writeOutput("var_list_", output);
output << "info = dyn_forecast(var_list_,'simul');" << endl;
output << "[oo_.forecast,info] = dyn_forecast(var_list_,M_,options_,oo_,'simul');" << endl;
}
RamseyModelStatement::RamseyModelStatement(const SymbolList &symbol_list_arg,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment