Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # find min Volatility & max sharpe values in the dataframe (df)
- min_volatility = df['Volatility'].min()
- max_sharpe = df['Sharpe Ratio'].max()
- # use the min, max values to locate and create the two special portfolios
- sharpe_portfolio = df.loc[df['Sharpe Ratio'] == max_sharpe]
- min_variance_port = df.loc[df['Volatility'] == min_volatility]
- # plot frontier, max sharpe & min Volatility values with a scatterplot
- plt.style.use('seaborn-dark')
- df.plot.scatter(x='Volatility', y='Returns', c='Sharpe Ratio',
- cmap='RdYlGn', edgecolors='black', figsize=(10, 8), grid=True)
- plt.scatter(x=sharpe_portfolio['Volatility'], y=sharpe_portfolio['Returns'], c='red', marker='D', s=200)
- plt.scatter(x=min_variance_port['Volatility'], y=min_variance_port['Returns'], c='blue', marker='D', s=200 )
- plt.xlabel('Volatility (Std. Deviation)')
- plt.ylabel('Expected Returns')
- plt.title('Efficient Frontier')
- plt.show()
Add Comment
Please, Sign In to add comment