Created
July 18, 2021 10:48
-
-
Save rian-dolphin/94a31eb6fa00c959b96382ddd8e0bd2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-- Plot the risk vs. return of randomly generated portfolios | |
#- Convert the list from before into an array for easy plotting | |
mean_variance_pairs = np.array(mean_variance_pairs) | |
risk_free_rate=0 #-- Include risk free rate here for sharpe ratio | |
#-- Create Plot | |
fig = go.Figure() | |
fig.add_trace(go.Scatter(x=mean_variance_pairs[:,1]**0.5, | |
y=mean_variance_pairs[:,0], | |
#- Add color scale for sharpe ratio | |
marker=dict(color=(mean_variance_pairs[:,0]-risk_free_rate)/(mean_variance_pairs[:,1]**0.5), | |
showscale=True, | |
size=7, | |
line=dict(width=1), | |
colorscale="RdBu", | |
colorbar=dict(title="Sharpe<br>Ratio") | |
), | |
mode='markers')) | |
#- Add title/labels | |
fig.update_layout(template='plotly_white', | |
xaxis=dict(title='Annualised Risk (Volatility)'), | |
yaxis=dict(title='Annualised Return'), | |
title='Sample of Random Portfolios', | |
coloraxis_colorbar=dict(title="Sharpe Ratio")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment