cvxpy 有没有办法有条件约束,我正在研究一个像这样的简单凸投资组合优化问题。
from cvxpy import *
import numpy as np
np.random.seed(1)
n = 10
Sigma = np.random.randn(n, n)
Sigma = Sigma.T.dot(Sigma)
w = Variable(n)
mu = np.abs(np.random.randn(n, 1))
ret = mu.T*w
risk = quad_form(w, Sigma)
orig_w = [0.15,0.2,0.2,0.2,0.2,0.05,0.0,0.0,0.0,0.0]
lambda_ret = Parameter(sign='positive')
lambda_ret = 5
lambda_risk = Parameter(sign='positive')
lambda_risk = 1
constraints = [sum_entries(w) == 1, w >= 0]
prob = Problem(Maximize(lambda_ret * ret - lambda_risk * risk ),constraints)
prob.solve()
我正在尝试引入一个仅适用于某些场景的约束
sum_entries([ w[i]-orig_w[i] if w[i]-orig_w[i] >= 0 else 0 for i in range(n)]) >= some threshold
在这个 python 伪代码中,我只想控制正的权重变化。
我查看了 cvxpy 函数,但似乎没有什么能做到这一点。