Mapping Company Finance Data

Visualization company finance data using ReNom TDA.

In this tutorial, we visualize company finance data.

Requirement

In [1]:
import numpy as np

import pandas as pd

from sklearn.cluster import DBSCAN

from renom.tda.topology import SearchableTopology
from renom.tda.lens import TSNE

Import finance data

We get company finance data from https://hesonogoma.com/stocks/japan-all-stock-financial-results.html .

In [2]:
pdata = pd.read_csv("finance.csv")

Extract categorical data & numerical data

We extract categorical data like Company Name and numerical data.

In [3]:
categorical_data = np.array(pdata.loc[:, pdata.dtypes == "object"])

numerical_data = np.array(pdata.loc[:, np.logical_or(pdata.dtypes == "float", pdata.dtypes == "int")])
numerical_data = (numerical_data - np.average(numerical_data, axis=0)) / np.std(numerical_data, axis=0)

Create topology instance

In [4]:
topology = SearchableTopology()

Regist categorical data to topology instance

In [5]:
topology.regist_categorical_data(categorical_data)

Create point cloud

In [6]:
metric = None
lens = [TSNE(components=[0,1])]
topology.fit_transform(numerical_data, metric=metric, lens=lens)
projected by TSNE.
finish fit_transform.

Mapping to topological space

In [7]:
clusterer = DBSCAN(eps=5, min_samples=2)
topology.map(resolution=50, overlap=0.5, clusterer=clusterer)
mapping start, please wait...
created 982 nodes.
calculating cluster coordination.
calculating edge.
created 3191 edges.

Color topology & show

Next, we create color for topology and show.

In [8]:
e_col = ["sales(million yen)", "operationg profit(million yen)", "ordinaly profit(million yen)",
         "current profit(million yen)", "total assets(million yen)", "owned capital(million yen)",
         "capital(million yen)", "interest-bearing debt(million yen)", "aggregate market value",
         "ratio of worth", "return on equity", "return on assets", "number of stocks issued"]
for i in range(topology.data.shape[1]):
    print("colored by %s (%s)." % (pdata.columns[i+4], e_col[i]))

    topology.color(topology.data[:, i], dtype="numerical", ctype="rgb")
    topology.show(fig_size=(10, 10), node_size=5, edge_width=1, mode=None, strength=None)
colored by 売上高(百万円) (sales(million yen)).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_1.png
colored by 営業利益(百万円) (operationg profit(million yen)).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_3.png
colored by 経常利益(百万円) (ordinaly profit(million yen)).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_5.png
colored by 当期利益(百万円) (current profit(million yen)).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_7.png
colored by 総資産(百万円) (total assets(million yen)).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_9.png
colored by 自己資本(百万円) (owned capital(million yen)).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_11.png
colored by 資本金(百万円) (capital(million yen)).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_13.png
colored by 有利子負債(百万円) (interest-bearing debt(million yen)).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_15.png
colored by 時価総額(百万円) (aggregate market value).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_17.png
colored by 自己資本比率 (ratio of worth).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_19.png
colored by ROE (return on equity).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_21.png
colored by ROA (return on assets).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_23.png
colored by 発行済株式数 (number of stocks issued).
../../../_images/notebooks_tda-case-study_company-finance-data-mapping_notebook_16_25.png