import numpy as np
import pandas as pd
import cvxpy as cp
import cvxopt
from cvxopt import matrix
G_ = np.load('/shared/FactorBank/temp/G.npy')
h_ = np.load('/shared/FactorBank/temp/h.npy')
q_ = np.load('/shared/FactorBank/temp/q.npy')
N = len(q_)
这是cvxpy的一部分。
h = h_.reshape(len(h_))
A = np.ones((1, N))
b = np.ones(1)
x = cp.Variable(int(N))
obj = cp.sum(q_ * x)
#print(G_)
constraints = [G_ * x <= h, A * x == b]
prob = cp.Problem(cp.Minimize(obj), constraints)
prob.solve()
print "status:", prob.status
print "optimal value", prob.value
print "optimal var", x.value
状态:最佳
最佳值-3.598688474475655
最优变量[1.45281688e-05 1.21958458e-05 -2.80709993e-04 ... -1.77801870e-04 -2.01577984e-04 -1.12303384e-04]
这是cvxopt的一部分。
G = matrix(G_)
h = matrix(h_)
A = matrix(1.0, (1, N))
b = matrix(1.0)
q = matrix(q_.T)
portfolios = cvxopt.solvers.lp(q, G, h, A, b)
pcost dcost差距等于k / t
0:2.8090e-02 -3.1698e + 02 2e + 04 2e-01 5e-09 1e + 00
1:-6.1531e + 01 -9.3943e + 01 2e + 03 2e-02 6e-10 2e-02
2:-2.7578e + 01 -3.3144e + 01 1e + 02 3e-03 1e-10 2e-02
3:-1.8330e + 01 -2.1642e + 01 7e + 01 2e-03 6e-11 1e-02
……
22:-2.4301e + 00 -2.4301e + 00 5e-06 1e-10 3e-11 7e-10
23:-2.4301e + 00 -2.4301e + 00 8e-08 2e-12 1e-09 1e-11 找到了最佳解决方案。
所以有人知道尽管状态均为“最佳”,但结果为何不相同?