PacktPublishing / Python-for-Finance-Cookbook

Python for Finance Cookbook, published by Packt
728 stars 266 forks source link

Chapter 7.2 While plotting the "Efficient Frontier" facing IndexError: list index out of range #10

Closed rajesh1994 closed 3 years ago

rajesh1994 commented 3 years ago

`marks = ['o', "s", "x", "+"]

fig, ax = plt.subplots()

pf_results.plot(kind='scatter', x='volatility', y='returns', c='sharpe_ratio', cmap='RdYlGn', edgecolors='black', ax=ax) ax.set(xlabel='Volatility', ylabel='Expected Returns', title='Efficient Frontier') ax.plot(pf_vol_ef, pf_returns_ef, 'b--')

for asset_index in range(n_assets): ax.scatter(x=np.sqrt(cov_mat.iloc[asset_index, asset_index]), y=avg_returns[asset_index], marker=marks[asset_index], s=150, color='black', label=assets[asset_index]) ax.legend() plt.tight_layout() plt.show();`

Refer the attached image image

jiripik commented 3 years ago

I have just recalculated the notebook and all works here. Most likely you have removed some code from the original notebook.

For example, your screenshot is missing plt.savefig('images/ch7_im8.png')

Please redownload and recalculate- https://user-images.githubusercontent.com/22610174/110244799-79c17980-7f86-11eb-8055-7ba3cd690aac.png

gaurav-packt commented 3 years ago

Hello @jiripik,

Thanks for sharing your feedback.

With this I'm closing the issue.