我試圖建立其相對於在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。 –