mlfinlab.networks.visualisations
These methods allows the user to easily deploy graph visualisations given an input file dataframe.
Module Contents
Functions
|
This method returns a Dash server ready to be run. |
|
This method returns the distance matrix ready to be inputted into the Graph class. |
|
This method returns a Dash server ready to be run. |
|
This method returns a Dash server ready to be run. |
|
This method returns a PMFGDash server ready to be run. |
|
Given a NetworkX graph, this method generates and returns a ranking of centrality. |
- generate_mst_server(log_returns_df, mst_algorithm='kruskal', distance_matrix_type='angular', jupyter=False, colours=None, sizes=None)
-
This method returns a Dash server ready to be run.
- Parameters:
-
-
log_returns_df – (pd.DataFrame) An input dataframe of log returns with stock names as columns.
-
mst_algorithm – (str) A valid MST type such as ‘kruskal’, ‘prim’, or ‘boruvka’.
-
distance_matrix_type – (str) A valid sub type of a distance matrix, namely ‘angular’, ‘abs_angular’, ‘squared_angular’.
-
jupyter – (bool) True if the user would like to run inside jupyter notebook. False otherwise.
-
colours – (Dict) A dictionary of key string for category name and value of a list of indexes corresponding to the node indexes inputted in the initial dataframe.
-
sizes – (List) A list of numbers, where the positions correspond to the node indexes inputted in the initial dataframe.
-
- Returns:
-
(Dash) Returns the Dash app object, which can be run using run_server. Returns a Jupyter Dash object if the parameter jupyter is set to True.
- create_input_matrix(log_returns_df, distance_matrix_type)
-
This method returns the distance matrix ready to be inputted into the Graph class.
- Parameters:
-
-
log_returns_df – (pd.DataFrame) An input dataframe of log returns with stock names as columns.
-
distance_matrix_type – (str) A valid sub type of a distance matrix, namely ‘angular’, ‘abs_angular’, ‘squared_angular’.
-
- Returns:
-
(pd.DataFrame) A dataframe of a distance matrix.
- generate_almst_server(log_returns_df, distance_matrix_type='angular', jupyter=False, colours=None, sizes=None)
-
This method returns a Dash server ready to be run.
- Parameters:
-
-
log_returns_df – (pd.DataFrame) An input dataframe of log returns with stock names as columns.
-
distance_matrix_type – (str) A valid sub type of a distance matrix, namely ‘angular’, ‘abs_angular’, ‘squared_angular’.
-
jupyter – (bool) True if the user would like to run inside jupyter notebook. False otherwise.
-
colours – (dict) A dictionary of key string for category name and value of a list of indexes corresponding to the node indexes inputted in the initial dataframe.
-
sizes – (list) A list of numbers, where the positions correspond to the node indexes inputted in the initial dataframe.
-
- Returns:
-
(Dash) Returns the Dash app object, which can be run using run_server. Returns a Jupyter Dash object if the parameter jupyter is set to True.
- generate_mst_almst_comparison(log_returns_df, distance_matrix_type='angular', jupyter=False)
-
This method returns a Dash server ready to be run.
- Parameters:
-
-
log_returns_df – (pd.DataFrame) An input dataframe of log returns with stock names as columns.
-
distance_matrix_type – (str) A valid sub type of a distance matrix, namely ‘angular’, ‘abs_angular’, ‘squared_angular’.
-
jupyter – (bool) True if the user would like to run inside jupyter notebook. False otherwise.
-
- Returns:
-
(Dash) Returns the Dash app object, which can be run using run_server. Returns a Jupyter Dash object if the parameter jupyter is set to True.
- generate_pmfg_server(log_returns_df, input_type='distance', jupyter=False, colours=None, sizes=None)
-
This method returns a PMFGDash server ready to be run.
- Parameters:
-
-
log_returns_df – (pd.DataFrame) An input dataframe of log returns with stock names as columns.
-
input_type – (str) A valid input type correlation or distance. Inputting correlation will add the edges by largest to smallest, instead of smallest to largest.
-
jupyter – (bool) True if the user would like to run inside jupyter notebook. False otherwise.
-
colours – (Dict) A dictionary of key string for category name and value of a list of indexes corresponding to the node indexes inputted in the initial dataframe.
-
sizes – (List) A list of numbers, where the positions correspond to the node indexes inputted in the initial dataframe.
-
- Returns:
-
(Dash) Returns the Dash app object, which can be run using run_server. Returns a Jupyter Dash object if the parameter jupyter is set to True.
- generate_central_peripheral_ranking(nx_graph)
-
Given a NetworkX graph, this method generates and returns a ranking of centrality. The input should be a distance based PMFG.
The ranking combines multiple centrality measures to calculate an overall ranking of how central or peripheral the nodes are. The smaller the ranking, the more peripheral the node is. The larger the ranking, the more central the node is.
The factors contributing to the ranking include Degree, Eccentricity, Closeness Centrality, Second Order Centrality, Eigen Vector Centrality and Betweenness Centrality. The formula for these measures can be found on the NetworkX documentation (https://networkx.github.io/documentation/stable/reference/algorithms/centrality.html)
- Parameters:
-
nx_graph – (nx.Graph) NetworkX graph object. You can call get_graph() on the MST, ALMST and PMFG to retrieve the nx.Graph.
- Returns:
-
(List) Returns a list of tuples of ranking value to node.