Writtng a dsgevar_forecast function

Dear dynare friends,

i’m writting a code to forecast through the dsgevar model following the suggestions of Prof. Pfeifer and Prof. Adjemian. I’m taking the bvar_forecast function and adjusting it for call the normal-inverse wishart matrices from the dsgevar_posterior_density function but i have a particular situation. I append the M file.

I have a problem calling the dsgevar_posterior_density function because i can not identify completly all the arguments of this function. Please watch the lines 21 to 27 in the M file. For example, what’s BayesInfo argument?, the others are called correctly?. I haven’t could identify this argument watching other functions inside dynare.

Someone could give me an advice to identify these arguments?, for example through other functions that call similar arguments.

Once i can call the dsgevar_posterior_density function correctly, we can call the normal-wishart inverse structure at lines 55 to 59 and we can pass the matrices to the random number generator functions.

The posterior lines of M file are adjusted to the dsgevar situation.

I appreciate your suggestions or any opinion. I need forecast from this hybrid model

Thanks a lot,
dsgevar_forecast.m (7.11 KB)

Where exactly do you want to integrate this function? It would belong into prior_posterior_statistics_core.m
The BayesInfo variable is the bayestopt_ variable. What else do you need?

Prof. Pfeifer,

I need to establish the arguments to CALL the dsgevar_posterior_density correctly. I’m getting the following error through BREAKPOINT analysis:

dsgevar_forecast
Loading 53 observations from DATABmr.xlsx

Undefined variable “options_” or class “options_.nobs”.

Error in dsgevar_posterior_density (line 36)
gend = options_.nobs;

Error in dsgevar_forecast (line 48)
bvar =
dsgevar_posterior_density(deep,DynareDataset,DynareOptions,Model,EstimatedParameters,BayesInfo,DynareResults);

For example, there is an error at the moment to pass ‘DynareOptions=options_’ to dsgevar_posterior_density because it can not calculate the number of observations (nobs)

The description of these arguments in the M file ‘dsgevar_forecast’ are between lines 25 and 32, but i’m not sure if all of these definitions of arguments are ok.

I attached the DSGEVAR code, the data base ‘DATABmr’ and the M file.

I appreciate any suggestion Prof. Pfeifer.

thanks a lot!
DATABmr.xls (34 KB)
dsgevar_forecast.m (7.16 KB)
dsgevar_ex.mod (33.6 KB)

Please do not use

dsgevar_posterior_density 

but

dsge_var_likelihood

The former might be removed soon, because it is buggy.
Then, within your forecast function for now use

function dsgevar_forecast(nlags,var_list_)

% function dsgebvar_forecast(nlags,var_list_)
% builds forecats for a dsgebvar model
% based on the posterior dsgebvar
%
% Date: 13.04-2016
%
%
% INPUTS
%    nlags:     number of lags for the bvar
%    var_list_: list of variables
% OUTPUTS
%    none
%
% SPECIAL REQUIREMENTS
%    none

global options_ oo_ M_ estim_params_ bayestopt_ dataset_ dataset_info

if options_.forecast == 0
    error('dsgevar_forecast: you must specify "forecast" option')
end

[dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_, bayestopt_, bounds] = ...
    dynare_estimation_init(var_list_, M_.dname, ], M_, options_, oo_, estim_params_, bayestopt_);
[fval,grad,hess,exit_flag,info,PHI,SIGMAu,iXX,prior] = dsge_var_likelihood(xparam1,dataset_,options_,options_,M_,estim_params_,bayestopt_,bounds,oo_);

Note that you need to pass var_list_ in your call, i.e.

dsgevar_forecast(1,var_list_);

Prof. Pfeifer,

Thanks for your recommendation. I was working in the function before recieve your email and I could write a ‘dsgevar_forecast’ function calling the ‘dsgevar_likelihood’ function indirectly.

Before I run the estimation code (optimization process), the ‘dsgevar_likelihood’ is modified to save the estimated matrices PHI, SIGMAu and iXX in the matlab workspace; i.e. i put at the end of the dsgevar_likelihood function the following lines.

assignin('base','PHI',PHI);
assignin('base','SIGMAu',SIGMAu);
assignin('base','iXX',iXX);

After that, the estimation is executed and the ‘dsgevar_forecast’ call the PHI, SIGMAu and iXX optimized and pass the ‘respective’ matrices to the Normal/Wishart function generators. The forecasts from the dsgevar model are inside my expectations against the dsge only.

Professor, What do you think about this strategy?

I attach the ‘dsgevar_forecast’ M file.

I’m going to try with your suggestion. Thanks a lot.

JCamilo Santana
dsgevar_forecast.m (9.71 KB)

Please try to modify as few Dynare functions as possible and document your code as good as possible. Once you feel confident your code works, I am going to properly integrate it into Dynare. I will then also make sure that the correct arguments are passed, e.g. during posterior sampling where you cannot easily store results in the base workspace, so don’t worry about this hack for now.

Thanks Professor, I’m going to check the code and the arguments of the random number generators.

JCamilo Santana

hi, did you modify the code to works properly?
best regards.