0
$\begingroup$

I am looking to implement the following optimization problem in CVXPY.

$$ \max _{x_t} x_t' \mu - \frac{\gamma}{2} x'_t \Sigma x_t - x'_t\Lambda \Delta x_t $$

where $\Delta x_t := x_t - x_{t-1}$ and $\Sigma$ and $\Lambda$ are positive definite symmetric matrices.

Here is my attempt:

import cvxpy as cp
import numpy as np

N = 2
gamma = 0.01
xprev = [0.5, 0.5]
mu = [0.01, 0.01]
Sigma = np.diag([0.1 ** 2] * 2)
Lambda = Sigma * 0.01
x = cp.Variable(N)
obj_terms = []
constraints = []
xdiff = x - xprev

term1 = cp.sum(cp.multiply(mu, x))
term2 = gamma * 0.5 * cp.quad_form(x, Sigma)
term3 = x.T @ Lambda @ xdiff

term = (term1 - term2 - term3)
obj_terms.append(term)
objective = cp.Maximize(cp.sum(obj_terms))  
problem = cp.Problem(objective)
problem.solve()
x_value = x.value  
print(x_value)

However, this implementation always results in a DCP error. I believe this problem is a convex one. The problem child is the implementation x.T @ Lambda @ xtdiff. Can someone please help me figure out how to implement the term $x'_t\Lambda \Delta x_t$ in CVXPY?

$\endgroup$
9
  • 2
    $\begingroup$ How did you establish this is convex? I don't think it is. (Last term is spoiling things). $\endgroup$ Jun 26, 2023 at 11:14
  • $\begingroup$ Please include the DCP error message $\endgroup$ Jun 26, 2023 at 11:16
  • $\begingroup$ Where does this QP come from? $\endgroup$ Jun 26, 2023 at 11:17
  • $\begingroup$ @ErwinKalvelagen It is convex given that $\Gamma$ and $\Lambda$ are symmetric matrices (see updated problem statement). One can establish by taking the derivative twice. $\endgroup$
    – Lydia
    Jun 26, 2023 at 13:51
  • $\begingroup$ @RodrigodeAzevedo Here is the error. cvxpy.error.DCPError: Problem does not follow DCP rules. Specifically: The objective is not DCP. $\endgroup$
    – Lydia
    Jun 26, 2023 at 13:53

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.