0001 function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1,gend,Y)
0002
0003
0004
0005 global bayestopt_ M_ oo_ estim_params_ options_
0006
0007 alphahat = [];
0008 epsilonhat = [];
0009 etahat = [];
0010 nobs = size(options_.varobs,1);
0011 smpl = size(Y,2);
0012
0013 set_all_parameters(xparam1);
0014
0015
0016
0017
0018 [T,R,SteadyState] = dynare_resolve;
0019 bayestopt_.mf = bayestopt_.mf2;
0020 if options_.loglinear == 1
0021 constant = log(SteadyState(bayestopt_.mfys));
0022 else
0023 constant = SteadyState(bayestopt_.mfys);
0024 end
0025 trend_coeff = zeros(nobs,1);
0026 if bayestopt_.with_trend == 1
0027 trend_coeff = zeros(nobs,1);
0028 nx1 = estim_params_.nvx+estim_params_.nvn+estim_params_.ncx+estim_params_.ncn;
0029 for i=1:nobs
0030 trend_coeff(i) = evalin('base',bayestopt_.trend_coeff{i});
0031 end
0032 trend = constant*ones(1,gend)+trend_coeff*(1:gend);
0033 else
0034 trend = constant*ones(1,gend);
0035 end
0036 start = options_.presample+1;
0037 np = size(T,1);
0038 mf = bayestopt_.mf;
0039
0040
0041
0042
0043
0044
0045
0046
0047 Q = M_.Sigma_e;
0048 H = M_.H;
0049
0050 if options_.lik_init == 1
0051 Pstar = lyapunov_symm(T,R*Q*transpose(R));
0052 Pinf = [];
0053 elseif options_.lik_init == 2
0054 Pstar = 10*eye(np);
0055 Pinf = [];
0056 elseif options_.lik_init == 3
0057 Pstar = zeros(np,np);
0058 ivs = bayestopt_.i_T_var_stable;
0059 Pstar(ivs,ivs) = lyapunov_symm(T(ivs,ivs),R(ivs,:)*Q* ...
0060 transpose(R(ivs,:)));
0061 Pinf = bayestopt_.Pinf;
0062
0063 RR=T(:,find(~ismember([1:np],ivs)));
0064 i=find(abs(RR)>1.e-10);
0065 R0=zeros(size(RR));
0066 R0(i)=sign(RR(i));
0067 Pinf=R0*R0';
0068
0069 end
0070
0071
0072
0073 if estim_params_.nvn
0074 if options_.kalman_algo == 1
0075 [alphahat,epsilonhat,etahat,ahat,aK] = DiffuseKalmanSmootherH1(T,R,Q,H,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
0076 if all(alphahat(:)==0)
0077 [alphahat,epsilonhat,etahat,ahat,aK] = DiffuseKalmanSmootherH3(T,R,Q,H,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
0078 end
0079 elseif options_.kalman_algo == 3
0080 [alphahat,epsilonhat,etahat,ahat,aK] = DiffuseKalmanSmootherH3(T,R,Q,H,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
0081 end
0082 else
0083 if options_.kalman_algo == 1
0084 [alphahat,etahat,ahat,aK] = DiffuseKalmanSmoother1(T,R,Q,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
0085 if all(alphahat(:)==0)
0086 [alphahat,etahat,ahat,aK] = DiffuseKalmanSmoother3(T,R,Q,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
0087 end
0088 elseif options_.kalman_algo == 3
0089 [alphahat,etahat,ahat,aK] = DiffuseKalmanSmoother3(T,R,Q,Pinf,Pstar,Y,trend,nobs,np,smpl,mf);
0090 end
0091 end