R 中级投资组合分析
Ross Bennett
Instructor
许多求解器并非专为投资组合优化设计
需了解求解器能力与边界,以便选对求解器,或重塑问题以适配
在求解器间切换困难
闭式求解器(如二次规划)
全局求解器(如差分进化优化)
$$\omega_{i} >= 0$$
$$\sum_{i=1}^{n} \omega_i = 1$$
使用 R 包 quadprog 求解二次效用优化问题
solve.QP() 解决如下形式的二次规划:
$$min(-d^Tb+\frac{1}{2}b^TDb)$$
$$A^Tb>=b_0$$
library(quadprog)
data(edhec)
dat <- edhec[,1:4]
# Create the constraint matrix
Amat <- cbind(1, diag(ncol(dat)), -diag(ncol(dat)))
# Create the constraint vector
bvec <- c(1, rep(0, ncol(dat)), -rep(1, ncol(dat)))
# Create the objective matrix
Dmat <- 10 * cov(dat)
# Create the objective vector
dvec <- colMeans(dat)
# Specify number of equality constraints
meq <- 1
# Solve the optimization problem
opt <- solve.QP(Dmat, dvec, Amat, bvec, meq)
R 中级投资组合分析