R 中級投資組合分析
Ross Bennett
Instructor
許多求解器並非專為投資組合最佳化設計
瞭解求解器的能力與限制,才能選對工具,或調整問題以適配求解器
在不同求解器間切換不易
封閉形式求解器(例如 quadratic programming)
全域求解器(例如 differential evolution optimization)
$$\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 中級投資組合分析