2006-03-05 22:01:27 +01:00
|
|
|
|
function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1,gend,Y)
|
2005-02-18 20:54:39 +01:00
|
|
|
|
% stephane.adjemian@cepremap.cnrs.fr [09-07-2004]
|
|
|
|
|
%
|
|
|
|
|
% Adapted from mj_optmumlik.m
|
2005-09-11 11:38:52 +02:00
|
|
|
|
global bayestopt_ M_ oo_ estim_params_ options_
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
2005-09-11 11:38:52 +02:00
|
|
|
|
alphahat = [];
|
|
|
|
|
epsilonhat = [];
|
|
|
|
|
etahat = [];
|
|
|
|
|
nobs = size(options_.varobs,1);
|
|
|
|
|
smpl = size(Y,2);
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
2006-03-05 22:01:27 +01:00
|
|
|
|
set_all_parameters(xparam1);
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
2005-09-11 11:38:52 +02:00
|
|
|
|
%------------------------------------------------------------------------------
|
|
|
|
|
% 2. call model setup & reduction program
|
|
|
|
|
%------------------------------------------------------------------------------
|
|
|
|
|
[T,R,SteadyState] = dynare_resolve;
|
2006-06-03 21:45:05 +02:00
|
|
|
|
bayestopt_.mf = bayestopt_.mf2;
|
2005-09-11 11:38:52 +02:00
|
|
|
|
if options_.loglinear == 1
|
|
|
|
|
constant = log(SteadyState(bayestopt_.mfys));
|
|
|
|
|
else
|
|
|
|
|
constant = SteadyState(bayestopt_.mfys);
|
|
|
|
|
end
|
|
|
|
|
trend_coeff = zeros(nobs,1);
|
|
|
|
|
if bayestopt_.with_trend == 1
|
|
|
|
|
trend_coeff = zeros(nobs,1);
|
|
|
|
|
nx1 = estim_params_.nvx+estim_params_.nvn+estim_params_.ncx+estim_params_.ncn;
|
|
|
|
|
for i=1:nobs
|
|
|
|
|
trend_coeff(i) = evalin('base',bayestopt_.trend_coeff{i});
|
|
|
|
|
end
|
|
|
|
|
trend = constant*ones(1,gend)+trend_coeff*(1:gend);
|
|
|
|
|
else
|
|
|
|
|
trend = constant*ones(1,gend);
|
|
|
|
|
end
|
|
|
|
|
start = options_.presample+1;
|
|
|
|
|
np = size(T,1);
|
|
|
|
|
mf = bayestopt_.mf;
|
|
|
|
|
% ------------------------------------------------------------------------------
|
|
|
|
|
% 3. Initial condition of the Kalman filter
|
|
|
|
|
% ------------------------------------------------------------------------------
|
|
|
|
|
%
|
|
|
|
|
% C'est ici qu'il faut d<>terminer Pinf et Pstar. Si le mod<6F>le est stationnaire,
|
|
|
|
|
% alors il suffit de poser Pstar comme la solution de l'<27>uation de Lyapounov et
|
|
|
|
|
% Pinf=[].
|
|
|
|
|
%
|
2006-03-05 22:01:27 +01:00
|
|
|
|
Q = M_.Sigma_e;
|
|
|
|
|
H = M_.H;
|
|
|
|
|
|
2005-09-11 11:38:52 +02:00
|
|
|
|
if options_.lik_init == 1 % Kalman filter
|
|
|
|
|
Pstar = lyapunov_symm(T,R*Q*transpose(R));
|
|
|
|
|
Pinf = [];
|
|
|
|
|
elseif options_.lik_init == 2 % Old Diffuse Kalman filter
|
|
|
|
|
Pstar = 10*eye(np);
|
|
|
|
|
Pinf = [];
|
|
|
|
|
elseif options_.lik_init == 3 % Diffuse Kalman filter
|
|
|
|
|
Pstar = zeros(np,np);
|
2006-09-18 21:36:10 +02:00
|
|
|
|
ivs = bayestopt_.var_list_stationary;
|
2005-09-11 11:38:52 +02:00
|
|
|
|
Pstar(ivs,ivs) = lyapunov_symm(T(ivs,ivs),R(ivs,:)*Q* ...
|
|
|
|
|
transpose(R(ivs,:)));
|
2006-09-18 21:36:10 +02:00
|
|
|
|
% Pinf = bayestopt_.Pinf;
|
2006-03-03 14:13:00 +01:00
|
|
|
|
% by M. Ratto
|
|
|
|
|
RR=T(:,find(~ismember([1:np],ivs)));
|
|
|
|
|
i=find(abs(RR)>1.e-10);
|
|
|
|
|
R0=zeros(size(RR));
|
|
|
|
|
R0(i)=sign(RR(i));
|
|
|
|
|
Pinf=R0*R0';
|
|
|
|
|
% by M. Ratto
|
2005-09-11 11:38:52 +02:00
|
|
|
|
end
|
|
|
|
|
% -----------------------------------------------------------------------------
|
|
|
|
|
% 4. Kalman smoother
|
|
|
|
|
% -----------------------------------------------------------------------------
|
|
|
|
|
if estim_params_.nvn
|
|
|
|
|
if options_.kalman_algo == 1
|
2006-03-05 22:01:27 +01:00
|
|
|
|
[alphahat,epsilonhat,etahat,ahat,aK] = DiffuseKalmanSmootherH1(T,R,Q,H,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
|
2005-09-11 11:38:52 +02:00
|
|
|
|
if all(alphahat(:)==0)
|
2006-03-05 22:01:27 +01:00
|
|
|
|
[alphahat,epsilonhat,etahat,ahat,aK] = DiffuseKalmanSmootherH3(T,R,Q,H,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
|
2005-09-11 11:38:52 +02:00
|
|
|
|
end
|
|
|
|
|
elseif options_.kalman_algo == 3
|
2006-03-05 22:01:27 +01:00
|
|
|
|
[alphahat,epsilonhat,etahat,ahat,aK] = DiffuseKalmanSmootherH3(T,R,Q,H,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
|
2005-09-11 11:38:52 +02:00
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if options_.kalman_algo == 1
|
2006-03-05 22:01:27 +01:00
|
|
|
|
[alphahat,etahat,ahat,aK] = DiffuseKalmanSmoother1(T,R,Q,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
|
2005-09-11 11:38:52 +02:00
|
|
|
|
if all(alphahat(:)==0)
|
2006-03-13 11:57:01 +01:00
|
|
|
|
[alphahat,etahat,ahat,aK] = DiffuseKalmanSmoother3(T,R,Q,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
|
2005-09-11 11:38:52 +02:00
|
|
|
|
end
|
|
|
|
|
elseif options_.kalman_algo == 3
|
2006-03-05 22:01:27 +01:00
|
|
|
|
[alphahat,etahat,ahat,aK] = DiffuseKalmanSmoother3(T,R,Q,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
|
2005-09-11 11:38:52 +02:00
|
|
|
|
end
|
|
|
|
|
end
|