R 中的投资组合优化与交易成本

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

目标是使用交易成本作为惩罚来重新平衡投资组合。

我尝试用 mosek 主页的交易成本重写投资组合优化示例:https://docs.mosek.com/latest/rmosek/case-studies-portfolio.html#transaction-costs 以最大限度地降低风险在给定一定风险的情况下最大化回报。

 GT     <- rbind( c(0.30758, 0.12146, 0.11341, 0.11327, 0.17625, 0.11973, 0.10435, 0.10638),
                  c(0.     , 0.25042, 0.09946, 0.09164, 0.06692, 0.08706, 0.09173, 0.08506),
                  c(0.     , 0.     , 0.19914, 0.05867, 0.06453, 0.07367, 0.06468, 0.01914),
                  c(0.     , 0.     , 0.     , 0.20876, 0.04933, 0.03651, 0.09381, 0.07742),
                  c(0.     , 0.     , 0.     , 0.     , 0.36096, 0.12574, 0.10157, 0.0571 ),
                  c(0.     , 0.     , 0.     , 0.     , 0.     , 0.21552, 0.05663, 0.06187),
                  c(0.     , 0.     , 0.     , 0.     , 0.     , 0.     , 0.22514, 0.03327),
                  c(0.     , 0.     , 0.     , 0.     , 0.     , 0.     , 0.     , 0.2202 ))

 # max traded weight per x_j
  u <- 1.0

  n <- ncol(GT)
  
  w_prev <- rep(0.0, n)
  
  prob <- list(sense="min")
  prob$c <- c(rep(0,3*n), 1)
  tc <- rep(0.005, n)

  # Specify linear constraints
  # [ e'  g'  0  ]   [ x ]  =   1
  # [ I  -I   0  ] * [ z ]  <=  w_prev
  # [ I   I   0  ]   [ y ]  >=  w_prev
  # [ 0   I  -U  ]          <=  0
  prob$A <- rbind(cbind(Matrix(1.0,ncol=n), t(tc),                    Matrix(0.0,ncol=n), 0),
                  cbind(Diagonal(n, 1.0),   -Diagonal(n, 1.0),        Matrix(0,n,n),      0),
                  cbind(Diagonal(n, 1.0),   Diagonal(n, 1.0),         Matrix(0,n,n),      0),
                  cbind(Matrix(0,n,n),      Diagonal(n, 1.0),         Diagonal(n,-u),     0))
  
  
  prob$bc <- rbind(blc=c(1.0, rep(-Inf,n), w_prev, rep(-Inf,n)),
                   buc=c(1.0, w_prev, rep(Inf,n), rep(0.0,n)))
  
  # No shortselling and the linear bound 0 <= y <= 1     
  prob$bx <- rbind(blx=c(rep(0.0,n), rep(-Inf,n), rep(0.0,n), 0.0),
                   bux=c(rep(Inf,n), rep(Inf, n), rep(1.0,n), Inf))
  
  # Specify the affine conic constraints for risk
  prob$F <- rbind(
    cbind(Matrix(0.0,nrow=1,ncol=3*n),     1), 
    cbind(GT, Matrix(0.0,nrow=n,ncol=2*n), 0)
  )
  prob$g <- c(0, rep(0,n))
  prob$cones <- matrix(list("QUAD", 1+n, NULL), nrow=3, ncol=1)
  rownames(prob$cones) <- c("type","dim","conepar")
  
  # Demand y to be integer (hence binary)
  prob$intsub <- (2*n+1):(3*n);
  
  # Solve the problem
  r <- mosek(prob,list(verbose=10))
  stopifnot(identical(r$response$code, 0))
  
  stopifnot(identical(r$sol$int$solsta, 'INTEGER_OPTIMAL'))    
  
  # Return the solution
  x <- r$sol$int$xx[1:n]
  z <- r$sol$int$xx[(n+1):(2*n)]
  y <- r$sol$int$xx[(2*n+1):(3*n)]
  t_value <- r$sol$int$xx[3*n+1]

问题是,无论 w_prev 的值如何,对于每个资产 j 和 z 来说,y 始终为 1,这应该使资产 j 的交易量始终为 1-tc。

我认为第 2 行和第 3 行中的线性约束一定有问题,但我只是没有看到它。

此外,这是否是解决问题的正确方法,或者交易成本是否应该在目标中?

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

您选择了无截距的交易成本(第一个预算约束中

y
的系数为0),因此
y=1
总是好的,也可以删除。在这种情况下,您也不需要任何整数优化。
y
的要点是,如果您进行交易,则激活一个固定常量,否则将其保持为 0,这就是组合数学的用武之地..

通过这种选择,最佳方案是尽可能多地推进

z
,并尽可能少地为
x
留下风险最小化。

这里你遇到了另一个问题,那就是你完全失去了回报。如果您从目标中删除了最大化回报,那么您可能应该有一个约束,例如

mu'*x >= min_return
。如果没有它,优化器总是会被激励将
x
推至零,因为根本不投资可以最大限度地降低风险。

© www.soinside.com 2019 - 2024. All rights reserved.