Giter Site home page Giter Site logo

bvar_'s People

Contributors

naffe15 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bvar_'s Issues

VARX (un)conditional forecasts

  1. I seem to have found a bug in how unconditional forecasts for VARX models are produced. I have found out that no matter which values for the exogenous variable I use for the forecast period (with the length of options.controls being equal to T + fhor), the forecast stays exactly the same. I guess line 841 in bvar_.m should read:

forecast_data.xdata = [forecast_data.xdata exogenous(T+1 : T+fhor,:)];

  1. I also wonder why the code does not allow to use exogenous variables while producing conditional forecasts. When I comment line 632 in bvar_m.m and fix the bug described above, everything seems to work OK.

Error in checkrestrictions2

When I run the examples in the toolbox I got the following errors:

Operands to the logical and (&&) and or (||) operators must be convertible to logical scalar values.
Error in checkrestrictions2 (line 22)
if count == size(restriction,2) || count1 == size(restriction,2) % if all signs are verified stop
Error in iresponse_sign (line 73)
[d,fsign] = checkrestrictions2(signrestriction,y);
Error in bvar_ (line 951)
[irsign,Omega] = iresponse_sign(Phi(1 : ny*lags, 1 : ny),Sigma,hor,signs);
Error in example_3_irf (line 25)
bvar1 = bvar_(y,lags,options);

Any idea how to fix it?

function "polydet_break" missing?

Hello! The hitchhiker’s guide mentions a function "polydet_break" in page 119, but I couldn't find it in the "bvartools" folder. Is it missing?

Thanks! Best, Sergio

example 2

Hi,
In example 2,the code missed "lags=6"?

error messages

Hi,Ferroni

When I ran your template in Matlab 2020a and Win 10, it got an error message:

Error using bvar
Abstract classes cannot be instantiated. Class 'bvar' defines abstract methods and/or
properties.

Toolbox requirements

Perhaps it would be helpful to inform potential users that the toolbox requires Matlab's Statistics and Machine Learning Toolbox to run, at least definitely to run the 'direct methods' routines.

Are the line 863&864 var.X and Var.y rigint in bvar.m?

When I run any example, it alarms "Unable to resolve the name var.X." in bvar.m. I've checked there is no var in any places, so I modify it to varols.X, and var.y to varols.y.

Please help check if it is right.

Thank you!

Sign restriction identification vs. Mixed identification strategy

I have a conceptual question regarding the functions used for estimating sign-restricted and sign-zero restricted identified VARs in the toolbox. My intuition led me to believe that when both functions are parameterized the same way and no zero restrictions are applied, they should yield, in theory, identical results. However, I have encountered some discrepancies, and I'd like to seek clarification on this matter.

Minimal Working Example

Set up a VAR model with the data provided in the toolbox.

% example_3_irf.m Impulse  responses, variance  decomp, historical decomp
%                 plus  time varying  IRFs
% Authors:   Filippo Ferroni and  Fabio Canova
% Date:     27/02/2020, revised  14/12/2020
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1) Computation of IRFs using various  identification schemes
% 2) Calculation of  variance and  historical decompositions
% 3) Rolling window estimation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

close all; clc; clear;
addpath ../../cmintools/
addpath ../../bvartools/

% load the data
load DataGK
y = [logip logcpi gs1 ebp];

% Set lag and horizon
lags        = 12;
options.hor = 24;

% Keep the same order of variables as in the estimation
% 1. gs1; 2. logip; 2. logcpi; 4. ebp;
indx_var              = [3, 2, 1, 4];

I will commence by estimating a sign-restricted VAR model, akin to the framework showcased in Example 11, which analyses responses to monetary policy shocks with sign identification. However, the singular deviation in this instance is that I exclusively impose response restrictions within the first period. This initial step is taken to ensure that subsequent results can be directly compared to those derived from a sign-zero restricted VAR model.

%% 1) Sign restrictions

% specify the restrictions
options.signs{1} = 'y(3,1,1)>0'; % 1Y rate up in period 1
options.signs{2} = 'y(2,1,1)<0'; % CPI down in period 1 
options.K        = 10000;
% run the BVAR
bvar2             = bvar_(y,lags,options);

% Define the IRF of Interest
% index of the shocks of interest (shock to gs1)
indx_sho         = 1;  
% IRF  (notice that we change the order of the variables for the plot)
irfs_to_plot     = bvar2.irsign_draws(indx_var,:,indx_sho,:);

% Customize the IRF plot
% names of the figure to save
options.saveas_strng  = 'signs';
% name of the shock
options.shocksnames   = {'MPtightening'}; % 
plot_irfs_(irfs_to_plot,options)
pause;

This gives me the impulse response function.

Now, I intended to compare these impulse response functions (IRFs) with those obtained from a zero-sign restricted model, utilising a similar parameterisation.

%% 4) Zeros and Signs

% Housekeeping: remove previous identification settings
options = rmfield(options,'signs');

% specify the restrictions
% 1) MP shock: as above 
options.zeros_signs{1}     = 'y(3,1)=1;';
options.zeros_signs{end+1} = 'y(2,1)=-1;';
options.K        = 10000;
% run the BVAR
bvar4             = bvar_(y,lags,options);

