Guest User

Untitled

a guest
Oct 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. # find min Volatility & max sharpe values in the dataframe (df)
  2. min_volatility = df['Volatility'].min()
  3. max_sharpe = df['Sharpe Ratio'].max()
  4.  
  5. # use the min, max values to locate and create the two special portfolios
  6. sharpe_portfolio = df.loc[df['Sharpe Ratio'] == max_sharpe]
  7. min_variance_port = df.loc[df['Volatility'] == min_volatility]
  8.  
  9. # plot frontier, max sharpe & min Volatility values with a scatterplot
  10. plt.style.use('seaborn-dark')
  11. df.plot.scatter(x='Volatility', y='Returns', c='Sharpe Ratio',
  12. cmap='RdYlGn', edgecolors='black', figsize=(10, 8), grid=True)
  13. plt.scatter(x=sharpe_portfolio['Volatility'], y=sharpe_portfolio['Returns'], c='red', marker='D', s=200)
  14. plt.scatter(x=min_variance_port['Volatility'], y=min_variance_port['Returns'], c='blue', marker='D', s=200 )
  15. plt.xlabel('Volatility (Std. Deviation)')
  16. plt.ylabel('Expected Returns')
  17. plt.title('Efficient Frontier')
  18. plt.show()
Add Comment
Please, Sign In to add comment