BVAR-DSGE with constant (not yet ready)

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1167 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
adjemian 2007-01-26 14:50:30 +00:00
parent 6c7fcaa567
commit 44093cbbb9
3 changed files with 87 additions and 79 deletions

View File

@ -1,7 +1,6 @@
function [fval,cost_flag,ys,trend_coeff,info,PHI,SIGMAu,iXX] = DsgeVarLikelihood(xparam1,gend) function [fval,cost_flag,ys,trend_coeff,info,PHI,SIGMAu,iXX] = DsgeVarLikelihood(xparam1,gend)
% stephane.adjemian@ens.fr % stephane.adjemian@ens.fr
global bayestopt_ estim_params_ M_ options_ xparam1_test global bayestopt_ estim_params_ M_ options_
global xparam_
nvx = estim_params_.nvx; nvx = estim_params_.nvx;
nvn = estim_params_.nvn; nvn = estim_params_.nvn;
@ -49,12 +48,14 @@ for i=1:estim_params_.nvx
end end
offset = estim_params_.nvx; offset = estim_params_.nvx;
if estim_params_.nvn if estim_params_.nvn
H = zeros(nobs,nobs); disp('DsgeVarLikelihood :: Measurement errors are not implemented!')
for i=1:estim_params_.nvn return
k = estim_params_.var_endo(i,1); % $$$ H = zeros(nobs,nobs);
H(k,k) = xparam1(i+offset)*xparam1(i+offset); % $$$ for i=1:estim_params_.nvn
end % $$$ k = estim_params_.var_endo(i,1);
offset = offset+estim_params_.nvn; % $$$ H(k,k) = xparam1(i+offset)*xparam1(i+offset);
% $$$ end
% $$$ offset = offset+estim_params_.nvn;
end end
if estim_params_.ncx if estim_params_.ncx
for i=1:estim_params_.ncx for i=1:estim_params_.ncx
@ -77,23 +78,25 @@ if estim_params_.ncx
offset = offset+estim_params_.ncx; offset = offset+estim_params_.ncx;
end end
if estim_params_.nvn & estim_params_.ncn if estim_params_.nvn & estim_params_.ncn
for i=1:estim_params_.ncn disp('DsgeVarLikelihood :: Measurement errors are not implemented!')
k1 = options_.lgyidx2varobs(estim_params_.corrn(i,1));
k2 = options_.lgyidx2varobs(estim_params_.corrn(i,2));
H(k1,k2) = xparam1(i+offset)*sqrt(H(k1,k1)*H(k2,k2));
H(k2,k1) = H(k1,k2);
end
[CholH,testH] = chol(H);
if testH
a = eig(H);
k = a<0;
if k > 0
fval = bayestopt_.penalty*min(1e3,exp(sum(-a(k))));
cost_flag = 0;
return return
end % $$$ for i=1:estim_params_.ncn
end % $$$ k1 = options_.lgyidx2varobs(estim_params_.corrn(i,1));
offset = offset+estim_params_.ncn; % $$$ k2 = options_.lgyidx2varobs(estim_params_.corrn(i,2));
% $$$ H(k1,k2) = xparam1(i+offset)*sqrt(H(k1,k1)*H(k2,k2));
% $$$ H(k2,k1) = H(k1,k2);
% $$$ end
% $$$ [CholH,testH] = chol(H);
% $$$ if testH
% $$$ a = eig(H);
% $$$ k = a<0;
% $$$ if k > 0
% $$$ fval = bayestopt_.penalty*min(1e3,exp(sum(-a(k))));
% $$$ cost_flag = 0;
% $$$ return
% $$$ end
% $$$ end
% $$$ offset = offset+estim_params_.ncn;
end end
M_.params(estim_params_.param_vals(:,1)) = xparam1(offset+1:end); M_.params(estim_params_.param_vals(:,1)) = xparam1(offset+1:end);
M_.Sigma_e = Q; M_.Sigma_e = Q;
@ -121,13 +124,10 @@ else
constant = SteadyState(bayestopt_.mfys); constant = SteadyState(bayestopt_.mfys);
end end
if bayestopt_.with_trend == 1 if bayestopt_.with_trend == 1
trend_coeff = zeros(nobs,1); disp('DsgeVarLikelihood :: Linear trend is not yet implemented!')
for i=1:nobs return
trend_coeff(i) = evalin('base',bayestopt_.trend_coeff{i}); % $$$ else
end % $$$ trend = constant*ones(1,gend);
trend = constant*ones(1,gend)+trend_coeff*(1:gend);
else
trend = constant*ones(1,gend);
end end
%------------------------------------------------------------------------------ %------------------------------------------------------------------------------

View File