% IRFs of Interest
indx_sho     = 1;
irfs_to_plot = bvar4.irzerosign_draws(indx_var,:,indx_sho,:);

% Customize the IRF plots
options.saveas_strng    = 'zerossigns';
options.shocksnames     = {'MPshock'}; % 
% options.add_irfs        = bvar4.irzerosign_ols(indx_var,:,indx_sho,:);
plot_all_irfs_(irfs_to_plot,options)
pause

Expectations

I acknowledge that there are variations in how the functions handle the duration of restrictions. However, when the restrictions are limited to the impact period and no zero restrictions are enforced, I would expect the impulse responses to be either identical or highly similar. In my simulations, they exhibit notable quantitative differences.

Any guidance or insights would be greatly appreciated.

I think there are errors in drawing sign-restricted IRFs when the number of exogenous variables is more than two.

When bvar_.m gets the IRF with sign restrictions, it uses the following codes(line number 900):

% with sign restrictions
if signs_irf == 1        
    [irsign,Omega]         = iresponse_sign(Phi,Sigma,hor,signs);
    irsign_draws(:,:,:,d)  = irsign;
    Omega_draws(:,:,d)     = Omega;
end

But, since Phi includes not only values for endogenous variables but also values for exogenous variables, iresponse_sign function returns wrong IRF when the number of exogenous variables is more than two.

I believe the following codes will work:

    [irsign,Omega]         = iresponse_sign(Phi(1:(size(Phi,1)-nexogenous),:),Sigma,hor,signs);

Error when generating forecasts conditional on 2+ variables

I have tried to use the following code to generate the forecast conditional on the values of the 1st and the 4th endogenous variables:

options.max_minn_hyper = 1;
options.endo_index = [1, 4];
options.exo_index = [1, 4];
options.endo_path = [3 3 3 3 3 3 3 3; 45 50 50 50 50 50 50 50]';
c.var(1) = bvar_(y,lags,options);

However, what I obtain is an error message:

Error using cforecasts2
something went wrong: the number of path and the number of vars are not consistent.
Error in bvar_ (line 1013)
            cforecasts2(endo_path,endo_path_index,exo_index,forecast_data,Phi,Sigma,Omega);

It seems to mee that here the correct line should be:
if Ncondvar ~= length(endo_index)
rather than
if size(Ncondvar,2) ~= length(endo_index)
When I manually change it, the code still throws an error:
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication. Error in cforecasts2 (line 95) e(:,t) = inv(RR(endo_index,exo_index))*(endo_path(t,:) - y(endo_index));
What am I missing?

Example 23

the code of loading data:

% load the data
load Data
% select the variables
y_actual = [IPI HICP CORE Euribor1Y M3 EXRATE];
% stop estimation at August 2014
in_sample_end = find(T==2014 + 7/12); %Time----T
y = y_actual(1:in_sample_end,:);
Time = T(1:in_sample_end); %T---Time

example 3

When I ran example 3 in matlab 2017b, got an error messages:

Error using bvar_max_hyper (line 50)
Mismatch between the size of upper bounds and the param vector

How to add lagged exogenous variables

Hello!
Could you let me know how to add lagged exogenous variables?

For example,
y = [ y_1 ; y_2 ; ... ; y_100]
w = [ w_1 ; w_2 ; ... ; w_100]
And let lags = 2;

Then w(t) = [w_3; ... ; w_100], w(t-1) = [w_2; ... ; w_99], w(t-2) = [w_1; ... ; w_98]

According to HitchhikerGuide_.pdf(7 page), the user supplies z(t) to the toolkit and thus may include in the z(t) not only variables which are contemporaneous to y(t) but also lags, i.e. z(t) = [w(t), w(t-1), w(t-2)].

But thing is that the row length of z(t) is 98 but the row length of y(t) is 100, so I can't put z(t) into y(t) = Phi(L) y(t-1) + Phi0 + Gamma z(t) + u(t).

More importantly, the function rfvar3, which combines endogenous variables and exogenous variables for OLS estimation, uses the following codes:

X = [lagged_endo_var(:,:) exo_var(lags+1,:)];
y = ydata(lags+1,:);

I think I need to add zeros matrix to z(t), that is = z(t) = [ zeros(lags,nvar) ; z(t) ] to match time series sequences.

But codes above are not working! What is wrong with the codes?

-------full code---------------(Note : in this code, I want to use z(t) = [ w(t-1), w(t-2) ])

lags = 3

%create lagged exogenous variables
[yy_ex,exo] = YXB_(w,lags,[0 0]);
exo = [ zeros(lags,size(exo,2)); exo];
options.controls = exo;

bvar = bvar_(y,lags,options);

Error in Example 25

Undefined function or variable 'prior'.
Error in directmethods (line 203)
if length(lb) ~= length(prior.tau)

Sign restrictions

There seems to be an issue with estimating the model using sign restrictions (Matlab R2022b):

Unrecognized function or variable 'maxhorsign'.

Error in iresponse_sign (line 51)
hor0 = maxhorsign(signrestriction) ;

Error in bvar_ (line 951)
[irsign,Omega] = iresponse_sign(Phi(1 : ny*lags, 1 : ny),Sigma,hor,signs);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.