2

我正在尝试使用 Python 的 cvxopt最小化投资组合差异。但是,经过多次尝试,它似乎不起作用。该函数和我的代码以及错误粘贴在下面。感谢您的帮助!

最小化问题

目标函数:min x.dot(sigma_mv).dot(xT)

约束条件都是x>=0, sum(X) = 1

sigma_mv是800*800的协方差矩阵,dim = 800

代码

dim = sigma_mv.shape[0]
P = 2*sigma_mv   
q = np.matrix([0.0])
G = -1*np.identity(dim)
h = np.matrix(np.zeros((dim,1)))

sol = solvers.qp(P,q,G,h)

Traceback (most recent call last):

  File "<ipython-input-47-a077fa141ad2>", line 6, in <module>
    sol = solvers.qp(P,q)   

  File "D:\spyder\lib\site-packages\cvxopt\coneprog.py", line 4470, in qp
    return coneqp(P, q, G, h, None, A,  b, initvals, kktsolver = kktsolver, options = options)

  File "D:\spyder\lib\site-packages\cvxopt\coneprog.py", line 1822, in coneqp
    raise ValueError("use of function valued P, G, A requires a "\

ValueError: use of function valued P, G, A requires a user-provided kktsolver
4

1 回答 1

0

您有相等和不等式约束,因此您需要向内置 qp 求解器 Gx <=h Ax=b 提供所有参数

这里 x>=0 可以写成 -x<=0 所以,G 矩阵看起来像 -1*(Identity matrix) 并且 h 将是一个 0 向量类似地,你的 A 将是一个 Identity 矩阵,b 将是一个统一向量(所有元素 =1)

最后,求解表达式应如下所示:

sol=solvers.qp(P, q, G, h, A, b)
于 2020-01-24T05:14:12.743 回答