在大型面板上运行多元线性状态空间模型的有效方法(Fama French)

时间:2015-03-10 10:41:20

标签: r state-space

我试图估算一组股票的多元线性状态空间模型。我每天都有超过15年的回报,并将它们按照每月的时间序列进行了整理。除此之外,MLE估计的整个过程需要花费大量时间才能完成。有没有一种有效的方法来处理这个问题?

该模型是m资产的动态Fama-French三因子模型的多变量版本,j = 1,...,m。因子以x(t)加载。模型是:

y = α + β1 * x1 + β2 * x2 + β3 * x3 + v

α(t) = α(t-1) + w1 
β1(t) = β1(t-1) + w2
β2(t) = β1(t-1) + w3
β3(t) = β1(t-1) + w4

假设截距和斜率在m个股票之间是相关的是明智的。上述模型可以用更通用的形式重写,例如

y(t) = (Ft⊗Im)θ + υt, υt∼N(0,V)
θt = (G⊗Im)θ(t−1) + ωt, ωt∼N(0,W)

,其中

yt=[y1t,…,ymt] are the values of the m different y series
θt=[α1t,…,αmt,β1_1p,…,β1_mt,β2_1p,…,β2_1mt, β3_1p,…,β3_mt ]
υt=[υ1t,…,υmt] and ωt=[ω1t,…,ωmt] are iid
W=blockdiag(Wα;Wβ1;Wβ3;Wβ3)
Ft=[1xt]; and G=I_4

我正在使用dlm包,这里是代码的快照:

I assume for simplicity that the αj,t are time-invariant, which amounts to     
assuming that Wα=0

m <- NCOL(ret)
q <- NCOL(factors) + 1  #factors + alpha 
d <- sum((as.numeric(upper.tri(diag(m)))))

# Define a “build” function to be given to MLE routine
buildSUR <- function(psi) {
  ### Set up the model
  CAPM <- dlmModReg(factors, addInt = TRUE)
  CAPM$FF <- CAPM$FF %x% diag(m)
  CAPM$GG <- CAPM$GG %x% diag(m)
  CAPM$JFF <- CAPM$JFF %x% diag(m)

  # specifying the mean of the distribution of the initial state of theta    (alpha; beta1; beta2; beta3; beta4)
  CAPM$m0 <- c(rep(0,q*m))

  # Specifying the variance of the distribution of the initial state of theta  (alpha; beta1; beta2; beta3; beta4)
  CAPM$C0 <- CAPM$C0 %x% diag(m)

  # ’CLEAN’ the system and observation variance-covariance matrices
  CAPM$V <- CAPM$V %x% matrix(0, m, m)
  CAPM$W <- CAPM$W %x% matrix(0, m, m)

  # parametrization of the covariance matrix W
  U <- matrix(0, nrow = m, ncol = m)
  U2 <- matrix(0, nrow = m, ncol = m)
  U3 <- matrix(0, nrow = m, ncol = m)
  U4 <- matrix(0, nrow = m, ncol = m)

  # putting random element in the upper triangle and making sure that the   diagonal element of U are positive
  U[upper.tri(U)] <- psi[1 : d]
  diag(U) <- exp(0.5 * psi[(d+1) : (m+d)])
  U2[upper.tri(U2)] <- psi[(m+d+1) : (m+2*d)]
  diag(U2) <- exp(0.5 * psi[(m+2*d+1) : (2*m+2*d)])
  U3[upper.tri(U2)] <- psi[(2*m+2*d+1) : (2*m+3*d)]
  diag(U3) <- exp(0.5 * psi[(2*m+3*d+1) : (3*m+3*d)])
  U4[upper.tri(U2)] <- psi[(3*m+3*d+1) : (3*m+4*d)]
  diag(U4) <- exp(0.5 * psi[(3*m+4*d+1) : (4*m+4*d)])

  #Constructing the matrix W_beta as the cross product of the U - equivalent to t(U) %*% U
  # Assuming W_alpha is zero, U for beta1, U2 for beta2 etc.
  W(CAPM)[(m+1) : (2*m), (m+1) : (2*m)] <- crossprod(U)
  W(CAPM)[(2*m+1) : (3*m), (2*m+1) : (3*m)] <- crossprod(U2)
  W(CAPM)[(3*m+1) : (4*m), (3*m+1) : (4*m)] <- crossprod(U3)
  W(CAPM)[(4*m+1) : (5*m), (4*m+1) : (5*m)] <- crossprod(U4)

  # parametrization of the covariance matrix V
  U5 <- matrix(0, nrow = m, ncol = m)
  # putting random element in the upper triangle
  U5[upper.tri(U5)] <- psi[(4*m+4*d+1) : (4*m+5*d)]
  # making the diagonal element positive
  diag(U5) <- exp(0.5 * psi[(4*m+5*d+1) : (5*m+5*d)])
  V(CAPM) <- crossprod(U5)
  return(CAPM)
}
#MLE Estimate
CAPM_MLE <- dlmMLE(ret, rep(1, (5*m+5*d)), buildSUR, control = list(maxit =   500)).

1 个答案:

答案 0 :(得分:0)

我自己回答。股票需要不同的初始值才能通过MLE估算,因此我使用lm.fit的初始值单独运行每个股票的循环。