简体   繁体   English

投资组合优化

[英]Portfolio optimization

I am trying to build a portfolio which is optimized with respect to another in R. 我正在尝试建立一个相对于R中的另一个进行优化的投资组合。

I am trying to minimize the objective function 我正在尝试最小化目标功能

$$min Var(return_p-return'weight_{bm})$$ $$ min Var(return_p-return'weight_ {bm})$$

with the constraints 有约束

$$ 1_n'w = 1$$ $$ 1_n'w = 1 $$

$$w > .005$$ $$ w> .005 $$

$$w < .8$$ $$ w <.8 $$

with w being the returns from a portfolio. w是投资组合的回报。 there are 10 securities, so I set the benchmark weights at .1 each. 有10种证券,因此我将基准权重设置为.1。 I know that 我知道

$$ 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})$$ $$ 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$$ $$ = w'var(r)的W-2cov(R”,r'w_bm)瓦特$$

the last term is of the form I need so I tried to solve this with solve.QP in R, the constraints are giving me a problem though. 最后一项是我需要的形式,所以我尝试用R.QP中的Solve.QP解决,但是约束给我一个问题。

here is my code 这是我的代码

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)

the error I am getting is "constraints are inconsistent, no solution!" 我收到的错误是“约束不一致,没有解决办法!” but I can't find what's wrong with my A matrix 但我找不到我的A矩阵出了什么问题

My (transposed) A matrix looks like this 我的(转置)矩阵看起来像这样

[1,1,...,1]
[1,0,...,0]
[0,1,...,0]
...
[0,0,...,1]
[-1,0,...,0]
[0,-1,...,0]
...
[0,0,...,-1]

and my $b_0$ looks like this 我的$ b_0 $看起来像这样

[1]
[.005]
[.005]
...
[.005]
[.8]
[.8]
...
[.8]

so I'm not sure why it isn't finding a solution, could anyone take a look? 所以我不确定为什么找不到解决方案,有人可以看看吗?

I'm not familiar with the package, but just took a quick look at https://cran.r-project.org/web/packages/quadprog/quadprog.pdf , which apparently is what you are using. 我不熟悉该软件包,但只是快速浏览了https://cran.r-project.org/web/packages/quadprog/quadprog.pdf ,这显然是您所使用的。

Your RHS values of .8 should be -0.8 because this function uses ≥ inequalities. 您的RHS值.8应该为-0.8,因为此函数使用了不等式。 So you have been constraining the variables to be ≥ .005 and ≤ -0.8, which of course is not what you want, and is infeasible. 因此,您一直将变量限制为≥.005和≤-0.8,这当然不是您想要的,并且是不可行的。

So leave transposed A as is and make 因此,按原样放置转置的A并

 b0:
    [1]
    [.005]
    [.005]
    ...
    [.005]
    [-.8]
    [-.8]
    ...
    [-.8]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM