Python Scipy.Optimize.Minimize函数为所有输入值返回几乎相同的值。请帮我识别错误

Python Scipy.Optimize.Minimize函数为所有输入值返回几乎相同的值。请帮我识别错误,python,scipy,quantitative-finance,scipy-optimize,scipy-optimize-minimize,Python,Scipy,Quantitative Finance,Scipy Optimize,Scipy Optimize Minimize,minvol()函数应该返回在相同返回量下产生最小标准偏差的权重。标准偏差由portvol()函数和portfolio returns by portfolio return()函数根据该权重数据计算得出。然而,对于我的收益范围内的所有权重值,我从优化函数(最小化)中得到的投资组合标准偏差值多少是相同的。我的代码肯定有问题。有人能帮我确定是什么吗 from scipy.optimize import minimize import matplotlib.pyplot as plt rho=[

minvol()函数应该返回在相同返回量下产生最小标准偏差的权重。标准偏差由portvol()函数和portfolio returns by portfolio return()函数根据该权重数据计算得出。然而,对于我的收益范围内的所有权重值,我从优化函数(最小化)中得到的投资组合标准偏差值多少是相同的。我的代码肯定有问题。有人能帮我确定是什么吗

from scipy.optimize import  minimize
import matplotlib.pyplot as plt

rho=[[1,0.4000,0.2500,0.2000,0.1500,0.2000],[0.4000,1,0.7000,0.6000,0.7000,0.2000],[0.2500,0.7000,1,0.7500,0.6000,0.1000],[0.2000,0.6000,0.7500,1,0.2500,0.1500],[0.1500,0.7000,0.6000,0.2500,1,0.3000],[0.2000,0.2000,0.1000,0.1500,0.3000,1]]
o=[[0]*6]*6
arr=[0.0680,0.2240,0.2210,0.3000,0.2310,0.0680]
for i in range(6):
    o[i][i]=arr[i]
cov=np.matmul(np.matmul(o,rho),o)
er=[0.400,0.1060,0.0830,0.1190,0.1280,0.0620]
def portfolio_return(w):
    return np.dot(w,er)
def portvol(w):
    return np.matmul(np.matmul(np.transpose(w),cov),w)

def minvol(target):
 initw=np.repeat(1/6,6)
 bounds=((0.0,1.0),)*6
 is_target = {'type': 'eq','fun':lambda w:(target - portfolio_return(w))}
 sumweight = {'type':'eq','fun':lambda w:(np.sum(w)-1)}
 cons=[is_target,sumweight]
 result=minimize(portvol, initw, method="SLSQP", options={'disp':False}, constraints=cons , bounds=bounds)
 return result.x

def wtdefine():
    target=np.linspace(0.0620,0.1280,100)
    weights=[minvol(tar) for tar in target]
    return weights
def plotter():
    weights=wtdefine()
    rets=[portfolio_return(w) for w in weights]
    vols=[portvol(w) for w in weights]
    print(rets,vols)
    plt.plot(vols,rets)
    plt.show()
plotter()