I'm trying to represent the efficient frontier from an old financial model (MPT). Everything is fine until it comes to representation. In particular, from Matplot I got a neverending error, and from Plotly (I've tried both) a blank figure.
The first code is the following:
returns = np.linspace(0, 0.7, 50) volatility_opt = []
def GR(w):
w = np.array(w)
R = np.sum(meanlogReturns*w)
return R
for R in returns:
opt = minimize(minimizeMyvolatility, w0, method = 'SLSQP', bounds = bounds, constraints = constraints)
constraints = ({'type': 'eq', 'fun': b},
{'type': 'eq', 'fun': lambda w: GR(w) - R})
def minimizeMyvolatility(w):
w =np.array(w)
V = np.sqrt(np.dot(w.T, np.dot(Sigma, w)))
return V
volatility_opt.append(opt['fun'])
The scatter is working only without the plt.scatter() for volatility and returns:
plt.figure(figsize=(20,6))
plt.scatter(expectedVolatility,expectedReturn,c=sharpeRatio)
plt.xlabel('expected volatility')
plt.ylabel('expected log returns')
plt.colorbar(label='sharpe ratio')
plt.scatter(expectedVolatility[maxIndex],expectedReturn[maxIndex],c='red')
plt.scatter(volatility_opt,returns)
plt.show()
ValueError: x and y must be the same size
source https://stackoverflow.com/questions/74071820/scattering-for-volatility-opt-and-returns-not-displaying-for-matplot-x-and-y
Comments
Post a Comment