我正在使用quadprog
两个约束(资产权重之和等于 1)进行优化,资产权重在 0 到 10% 之间。一切正常,但我不明白的结果与我的结果相反。当TAU
(我的风险承受能力)最低(= 0)时,我的结果矩阵中的值应该最低。这就是说,在我最低的风险承受能力下,我将获得最低的回报。这遵循现代投资组合理论。同样,当TAU
我的返回向量最高时,我的返回向量也应该最高。我知道发生了一些逆或符号错误。有人可以解释吗?
mu #return vector of our 30 assets
Dmatrix <- Q #covariance matrix
na <- 30 #number of assets
wmin <- 0 #minimum weight of an asset
wmax <- 0.1 #maximum weight of an asset, 10% = 0.1
A <- rbind(1,-diag(na), diag(na)) #A matrix with proper diagonals for linear algebra
b <- c(1, -rep(wmax, na), rep(wmin, na)) #b vector to store weights
print(b)
# [1] 1.0 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 -0.1
#[26] -0.1 -0.1 -0.1 -0.1 -0.1 -0.1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
#[51] 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
#cbind(A, b)
TAU <- seq(0, 0.5, by = 0.001) ## choose an appropriate stepsize
results <- numeric(length(TAU))
weights <- array(NA, dim = c(na, length(TAU)))
for (i in seq_along(TAU)) {
solQP <- solve.QP(Dmat = Dmatrix,
dvec = TAU[i]*mu,
Amat = t(A),
bvec = b, meq = 1)
## an equivalent computation
## NMOF::mvPortfolio(mu, V, wmax = 0.1, lambda = c(TAU[i], 0.5))
results[i] <- solQP$value
weights[, i] <- solQP$solution
}
results[1] #TAU = 0
#[1] 0.2214824
results[501] #TAU = 0.5
#[1] 0.2046475