writting a dsgevar_forecast function

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

writting a dsgevar_forecast function

Postby jcsantanac » Thu Apr 14, 2016 2:59 pm

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,
Attachments
dsgevar_forecast.m
dsgevar_forecast
(7.11 KiB) Downloaded 73 times
jcsantanac
 
Posts: 16
Joined: Fri Jan 03, 2014 2:08 am

Re: writting a dsgevar_forecast function

Postby jpfeifer » Thu Apr 14, 2016 6:22 pm

Where exactly do you want to integrate this function? It would belong into
Code: Select all
prior_posterior_statistics_core.m

The
Code: Select all
BayesInfo
variable is the
Code: Select all
bayestopt_
variable. What else do you need?
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: writting a dsgevar_forecast function

Postby jcsantanac » Fri Apr 15, 2016 12:36 am

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!
Attachments
DATABmr.xls
(34 KiB) Downloaded 83 times
dsgevar_forecast.m
(7.16 KiB) Downloaded 80 times
dsgevar_ex.mod
(33.6 KiB) Downloaded 80 times
jcsantanac
 
Posts: 16
Joined: Fri Jan 03, 2014 2:08 am

Re: writting a dsgevar_forecast function

Postby jpfeifer » Mon Apr 18, 2016 8:38 pm

Please do not use
Code: Select all
dsgevar_posterior_density

but
Code: Select all
dsge_var_likelihood

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

Code: Select all
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.
Code: Select all
dsgevar_forecast(1,var_list_);
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: writting a dsgevar_forecast function

Postby jcsantanac » Tue Apr 19, 2016 1:26 am

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
Attachments
dsgevar_forecast.m
(9.71 KiB) Downloaded 75 times
jcsantanac
 
Posts: 16
Joined: Fri Jan 03, 2014 2:08 am

Re: writting a dsgevar_forecast function

Postby jpfeifer » Tue Apr 19, 2016 6:04 am

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: writting a dsgevar_forecast function

Postby jcsantanac » Tue Apr 19, 2016 3:20 pm

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

JCamilo Santana
jcsantanac
 
Posts: 16
Joined: Fri Jan 03, 2014 2:08 am


Return to Dynare help

Who is online

Users browsing this forum: Google [Bot] and 6 guests