我试图将 100 种证券的投资组合的差异最小化。
def portvol(w, x):
return np.dot(w.T, np.dot(x, w))*252
covmat = annreturn.cov()
w0 = np.ones(len(covmat)) * (1 / len(covmat)) #equal weighting initially
bounds = ((0,1),) * len(covmat)
constraints = {'fun': lambda i: np.sum(i)-1.0, 'type': 'eq'}
optweights = minimize(portvol, w0, args = (covmat), method = 'SLSQP', bounds = bounds, constraints =
constraints)
annereturn.cov() 是一个 100x100 的数据帧。输出与我开始时相同的 0.01 偶数权重和此失败消息:
message: 'Inequality constraints incompatible'
nfev: 102
nit: 1
njev: 1
状态:4 成功:假