Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bvartools/OrderingIndexes.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
if check == 1
%assignin('base', [newstrng 'index_' varordering{ii} ], ii);
String = varordering{ii};
String = replace(String,'-','');
iString = String(find(~isspace(String)));
assignin('base', [newstrng 'i' iString ], ii);
else
Expand Down
14 changes: 7 additions & 7 deletions bvartools/bvar_.m
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,9 @@
else % pooled units
yy = []; XX = [];
for nunit = 1 : nunits
[yy,XX] = YXB_(y(idx, :, nunit),lags,[nx timetrend]);
XX = [XX; XX];
yy = [yy; yy];
[yy_p,XX_p] = YXB_(y(idx, :, nunit),lags,[nx timetrend]);
XX = [XX; XX_p];
yy = [yy; yy_p];
end
end

Expand Down Expand Up @@ -1517,17 +1517,17 @@
% inference and IRFs
BVAR.Phi_draws = Phi_draws; % draws from the autoregressive part
BVAR.Sigma_draws = Sigma_draws; % draws from the covarance matrix
BVAR.alpha_draws = Phi_draws; % Older name: draws from the autoregressive part
BVAR.sigma_draws = Sigma_draws; % Older name: draws from the covarance matrix
% BVAR.alpha_draws = Phi_draws; % Older name: draws from the autoregressive part
% BVAR.sigma_draws = Sigma_draws; % Older name: draws from the covarance matrix
BVAR.Sigma_lower_chol_draw = Sigma_lower_chol_draw;
BVAR.ir_draws = ir_draws; % draws from the IRF with cholesky
BVAR.irlr_draws = irlr_draws; % draws from the IRF with Long Run
BVAR.Qlr_draws = Qlr_draws; % Long Run Rotation matrix
BVAR.lags = lags; % lags
BVAR.N = ny; % number of variables
BVAR.e_draws = e_draws; % residuals
BVAR.e = e_draws; % backward compatible with earlier versions
BVAR.fe_draws = fe_draws; % backward compatible with earlier versions
% BVAR.e = e_draws; % backward compatible with earlier versions
BVAR.fe_draws = fe_draws; % insample forecast errors

BVAR.posterior = posterior;
BVAR.prior = prior; % priors used
Expand Down
18 changes: 14 additions & 4 deletions bvartools/max_fevd.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,28 @@
if nargin < 6
Kappa = 1000;
end
if length(i) ~= length(j)
error('each shock must have one target')
end

N = size(Sigma,1);
crit = nan(Kappa,1);
crit = nan(Kappa,length(j));
Q = nan(N,N,Kappa);
for k = 1 : Kappa
Q(:,:,k) = generateQ(N); % generate an orthonormal matrix
FEVD = fevd(h,Phi,Sigma,Q(:,:,k)); % compute the FEVD
% Calculate the contribution of shock j, to variable i forecast error volatility, at horizon h
crit(k,1) = FEVD(i, j);
for j1 = 1 : length(j)
crit(k,j1) = FEVD(i(j1), j(j1));
end
end
% Pick the maximum
[~,index] = max(crit);
Qbar = Q(:,:,index);
Qbar = nan(N,N,length(j));
for j1 = 1 : length(j)
[~,index] = max(crit(:,j1));
tmp_notindx = setdiff([1:N] , j(j1));
Omega = Q(:,:,index);
Qbar(:,:,j1) = Omega(:,[j(j1) tmp_notindx]);
end

end
11 changes: 11 additions & 0 deletions bvartools/u2nu.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function [nu] = u2nu(e_draws,Sigma_draws,Omega_draws)

nu=zeros(size(e_draws));
for dd = 1 : size(e_draws,3)
errors = e_draws(:,:,dd);
A = chol( Sigma_draws(:,:,dd),'lower');
nu(:,:,dd) = errors * inv( Omega_draws(:,:,dd)' * A'); %#ok<MINV>

% nu(:,:,dd) = errors / ( Omega_draws(:,:,dd)' * A'); % structural innovations
end

22 changes: 22 additions & 0 deletions examples/BVAR tutorial/example_2_minn.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,25 @@

%% ESSENCE: OPTIMALLY CHOSEN AND CHERRY PICKED CHOSEN
%% HYPER-PARAMETER VALUES MAKE LITTLE DIFFERENCE FOR SHAPE OF IRFS.

%% 3.4 Use a presample as prior
clear options;
% run a VAR on presample data
presample = 50; % 8 years of presample
lags = 6;
bvar1 = bvar_(y(1:presample,:),lags);


% use the VAR estimates to set the priors for the LP
options.priors.name = 'Conjugate';
% posterior mean of the VAR AR coeff and constant
options.priors.Phi.mean = mean(bvar1.Phi_draws,3);
% average variance of the AR coeff and constant
options.priors.Phi.cov = diag(mean(var(bvar1.Phi_draws,0,3),2));
% posterior mean of the Covariance of the VAR residuals
options.priors.Sigma.scale = mean(bvar1.Sigma_draws,3);
options.priors.Sigma.df = size(bvar1.Phi_draws,1)-2;
options.K = 1000;

bvar2 = bvar_(y(presample+1:end,:),lags,options);