function [AHess] = AHessian(T,R,Q,H,P,Y,DT,DYss,DOm,DH,DP,start,mf,kalman_tol,riccati_tol) % function [AHess] = AHessian(T,R,Q,H,P,Y,DT,DYss,DOm,DH,DP,start,mf,kalman_tol,riccati_tol) % % computes the asymptotic hessian matrix of the log-likelihood function of % a state space model (notation as in kalman_filter.m in DYNARE % Thanks to Nikolai Iskrev % % NOTE: the derivative matrices (DT,DR ...) are 3-dim. arrays with last % dimension equal to the number of structural parameters % Copyright (C) 2011 Dynare Team % % This file is part of Dynare. % % Dynare is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % Dynare is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with Dynare. If not, see =start AHess = AHess + Dv'*iPmf*Dv + .5*(vecDPmf' * kron(iPmf,iPmf) * vecDPmf); end a = T*(a+K*v); P = T*(P-K*P(mf,:))*transpose(T)+Om; DP = DP1; end notsteady = max(max(abs(K-oldK))) > riccati_tol; oldK = K; end if F_singular error('The variance of the forecast error remains singular until the end of the sample') end if t < smpl t0 = t+1; while t < smpl t = t+1; v = Y(:,t)-a(mf); for ii = 1:k Dv(:,ii) = -Da(mf,ii)-DYss(mf,ii); Da(:,ii) = DT(:,:,ii)*(a+K*v) + T*(Da(:,ii)+DK(:,:,ii)*v + K*Dv(:,ii)); end if t>=start AHess = AHess + Dv'*iPmf*Dv; end a = T*(a+K*v); end AHess = AHess + .5*(smpl+t0-1)*(vecDPmf' * kron(iPmf,iPmf) * vecDPmf); % for ii = 1:k; % for jj = 1:ii % H(ii,jj) = trace(iPmf*(.5*DP(mf,mf,ii)*iPmf*DP(mf,mf,jj) + Dv(:,ii)*Dv(:,jj)')); % end % end end AHess = -AHess; % end of main function function [DK,DF,DP1] = computeDKalman(T,DT,DOm,P,DP,DH,mf,iF,K) k = size(DT,3); tmp = P-K*P(mf,:); for ii = 1:k DF(:,:,ii) = DP(mf,mf,ii) + DH(:,:,ii); DiF(:,:,ii) = -iF*DF(:,:,ii)*iF; DK(:,:,ii) = DP(:,mf,ii)*iF + P(:,mf)*DiF(:,:,ii); Dtmp = DP(:,:,ii) - DK(:,:,ii)*P(mf,:) - K*DP(mf,:,ii); DP1(:,:,ii) = DT(:,:,ii)*tmp*T' + T*Dtmp*T' + T*tmp*DT(:,:,ii)' + DOm(:,:,ii); end % end of computeDKalman