R解。QP跟踪误差最小化约束不一致

问题描述 投票:0回答:1

我在Solve.QP方面苦苦挣扎,以寻求最小化跟踪误差的解决方案。我有一个包含6个资产(asset_a至asset_f)的基准。对于我的投资组合,我有上限和下限(我不能在asset_f中拥有头寸)。还给出了cov矩阵。我想获得6种资产的投资组合权重,以将跟踪误差与基准的误差最小化(asset_f中的头寸等于零)。

基准:

  1. asset_a:0.3
  2. asset_b:0.3
  3. asset_c:0.1
  4. assed_d:0.1
  5. asset_e:0.1
  6. asset_f:0.1

下限:

  1. asset_a:0.166
  2. asset_b:0.133
  3. asset_c:0.037
  4. assed_d:0.035
  5. asset_e:0.039
  6. asset_f:0

上限:

  1. asset_a:1
  2. asset_b:1
  3. asset_c:1
  4. asset_d:1
  5. asset_e:1
  6. 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)

给我

约束不一致,无解!

r optimization portfolio quadratic-programming r-portfolioanalytics
1个回答
1
投票

[好像您的Amatbvec出了点问题,即您不必同时传递前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
© www.soinside.com 2019 - 2024. All rights reserved.