Commit e7a65da2 authored by adjemian's avatar adjemian
Browse files

DsgeSmoother() returns the state equation + documentation.

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1249 ac1d8469-bf42-47a9-8791-bf33cf982152
parent cec9b756
......@@ -18,7 +18,7 @@ spinf = size(Pinf1);
spstar = size(Pstar1);
v = zeros(pp,smpl);
a = zeros(mm,smpl+1);
aK = zeros(nk,mm,smpl+nk);
aK = zeros(nk,mm,smpl+nk);
iF = zeros(pp,pp,smpl);
Fstar = zeros(pp,pp,smpl);
iFinf = zeros(pp,pp,smpl);
......@@ -30,19 +30,19 @@ P = zeros(mm,mm,smpl+1);
Pstar = zeros(spstar(1),spstar(2),smpl+1); Pstar(:,:,1) = Pstar1;
Pinf = zeros(spinf(1),spinf(2),smpl+1); Pinf(:,:,1) = Pinf1;
crit = options_.kalman_tol;
crit1 = 1.e-8;
crit1 = 1.e-8;
steady = smpl;
rr = size(Q,1);
QQ = R*Q*transpose(R);
QRt = Q*transpose(R);
QRt = Q*transpose(R);
alphahat = zeros(mm,smpl);
etahat = zeros(rr,smpl);
epsilonhat = zeros(size(Y));
r = zeros(mm,smpl);
r = zeros(mm,smpl);
Z = zeros(pp,mm);
for i=1:pp;
Z(i,mf(i)) = 1;
Z(i,mf(i)) = 1;
end
t = 0;
......@@ -56,7 +56,7 @@ while rank(Pinf(:,:,t+1),crit1) & t<smpl
Kinf(:,:,t) = T*Pinf(:,mf,t)*iFinf(:,:,t);
a(:,t+1) = T*a(:,t) + Kinf(:,:,t)*v(:,t);
for jnk=1:nk,
aK(jnk,:,t+jnk) = T^(jnk-1)*a(:,t+1);
aK(jnk,:,t+jnk) = T^(jnk-1)*a(:,t+1);
end
Linf(:,:,t) = T - Kinf(:,:,t)*Z;
Fstar(:,:,t) = Pstar(mf,mf,t) + H;
......@@ -85,7 +85,7 @@ while notsteady & t<smpl
L(:,:,t) = T-K(:,:,t)*Z;
a(:,t+1) = T*a(:,t) + K(:,:,t)*v(:,t);
for jnk=1:nk,
aK(jnk,:,t+jnk) = T^(jnk-1)*a(:,t+1);
aK(jnk,:,t+jnk) = T^(jnk-1)*a(:,t+1);
end
P(:,:,t+1) = T*P(:,:,t)*transpose(T)-T*P(:,mf,t)*transpose(K(:,:,t)) + QQ;
notsteady = ~(max(max(abs(P(:,:,t+1)-P(:,:,t))))<crit);
......@@ -105,32 +105,32 @@ while t<smpl
v(:,t) = Y(:,t) - a(mf,t) - trend(:,t);
a(:,t+1) = T*a(:,t) + K_s*v(:,t);
for jnk=1:nk,
aK(jnk,:,t+jnk) = T^(jnk-1)*a(:,t+1);
aK(jnk,:,t+jnk) = T^(jnk-1)*a(:,t+1);
end
end
t = smpl+1;
while t>d+1 & t>2
t = t-1;
r(:,t-1) = transpose(Z)*iF(:,:,t)*v(:,t) + transpose(L(:,:,t))*r(:,t);
alphahat(:,t) = a(:,t) + P(:,:,t)*r(:,t-1);
etahat(:,t) = QRt*r(:,t);
alphahat(:,t) = a(:,t) + P(:,:,t)*r(:,t-1);
etahat(:,t) = QRt*r(:,t);
end
if d
r0 = zeros(mm,d); r0(:,d) = r(:,d);
r1 = zeros(mm,d);
for t = d:-1:2
r0 = zeros(mm,d); r0(:,d) = r(:,d);
r1 = zeros(mm,d);
for t = d:-1:2
r0(:,t-1) = transpose(Linf(:,:,t))*r0(:,t);
r1(:,t-1) = transpose(Z)*(iFinf(:,:,t)*v(:,t)-transpose(Kstar(:,:,t))*r0(:,t)) + transpose(Linf(:,:,t))*r1(:,t);
alphahat(:,t) = a(:,t) + Pstar(:,:,t)*r0(:,t-1) + Pinf(:,:,t)*r1(:,t-1);
etahat(:,t) = QRt*r0(:,t);
end
r0_0 = transpose(Linf(:,:,1))*r0(:,1);
r1_0 = transpose(Z)*(iFinf(:,:,1)*v(:,1)-transpose(Kstar(:,:,1))*r0(:,1)) + transpose(Linf(:,:,1))*r1(:,1);
alphahat(:,1) = a(:,1) + Pstar(:,:,1)*r0_0 + Pinf(:,:,1)*r1_0;
etahat(:,1) = QRt*r0(:,1);
r1(:,t-1) = transpose(Z)*(iFinf(:,:,t)*v(:,t)-transpose(Kstar(:,:,t))*r0(:,t)) + transpose(Linf(:,:,t))*r1(:,t);
alphahat(:,t) = a(:,t) + Pstar(:,:,t)*r0(:,t-1) + Pinf(:,:,t)*r1(:,t-1);
etahat(:,t) = QRt*r0(:,t);
end
r0_0 = transpose(Linf(:,:,1))*r0(:,1);
r1_0 = transpose(Z)*(iFinf(:,:,1)*v(:,1)-transpose(Kstar(:,:,1))*r0(:,1)) + transpose(Linf(:,:,1))*r1(:,1);
alphahat(:,1) = a(:,1) + Pstar(:,:,1)*r0_0 + Pinf(:,:,1)*r1_0;
etahat(:,1) = QRt*r0(:,1);
else
r0 = transpose(Z)*iF(:,:,1)*v(:,1) + transpose(L(:,:,1))*r(:,1);
alphahat(:,1) = a(:,1) + P(:,:,1)*r0;
alphahat(:,1) = a(:,1) + P(:,:,1)*r0;
etahat(:,1) = QRt*r(:,1);
end
epsilonhat = Y-alphahat(mf,:)-trend;
epsilonhat = Y-alphahat(mf,:)-trend;
\ No newline at end of file
function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK] = DsgeSmoother(xparam1,gend,Y)
% stephane.adjemian@cepremap.cnrs.fr [09-07-2004]
function [alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R] = DsgeSmoother(xparam1,gend,Y)
% Estimation of the smoothed variables and innovations.
%
% INPUTS
% o xparam1 [double] (p*1) vector of (estimated) parameters.
% o gend [integer] scalar specifying the number of observations ==> varargin{1}.
% o data [double] (T*n) matrix of data.
%
% OUTPUTS
% o alphahat [double] (m*T) matrix, smoothed endogenous variables.
% o etahat [double] (r*T) matrix, smoothed structural shocks (r>n is the umber of shocks).
% o epsilonhat [double] (n*T) matrix, smoothed measurement errors.
% o ahat [double] (m*T) matrix, one step ahead filtered (endogenous) variables.
% o SteadyState [double] (m*1) vector specifying the steady state level of each endogenous variable.
% o trend_coeff [double] (n*1) vector, parameters specifying the slope of the trend associated to each observed variable.
% o aK [double] (K,n,T+K) array, k (k=1,...,K) steps ahead filtered (endogenous) variables.
% o T and R [double] Matrices defining the state equation (T is the (m*m) transition matrix).
% ALGORITHM
% Metropolis-Hastings.
%
% Adapted from mj_optmumlik.m
% SPECIAL REQUIREMENTS
% None.
%
%
% part of DYNARE, copyright S. Adjemian, M. Juillard (2006)
% Gnu Public License.
global bayestopt_ M_ oo_ estim_params_ options_
alphahat = [];
epsilonhat = [];
etahat = [];
etahat = [];
nobs = size(options_.varobs,1);
smpl = size(Y,2);
smpl = size(Y,2);
set_all_parameters(xparam1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment