/******************************************************************
— Title : [Python; NetworkX] Supply Chain analysis
— Key word : networkx, Node, Edge, Centrality, Supply Chain, Value Chain
*******************************************************************/
Data
- About 200 major firms listed on Compustat data
- Data Set will soon encompass all the firms with CIK code
- Customer information extracted from 10-k disclosure data
Graph
- Drawn from the basic networkx graph tool (nx.draw())
- year : ordered in years ; 2000, 2005, 2010, 2015
- Size of node : in_degree_centrality
- Color of node : out_degree_centrality
Sample Code :
(Reference : https://briandew.wordpress.com/2016/06/15/trade-network-analysis-why-centrality-matters/)
import networkx as nx import pandas as pd import numpy as np import matplotlib import matplotlib.pyplot as plt def draw_G(G, year): oc = nx.out_degree_centrality(G) for key in oc.keys(): oc[key] = oc[key]*10 nx.set_node_attributes(G, name= 'cent', values = oc) ic = nx.in_degree_centrality(G) nx.set_node_attributes(G, name= 'in', values = ic) node_size = [float(G.node[v]['in'])*20000 + 1 for v in G] node_color = [float(G.node[v]['cent']) for v in G] pos = nx.spring_layout(G, k=30, iterations=8) nodes = nx.draw_networkx_nodes(G, pos, node_size=node_size, node_color = node_color, alpha=0.5) #nodes = nx.draw_networkx_nodes(G, pos, node_color=node_color, alpha=0.5) edges = nx.draw_networkx_edges(G, pos, edge_color='black', arrows=True, width=0.3) nx.draw_networkx_labels(G, pos, font_size=5) plt.text(0,-1.2, 'Node color is out_degree_centrality', fontsize=7) plt.title('Compustat firms Supply Chain (year : ' + str(year) + ')', fontsize=12) cbar = plt.colorbar(mappable=nodes, cax=None, ax=None, fraction=0.015, pad=0.04) cbar.set_clim(0, 1) plt.margins(0,0) plt.axis('off') plt.savefig(str(year)+ 'Supply Chain.png', dpi=1000) plt.show()
Numbers(Statistics)
- Longest path :