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 renom_tda.topology import Topology
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 text data & number data

We extract text data like Company Name and number data.

In [3]:
text_data = np.array(pdata.loc[:, pdata.dtypes == "object"])
text_data_columns = pdata.columns[:4]

number_data = np.array(pdata.loc[:, np.logical_or(pdata.dtypes == "float", pdata.dtypes == "int")])
number_data_columns = pdata.columns[4:]

Create topology instance

In [4]:
topology = Topology()

Load data

In [5]:
topology.load_data(number_data, number_data_columns=number_data_columns, text_data=text_data, text_data_columns=text_data_columns, standardize=True)

Create point cloud

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

Mapping to topological space

In [7]:
topology.map(resolution=50, overlap=0.5, eps=0.2, min_samples=2)
created 963 nodes.
created 3146 edges.

Colorize & show

Next, we colorize 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.number_data.shape[1]):
    print("colored by %s (%s)." % (number_data_columns[i], e_col[i]))

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

Search from values

In [9]:
search_dicts = [{
    "data_type": "number",
    "operator": ">",
    "column": "売上高(百万円)",
    "value": 20000
}, {
    "data_type": "number",
    "operator": ">",
    "column": "ROE",
    "value": 20
}]

target = topology.number_data[:, 0]
topology.color(target, color_method="mean", color_type="rgb")
node_index = topology.search_from_values(search_dicts=search_dicts, target=None, search_type="column")
topology.show(fig_size=(10,10), node_size=10, edge_width=0.5)
notebooks/tda-case-study/company-finance-data-mapping/../../../../../../../home/grid00/repositories/ReNom/doc/_build/html/.doctrees/nbsphinx/notebooks_tda-case-study_company-finance-data-mapping_notebook_18_0.png
In [10]:
node_index
Out[10]:
[302,
 303,
 304,
 305,
 348,
 349,
 350,
 351,
 394,
 395,
 396,
 397,
 398,
 399,
 400,
 440,
 441,
 443,
 444,
 445,
 446,
 486,
 487,
 488,
 489,
 490,
 491,
 492,
 493,
 494,
 495,
 496,
 497,
 498,
 531,
 532,
 533,
 534,
 535,
 536,
 537,
 538,
 539,
 540,
 541,
 542,
 543,
 579,
 580,
 581,
 582,
 584,
 585,
 586,
 587,
 588,
 591,
 592,
 623,
 624,
 625,
 626,
 627,
 628,
 629,
 630,
 631,
 632,
 635,
 636,
 666,
 667,
 668,
 669,
 670,
 671,
 672,
 673,
 674,
 711,
 712,
 713,
 714,
 765,
 766,
 773,
 774,
 775,
 803,
 804,
 805,
 811,
 812,
 813,
 839,
 840,
 841,
 854,
 855,
 860,
 871,
 872,
 873,
 874,
 886,
 887,
 896,
 897,
 898,
 899,
 900,
 915,
 916,
 917,
 918,
 932,
 933,
 952,
 953,
 956,
 957]

output csv file

Topology instance can create csv file from node indexes.
If text_data_columns and number_data_columns is not None, you can show output csv header with skip_header=False.
In [11]:
topology.output_csv_from_node_ids("output.csv", node_ids=node_index, skip_header=False)