Skip to content

Instantly share code, notes, and snippets.

@julian-west
Created September 7, 2019 17:08
Show Gist options
  • Save julian-west/2ea09ab1a148481d124cf3a60d3c823b to your computer and use it in GitHub Desktop.
Save julian-west/2ea09ab1a148481d124cf3a60d3c823b to your computer and use it in GitHub Desktop.
# ---------------------------------------
# Get statistics for tooltip
# ---------------------------------------
# make list of node labels.
node_label = list(mst.nodes())
# calculate annualised returns, annualised volatility and round to 2dp
annual_vol, annual_ret, annual_vol_2dp, annual_ret_2dp = calculate_stats()
# get top and bottom 3 correlations for each node
top_3_corrs, bottom_3_corrs = get_top_and_bottom_three()
# create tooltip string by concatenating statistics
description = [f"<b>{node}</b>" +
"<br>" + annual_ret_2dp[index] +
"<br>" + annual_vol_2dp[index] +
"<br><br>Strongest correlations with: " +
"<br>" + top_3_corrs[index] +
"<br>Weakest correlations with: "
"<br>" + bottom_3_corrs[index]
for index, node in enumerate(node_label)]
# ---------------------------------------
# Get poisitions of nodes and edges for Plotly graph
# ---------------------------------------
# get coordinates for nodes and edges
Xnodes, Ynodes, Xedges, Yedges = get_coordinates()
# ---------------------------------------
# Assign node colour and size depending on annualised returns
# ---------------------------------------
# assign node colour depending on positive or negative annualised returns
node_colour = [assign_colour(i) for i in annual_ret]
# assign node size based on annualised returns size (scaled by a factor)
node_size = [abs(x)**0.5*5 for x in annual_ret]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment