我试图建立其相对于在R.组合优化
我试图最小化目标函数
$$分钟VAR(return_p-return'weight_ {BM优化以另一组合})$$
与约束
$$ 1_n'w = 1 $$
$$瓦特> 0.005 $$
$$ w <.8 $$
其中w是投资组合的收益。有10个证券,所以我将基准权重设置为0.1。 我知道
$$ Var(return_p-return'weight_ {bm})= var(r)+ var(r'w_ {bm}) - 2 * cov(r_p,r'w_ {bm}) = var(r'w)-2cov(r'w,r'w_ {bm})= w'var(r)w-2cov(r'w,r'w_ {bm})$$
$ $ = w'var(r)w-2cov(r',r'w_bm)w $$
最后一项是我需要的形式,所以我尝试用solve.QP解决这个问题,在R中约束虽然给我一个问题。
这里是我的代码
trackport <- array(rnorm(obs * assets, mean = .2, sd = .15), dim = c(obs,
assets)) #this is the portfolio which the assets are tracked against
wbm <- matrix(rep(1/assets, assets)) #random numbers for the weights
Aeq <- t(matrix(rep(1,assets), nrow=assets, ncol = 1)) #col of 1's to add
#the weights
Beq <- 1 # weights should sum to 1's
H = 2*cov(trackport) #times 2 because of the syntax
#multiplies the returns times coefficients to create a vector of returns for
#the benchmark
rbm = trackport %*% wbm
#covariance between the tracking portfolio and benchmark returns
eff <- cov(trackport, rbm)
#constraints
Amatrix <- t(matrix(c(Aeq, diag(assets), -diag(assets)), ncol = assets,
byrow = T))
Bvector <- matrix(c(1,rep(.005, assets), rep(.8, assets)))
#solve
solQP3 <- solve.QP(Dmat = H,
dvec = zeros, #reduces to min var portfolio for
#troubleshooting purposes
Amat = Amatrix,
bvec = Bvector,
meq = 1)
我得到的错误是“约束是不一致的,无解!”但我不能找到什么毛病我的矩阵
我(转)矩阵看起来像这样
[1,1,...,1]
[1,0,...,0]
[0,1,...,0]
...
[0,0,...,1]
[-1,0,...,0]
[0,-1,...,0]
...
[0,0,...,-1]
和我的$ B_0 $看起来像这样
[1]
[.005]
[.005]
...
[.005]
[.8]
[.8]
...
[.8]
所以我米不知道为什么它没有找到一个解决方案,任何人都可以看看?
我希望我的函数为0.005
@Joel Sinofsky,是的!你将有-x $ \ ge $ -.8。这相当于x $ \ le $ .8,这就是你想要的。当然,您已经输入了x $ \ ge $ .005。 –