How to take the square root of quad_form output in

2019-07-08 11:11发布

问题:

I am trying to solve a problem that involves \sqrt{w^t \Sigma w} in the objective function. To compute w^t \Sigma w, I use the quad_form function. How do I take its square root?

When in the code I try to write

risk = sqrt(quad_form(w, E))

I am getting a DCP rule error but I am pretty sure it is convex given the other constraints I have. So the question is not really about maths but the actual implementation of the convex program.

The problem I am trying to solve is

ret = mu.T*w 
risk = sqrt(quad_form(w, E))
gamma.value = distr.pdf(distr.ppf(alpha)) / (1 - alpha)
minimizer = Minimize(-ret + risk * gamma) #cvxpy.sqrt(risk) * gamma) 
constraints = [w >= 0, 
               b.T * log(w) >= k] 
prob = Problem(minimizer, constraints)
prob.solve(solver='ECOS_BB',verbose=True)

回答1:

In order to take the square root of the quadratic form, matrix Sigma must be positive semidefinite. Compute a Cholesky decomposition Sigma = Q.T * Q and then include the term norm(Q*w,2) in your objective function.