资源简介
此代码为贝叶斯潜在多动态因子模型,用贝叶斯方法来估计因子
代码片段和文件信息
%BAYES_DFM This implements the state-space estimation of the dynamic
%factors their loadings and autoregressive parameters. The program was
%written by Piotr Eliasz (2003) Princeton University for his PhD thesis and
%and used in Bernake Boivin and Eliasz (2005) published in QJE.
%Modified by Dimitris Korobilis on Monday June 11 2007
%--------------------------------------------------------------------------
% Estimate dynamic factor model:
% X_t = Lam x F_t + e_t
% F_t = B(L) x F_t-1 + u_t
% The previous (Eliasz 2005) version was:
% [X_t ; Y_t] = [Lf Ly ; 0 I] x [F_t ; Y_t] + e_t
% [F_t ; Y_t] = [B(L) ; 0 I] x [F_t-1 ; Y_t-1] + u_t
%
%--------------------------------------------------------------------------
clear all;
clc;
randn(‘seed‘sum(100*clock)); %#ok<*RAND>
rand(‘seed‘sum(100*clock));
%---------------------------LOAD DATA--------------------------------------
% simulated dataset
X=dfmdgp();
[TN]=size(X);
%Demean xraw
X=X-repmat(mean(X)T1);
% Number of factors & lags in B(L):
K=3;
lags=1;
%----------------------------PRELIMINARIES---------------------------------
% Set some Gibbs - related preliminaries
nods = 10000; % Number of draws
bid = 2000; % Number of burn-in-draws
thin = 1; % Consider every thin-th draw (thin value)
% store draws in:
Ldraw=zeros(nods-bidNK);
Bdraw=zeros(nods-bidKKlags);
Qdraw=zeros(nods-bidKK);
Fdraw=zeros(nods-bidTK);
%********************************************************
% STANDARDIZE for PC only
X_st=X./repmat(std(X1)T1);
% First step - extract PC from X
[F0Lf]=extract(X_stK);
% Transform factors and loadings for LE normalization
[qlrl]=qr(Lf‘);
Lf=rl; % do not transpose yet is upper triangular
F0=F0*ql;
% Need identity in the first K columns of Lf call them A for now
A=Lf(:1:K);
Lf=[eye(K)inv(A)*Lf(:(K+1):N)]‘;
F0=F0*A;
% Obtain R:
e=X_st-F0*Lf‘;
R=e‘*e./T;
R=diag(diag(R));
L=Lf;
% Run a VAR in F obtain initial B and Q
[BBcvQinvFF]=estvar(F0lags[]);
% Put it all in state-space representation write obs equ as XY=FY*L+e
XY=X; %Tx(N+M)
FY=F0;
% adjust for lags in state equation Q is KxK
Q=[Q zeros(KK*(lags-1));zeros(K*(lags-1)K*lags)];
B=[B(::);eye(K*(lags-1)) zeros(K*(lags-1)K)];
% start with
Sp=zeros(K*lags1);
Pp=eye(K*lags);
% Proper Priors:-----------------------------------------------------------
% on VAR -- Normal-Wishart after Kadiyala Karlsson 1997
% on Q -- si
% on B -- increasing tightness
% on observable equation:
% N(0I)-iG(30.001)
% prior distributions for VAR part need B and Q
vo=K+2;
s0=3;
alpha=0.001;
L_var_prior=eye(K);
Qi=zeros(K1);
% singles out latent factors
indexnM=ones(Klags);
indexnM=find(indexnM==1);
%***************End of Preliminaries & PriorSpecification******************
tic;
%==========================================================================
%========================== Start Sampling ================================
%=====================================
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2009-09-23 11:53 Factor_Models\
文件 7383 2009-08-09 13:35 Factor_Models\BAYES_DFM.m
文件 706 2009-06-24 02:13 Factor_Models\bernoullirnd.m
文件 3214 2009-06-24 02:31 Factor_Models\BFM.m
文件 479 2009-07-07 00:16 Factor_Models\bfmdgp.m
文件 305 2009-05-29 23:09 Factor_Models\bfmdgp2.m
文件 884 2009-05-29 23:24 Factor_Models\dfmdgp.m
文件 1042 2007-06-20 20:08 Factor_Models\estvar.m
文件 527 2004-07-31 17:23 Factor_Models\extract.m
文件 677 2004-12-29 13:22 Factor_Models\gamrnd.m
文件 294074 2007-06-01 12:28 Factor_Models\Lopez+West (2004) - BAYESIAN MODEL ASSESSMENT IN FACTOR ANALYSIS.pdf
文件 1335 2009-05-29 23:25 Factor_Models\mlag.m
文件 1830 2004-07-31 17:23 Factor_Models\mvnrnd.m
文件 1059 2009-05-29 23:14 Factor_Models\normlt_rnd.m
文件 1827 2009-05-29 23:15 Factor_Models\normt_rnd.m
文件 281 2004-07-31 17:23 Factor_Models\olssvd.m
评论
共有 条评论