xs = 0.0000
xb = 1.5000
w1 = 0.0000
w2 = 2.5000
\[\sum_{i=1}^n w_i^+ + \sum_{i=1}^n w_i^- \le 2\]
\[w= I_n w^+ - I_n w^- =\begin{pmatrix} I_n & - I_n \end{pmatrix} \begin{pmatrix} w^+ \\ w^- \end{pmatrix} = D\hat{w}\]
\[(1/2) \times \text{raver} \times w^\top C w - r_s x_s + r_b x_b - \bar r^\top w\]
import cvxpy as cp
xs = cp.Variable(nonneg=True)
xb = cp.Variable(nonneg=True)
w = cp.Variable(2, nonneg=True)
ret = rs*xs - rb*xb + np.array([mn1, mn2]) @ w
risk = cp.quad_form(w, C)
prob = cp.Problem(
cp.Maximize(ret - 0.5 * raver * risk),
[xs - xb + cp.sum(w) == 1]
)
prob.solve()
print(xs.value, xb.value, w.value)xs = 0.0000
xb = 1.5000
w1 = 0.0000
w2 = 2.5000