对于CAPM(资本资产定价模型)的非线性测试,我想在假设beta(bi)和期望收益(x)是条件变量(z)的线性函数的情况下测试参数稳定性
继Ghysels(1998)之后,我想使用GMM在以下时刻条件下计算参数: GMM moment conditions
这是我的代码:
gl <- function(theta, x) {
g_PF <- function(a) {
aa1 <- (x[,a] * z[,1]) - ((z[,1:3] %*% matrix(theta[(a*3-2):(a*3)],3,1)) * z[,1])
aa2 <- (x[,a] * z[,2]) - ((z[,1:3] %*% matrix(theta[(a*3-2):(a*3)],3,1)) * z[,2])
aa3 <- (x[,a] * z[,3]) - ((z[,1:3] %*% matrix(theta[(a*3-2):(a*3)],3,1)) * z[,3])
ab1 <- (((z[,1:3] %*% matrix(theta[(a*3-2):(a*3)],3,1)) * z[,1]) - ((z[,1:3] %*% matrix(bi[((a+2)/3), 1:3], 3, 1) * z[,1:3] %*% matrix(theta[19:21],3,1)) * z[,1]))
ab2 <- (((z[,1:3] %*% matrix(theta[(a*3-2):(a*3)],3,1)) * z[,2]) - ((z[,1:3] %*% matrix(bi[((a+2)/3), 1:3], 3, 1) * z[,1:3] %*% matrix(theta[19:21],3,1)) * z[,2]))
ab3 <- (((z[,1:3] %*% matrix(theta[(a*3-2):(a*3)],3,1)) * z[,3]) - ((z[,1:3] %*% matrix(bi[((a+2)/3), 1:3], 3, 1) * z[,1:3] %*% matrix(theta[19:21],3,1)) * z[,3]))
mocon <- cbind(aa1, aa2, aa3, ab1, ab2, ab3)
return(mocon)
}
g_M <- function(b) {
bb1 <- (x[,b] * z[,1]) - ((z[,1:3] %*% matrix(theta[(b*3-2):(b*3)],3,1)) * z[,1])
bb2 <- (x[,b] * z[,2]) - ((z[,1:3] %*% matrix(theta[(b*3-2):(b*3)],3,1)) * z[,2])
bb3 <- (x[,b] * z[,3]) - ((z[,1:3] %*% matrix(theta[(b*3-2):(b*3)],3,1)) * z[,3])
mocon1 <- cbind(bb1, bb2, bb3)
return(mocon1)
}
#Moment conditions:
MSL <- g_PF(a = 1)
MSM <- g_PF(a = 2)
MSB <- g_PF(a = 3)
MHL <- g_PF(a = 4)
MHM <- g_PF(a = 5)
MHB <- g_PF(a = 6)
MM <- g_M(b = 7)
gmat <- cbind(MSL, MSM, MSB, MHL, MHM, MHB, MM)
return(gmat)
}
ress <- gmm(g = gl,x = x, rep(0,21))
summary(ress)
函数gl用于生成力矩条件,而期望的输出将是21个参数的向量(3个参数 - 两个调节变量+常数 - 用于六个测试投资组合+市场投资组合)。
当我运行我的代码时,我收到以下错误消息:
Error in AA %*% t(X) : requires numeric/complex matrix/vector arguments
In addition: Warning message:
In ar.ols(x, aic = aic, order.max = order.max, na.action = na.action, :
model order: 1 singularities in the computation of the projection matrix results are only valid up to model order 0
这是我的回报,beta和conditoning变量的数据: