R solve.QP 跟踪误差最小化约束不一致
R solve.QP tracking error minimization constraints inconsistent
我正在努力 Solve.QP 以获得最小化跟踪错误的解决方案。我有一个由 6 个资产组成的基准(asset_a 到 asset_f)。对于我的投资组合,我有上限和下限(我不能在 asset_f 中拥有头寸)。还给出了 cov 矩阵。我想获得 6 种资产的投资组合权重,以最小化跟踪误差与基准(asset_f 中的位置等于零)。
基准:
- asset_a: 0.3
- asset_b: 0.3
- asset_c: 0.1
- asset_d: 0.1
- asset_e: 0.1
- asset_f: 0.1
下界:
- asset_a: 0.166
- asset_b: 0.133
- asset_c: 0.037
- asset_d: 0.035
- asset_e: 0.039
- asset_f: 0
上限:
- asset_a: 1
- asset_b: 1
- asset_c: 1
- asset_d: 1
- asset_e: 1
- asset_f: 0
基准权重和界限:
test.benchmark_weights = c(0.3, 0.3, 0.1, 0.1, 0.1, 0.1)
test.lowerbound = c(0.166, 0.133, 0.037, 0.035, 0.039,0)
test.upperbound = c(1, 1, 1, 1, 1, 0)
cov 矩阵 (test.Dmat):
test.dmat = matrix(c(0.0119127162, 0.010862842, 0.010266683, 0.0009550136, 0.008242322, 0.00964462, 0.0108628421, 0.010603072, 0.009872992, 0.0011019412, 0.007422522, 0.0092528873, 0.0102666826, 0.009872992, 0.010487808, 0.0012107665, 0.006489204, 0.0096216627, 0.0009550136, 0.001101941, 0.001210766, 0.0115527788, 0.001181745, 0.0008387247, 0.0082423222, 0.007422522, 0.006489204, 0.0011817453, 0.012920482, 0.005973886, 0.00964462, 0.009252887, 0.009621663, 0.0008387247, 0.005973886, 0.0089904809), nrow=6, ncol=6)
dvec (test.dvec):
test.dvec = matrix(c(0, 0, 0, 0, 0, 0), nrow=6, ncol=1)
Amat 约束矩阵 (test.Amat):
test.amat = matrix(c(1,1,1,1,1,1, 1,1,1,1,1,0, -1,0,0,0,0,0, 0,-1,0,0,0,0, 0,0,-1,0,0,0, 0,0,0,-1,0,0, 0,0,0,0,-1,0, 0,0,0,0,0,-1, 1,0,0,0,0,0, 0,1,0,0,0,0, 0,0,1,0,0,0, 0,0,0,1,0,0, 0,0,0,0,1,0, 0,0,0,0,0,0, -1,0,0,0,0,0, 0,-1,0,0,0,0, 0,0,-1,0,0,0, 0,0,0,-1,0,0, 0,0,0,0,-1,0, 0,0,0,0,0,0), nrow=6, ncol=20)
bvec (test.bvec)
test.bvec =cbind(0, 1, t(test.benchmark_weights), t(test.lowerbound), -t(test.upperbound)) %>% as.matrix()
然后运行求解器
solve.QP(as.matrix(test.Dmat), test.dvec, test.Amat, test.bvec)
给我
约束不一致,无解!
您的 Amat
和 bvec
似乎有问题,即您不必传入等于 1 的前 5 个资产的权重总和等于 1 的 6 个资产的权重总和1 和基准权重不是约束,但边界是:
library(quadprog)
N = 6L
test.dvec = rep(0, N)
test.amat = cbind(
rep(1, N),
diag(1, N),
diag(-1, N))
test.bvec = c(1, test.lowerbound, -test.upperbound)
res = solve.QP(test.dmat, test.dvec, test.amat, test.bvec, meq=1L)
round(res$solution, 2)
#[1] 0.17 0.13 0.10 0.44 0.17 0.00
我正在努力 Solve.QP 以获得最小化跟踪错误的解决方案。我有一个由 6 个资产组成的基准(asset_a 到 asset_f)。对于我的投资组合,我有上限和下限(我不能在 asset_f 中拥有头寸)。还给出了 cov 矩阵。我想获得 6 种资产的投资组合权重,以最小化跟踪误差与基准(asset_f 中的位置等于零)。
基准:
- asset_a: 0.3
- asset_b: 0.3
- asset_c: 0.1
- asset_d: 0.1
- asset_e: 0.1
- asset_f: 0.1
下界:
- asset_a: 0.166
- asset_b: 0.133
- asset_c: 0.037
- asset_d: 0.035
- asset_e: 0.039
- asset_f: 0
上限:
- asset_a: 1
- asset_b: 1
- asset_c: 1
- asset_d: 1
- asset_e: 1
- asset_f: 0
基准权重和界限:
test.benchmark_weights = c(0.3, 0.3, 0.1, 0.1, 0.1, 0.1)
test.lowerbound = c(0.166, 0.133, 0.037, 0.035, 0.039,0)
test.upperbound = c(1, 1, 1, 1, 1, 0)
cov 矩阵 (test.Dmat):
test.dmat = matrix(c(0.0119127162, 0.010862842, 0.010266683, 0.0009550136, 0.008242322, 0.00964462, 0.0108628421, 0.010603072, 0.009872992, 0.0011019412, 0.007422522, 0.0092528873, 0.0102666826, 0.009872992, 0.010487808, 0.0012107665, 0.006489204, 0.0096216627, 0.0009550136, 0.001101941, 0.001210766, 0.0115527788, 0.001181745, 0.0008387247, 0.0082423222, 0.007422522, 0.006489204, 0.0011817453, 0.012920482, 0.005973886, 0.00964462, 0.009252887, 0.009621663, 0.0008387247, 0.005973886, 0.0089904809), nrow=6, ncol=6)
dvec (test.dvec):
test.dvec = matrix(c(0, 0, 0, 0, 0, 0), nrow=6, ncol=1)
Amat 约束矩阵 (test.Amat):
test.amat = matrix(c(1,1,1,1,1,1, 1,1,1,1,1,0, -1,0,0,0,0,0, 0,-1,0,0,0,0, 0,0,-1,0,0,0, 0,0,0,-1,0,0, 0,0,0,0,-1,0, 0,0,0,0,0,-1, 1,0,0,0,0,0, 0,1,0,0,0,0, 0,0,1,0,0,0, 0,0,0,1,0,0, 0,0,0,0,1,0, 0,0,0,0,0,0, -1,0,0,0,0,0, 0,-1,0,0,0,0, 0,0,-1,0,0,0, 0,0,0,-1,0,0, 0,0,0,0,-1,0, 0,0,0,0,0,0), nrow=6, ncol=20)
bvec (test.bvec)
test.bvec =cbind(0, 1, t(test.benchmark_weights), t(test.lowerbound), -t(test.upperbound)) %>% as.matrix()
然后运行求解器
solve.QP(as.matrix(test.Dmat), test.dvec, test.Amat, test.bvec)
给我
约束不一致,无解!
您的 Amat
和 bvec
似乎有问题,即您不必传入等于 1 的前 5 个资产的权重总和等于 1 的 6 个资产的权重总和1 和基准权重不是约束,但边界是:
library(quadprog)
N = 6L
test.dvec = rep(0, N)
test.amat = cbind(
rep(1, N),
diag(1, N),
diag(-1, N))
test.bvec = c(1, test.lowerbound, -test.upperbound)
res = solve.QP(test.dmat, test.dvec, test.amat, test.bvec, meq=1L)
round(res$solution, 2)
#[1] 0.17 0.13 0.10 0.44 0.17 0.00