@ -140,7 +140,6 @@ if ~isempty(options_.unit_root_vars)
end end
i_ur(i) = i1; i_ur(i) = i1;
end end
[junk,bayestopt_.var_list_stationary] = ... [junk,bayestopt_.var_list_stationary] = ...
setdiff((1:M_.endo_nbr)',i_ur); setdiff((1:M_.endo_nbr)',i_ur);
[junk,bayestopt_.restrict_var_list_stationary] = ... [junk,bayestopt_.restrict_var_list_stationary] = ...
@ -194,22 +193,31 @@ if length(options_.mode_file) > 0 & options_.posterior_mode_estimation
eval(['load ' options_.mode_file ';']'); eval(['load ' options_.mode_file ';']');
end end
%% compute sample moments if needed (bvar-dsge)
if ~isempty(strmatch('dsge_prior_weight',M_.param_names)) %% Compute the steadyn state:
evalin('base',['[mYY,mXY,mYX,mXX,Ydata,Xdata] = ' ... if options_.steadystate_flag% if the _steadystate.m file is provided.
'var_sample_moments(options_.first_obs,options_.first_obs+options_.nobs-1,options_.varlag,-1);']) [oo_.steady_state,tchek] = feval([M_.fname '_steadystate'],[],[]);
else% if the steady state file is not provided.
[dd,info] = resol(oo_.steady_state,0)
oo_.steady_state = dd.ys; clear('dd');
end end
%% Compute the steadyn state if the _steadystate.m file is provided
if options_.steadystate_flag
[oo_.steady_state,tchek] = feval([M_.fname '_steadystate'],[],[]);
end
initial_estimation_checks(xparam1,gend,data); initial_estimation_checks(xparam1,gend,data);
if options_.mode_compute == 0 & length(options_.mode_file) == 0 if options_.mode_compute == 0 & length(options_.mode_file) == 0
return; return;
end end
%% compute sample moments if needed (bvar-dsge)
if ~isempty(strmatch('dsge_prior_weight',M_.param_names))
if all(abs(oo_.steady_state)<10e-9)
evalin('base',['[mYY,mXY,mYX,mXX,Ydata,Xdata] = ' ...
'var_sample_moments(options_.first_obs,options_.first_obs+options_.nobs-1,options_.varlag,-1);'])
else% The steady state is non zero ==> a constant in the VAR is needed!
evalin('base',['[mYY,mXY,mYX,mXX,Ydata,Xdata] = ' ...
'var_sample_moments(options_.first_obs,options_.first_obs+options_.nobs-1,options_.varlag,0);'])
end
end
%% Estimation of the posterior mode or likelihood mode %% Estimation of the posterior mode or likelihood mode
if options_.mode_compute > 0 & options_.posterior_mode_estimation if options_.mode_compute > 0 & options_.posterior_mode_estimation
@ -827,7 +835,7 @@ end
if ~((any(bayestopt_.pshape > 0) & options_.mh_replic) | (any(bayestopt_.pshape ... if ~((any(bayestopt_.pshape > 0) & options_.mh_replic) | (any(bayestopt_.pshape ...
> 0) & options_.load_mh_file)) | ~options_.smoother > 0) & options_.load_mh_file)) | ~options_.smoother
%% ML estimation, or posterior mode without metropolis-hastings or metropolis without bayesian smooth variables %% ML estimation, or posterior mode without metropolis-hastings or metropolis without bayesian smooth variable
options_.lik_algo = 2; options_.lik_algo = 2;
[atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff] = DsgeSmoother(xparam1,gend,data); [atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff] = DsgeSmoother(xparam1,gend,data);
for i=1:M_.endo_nbr for i=1:M_.endo_nbr

View File

@ -29,7 +29,7 @@ if trend == -1% No constant
X = zeros(NumberOfObservations,NumberOfVariables*qlag); X = zeros(NumberOfObservations,NumberOfVariables*qlag);
elseif trend == 0% Constant elseif trend == 0% Constant
X = zeros(NumberOfObservations,NumberOfVariables*qlag+1); X = zeros(NumberOfObservations,NumberOfVariables*qlag+1);
indx = NumberOfVariables*qlag+1; indx = NumberOfVariables*qlag+1:NumberOfVariables*qlag+NumberOfVariables;
elseif trend == 1;% Constant + Trend elseif trend == 1;% Constant + Trend
X = zeros(NumberOfObservations,NumberOfVariables*qlag+2); X = zeros(NumberOfObservations,NumberOfVariables*qlag+2);
indx = NumberOfVariables*qlag+1:NumberOfVariables*qlag+2; indx = NumberOfVariables*qlag+1:NumberOfVariables*qlag+2;
@ -45,7 +45,7 @@ for t=1:NumberOfObservations
X(t,(lag-1)*NumberOfVariables+1:lag*NumberOfVariables) = data(line-lag,:); X(t,(lag-1)*NumberOfVariables+1:lag*NumberOfVariables) = data(line-lag,:);
end end
if trend == 0 if trend == 0
X(t,indx) = 1; X(t,indx) = ones(1,NumberOfVariables);
elseif trend == 1 elseif trend == 1
X(t,indx) = [ 1 , t ]; X(t,indx) = [ 1 , t ];
end end