Mastering Financial Analysis of Value Investing with Python for Better Investment Decisions in Taiwan Exchange Market — (1)

Introduction & Practical Exercise of Long Term DuPont Analysis

AgriEnvCoder
7 min readFeb 28, 2023

Investing Stock is a necessary task, after you realise that the money you deposit in bank is getting smaller and smaller due to inflation. Nonetheless, did I invest the right stock? How can I make ourselves feel at ease? I believe financial analyses can definitely help with that. Therefore, here we propose a framework of value investing and also build a practical work flow step-by-step. Stay tuned! Let’s dive in!

These analyses aim for effective long-term investment rather than swing trading.

  1. Choose worth investing companies at present
  2. Allocate personal asset into stock market.

Before analyses

Beyond all analyses, a crucial tip for investment is having basic knowledge of your target market. Make sure you do some research by yourself! More familiar you are with the market, industry or even company, more risks you are able to avoid.

It normally takes time and requires some “tuition fee” (loss owing to ridiculous decision in investment as a beginner). However, a good aviodance of paying tuition fee, is target on the largest companies listed on stock exchanges, for instance, S&P500.

In Taiwan stock market, we can start with 50 largest companies. Exchange traded fund 0050 (ETF 0050) is a good target to invest. Let’s put ETF 0050’s return into a line plot (Fig. 1). You can see although there is some fluctuation, the cumulative return over 7 years (from 01–28–2016 to 01–28–2022) is approximately 200%.

Fig. 1: Cumulative return of ETF 0050 in recent 7 years

Since the popular exchange trade fund has been reliable target for a long term, we can assume that the stocks they are choosing can be great targets too. Especially those stocks that have been always included. Note: ETF 0050 evaluates its components every season.

Even though components of ETF 0050 are considered as our targets, there are still too many stocks. Therefore, we create a selection method, via technical analyses, quantitative models, and a logical conceptual framework, integrated by a bit of coding, to realize an “almost” objective stock selection strategy.

The tutorial is going through several technical analyses, which (1) overlook the fundamental of companies, (2) long-term trend of individuals in stock market, and (3) guide investors to better allocate the assets theoretically. Let’s get started it!

Select worth investing companies

How could we know which companies have great potential or stability at present. On top of reading news, absorbing financial knowledge or even studying capitalist economies (e.g. boom cycle, inflation, recession, etc.), some figures and analyses are reliable and provide objective information.

ROE: Return of equity

A critical indicator for investor in stock market is return of equity (ROE). It is calculated by company’s net income divided by its shareholders’ equity, reflecting the profitability and efficiency in generating profit of a company. In other word, the higher the ROE, the better a company is at converting its equity financing into profits. It means that your investment is utilized well/not well by the company.

However, merely a number to determine performance of a company sounds a bit unfair. Moreover, since this indicator has a significant impact on confidence of investors. Companies naturally would tend to obtain nice ROE figure. There is some possible scenarios.

1.False financial report

Regardless size of the companies, fraudulent financial reporting is not quite common but absolutely exists.

2.Lump sum income

Due to the change of operation, or a good economic boom, the figure of net income can dramatically alert. ROE can be attributed of a lump sum income, but apparently it would not be long term.

3.Liabilities risk

According to the formula, lower shareholder’s equity also creates higher ROE. A company can also through raising debt reduce shareholder’s equity, since shareholder’s equity is real asset subtracting liabilities.

Image by Gerd Altmann from Pixabay

To conclude, high ROE is still not 100% representing great operation. We should look at several aspects in order to make our investment decision wisely.

DuPont Analysis

DuPont analysis is a framework that decomposes ROE into three components: Net profit margin, total asset turnover, and leverage.

(There is also a 5-step DuPont analysis which 5 components are involved, but we leave it here)

This analysis originated from DuPont, innovated by Donaldson Brown in 1914. Nowadays, this framework is widely used to determine the operational efficiency of two similar firms. Nevertheless, if we take one step back, DuPont analysis still provide us with a big picture of the performance of different companies.

1.Net Profit Margin

Net Profit Margin is a gauge of profitability. It also correlates with great quality product, high efficiency operation, and strong business ability.

2.Total Asset Turnover

Total asset turnover indicates the capability to transform products into income, reflecting the efficiency of using asset.

3.Leverage

The development of company somewhat replies on labilities. Leverage reflects the debt ratio. Higher leverage shows the company is willing to bear higher risk, and have confidence to generate revenue in the near future. On the other hand, this decision might lead to irreversible disaster if this company has no risk-avoidance strategy adopted.

Long-term analysis

Another method to avoid unhealthy companies by only looking into ROE, is long term analysis. “It takes time to (really) know a person.” If a company want to fake a figure, it is rare to do it throughout its lifespan, especially those companies who are the most largest companies in Taiwan. Therefore, if we look into the historical ROE, we can probably obtain the real picture.

Apart from acquiring ROE data for a long term, three components from DuPont analysis are also valuable to include.

Several websites provide DuPont analysis and Long-term analysis on the individual stock profile, like histock. However, as we stated ahead, DuPont is mainly used to compare different stocks. Now we would like to compare 50 largest companies in Taiwan stock’s market. It is difficult to go back and forth on the website and remember all information.

Hence, we developed a function in Python, in order to acquire target companies, length of time that we are interested in, and real-time analysis.

Quick function to trace ROE over time and decompose by DuPont analysis

Open-source dataset collection : FinMind

When we are wondering where can I get data which is near real-time, automatically updated, and free-to-use, there is a open-source dataset collection called FinMind, which focuses on collecting a wide range of Taiwan exchange market data in a daily basis.

It is also no registration needed. Although there is a limit of api request limit, in our case, 300/hour is enough. In our tutorial, we mainly explore this open-source dataset collection to fit it all formulas.

Data and Formulas

In order to calculate Net Profit Margin, Total Asset Turnover, and Leverage. We looked into the formulas and collate the data that we can find in FinMind.

{Data Name} << {Dataset Name}

Here is the formulas and data we are following:

  • Net Profit Margin

淨利率(Net Profit Margin) = 稅後盈餘(Income After Taxes)/營業收入(Revenue)

1.Income After Taxes << api.taiwan_stock_financial_statement

2.Revenue << api.taiwan_stock_financial_statement

  • Total Asset Turnover

總資產週轉率(Total Asset Turnover) = 營業收入(Revenue)/總資產(Total Assets)

1.Revenue << api.taiwan_stock_month_revenue

2.Total Asset << api.taiwan_stock_financial_statement

  • Financial leverage

財務槓桿(Financial leverage) = 總資產(Total Assets)/股東權益(Equity)

Total Assets << api.taiwan_stock_financial_statement

Equity << api.taiwan_stock_financial_statement

We simply write some functions,

# embedded functions: profit margin, total asset turnover, financial leverage
def profit_margin(IncomeAfterTaxes, Revenue):
return IncomeAfterTaxes/Revenue

def total_asset_turnover(Revenue,TotalAssets):
return Revenue/TotalAssets

def financial_leverage(TotalAssets,Equity):
return TotalAssets/Equity

and also a script to extract the data.

from FinMind.data import DataLoader

api = DataLoader()

# data access via API. Example: 2230 台積電
balance_sheet = api.taiwan_stock_balance_sheet(
stock_id='2330',
start_date='2000-01-31',
)

financial_statements = api.taiwan_stock_financial_statement(
stock_id=candidate,
start_date='2000-01-31',
)

Now we are able to do DuPont Analysis Test

from FinMind.data import DataLoader
import pandas as pd


# connect to api
api = DataLoader()

quarters = {'Q1':'03-31','Q2':'06-30','Q3':'09-30','Q4':'12-31'}

# embedded functions: profit margin, total asset turnover, financial leverage
def profit_margin(IncomeAfterTaxes, Revenue):
return IncomeAfterTaxes/Revenue

def total_asset_turnover(Revenue,TotalAssets):
return Revenue/TotalAssets

def financial_leverage(TotalAssets,Equity):
return TotalAssets/Equity

# data access via API
balance_sheet = api.taiwan_stock_balance_sheet(
stock_id='2330',
start_date='2000-01-31',
)

financial_statements = api.taiwan_stock_financial_statement(
stock_id='2330',
start_date='2000-01-31',
)


df = pd.concat([balance_sheet,financial_statements],axis=0)

# date intersect: find the dates where all variables are available
IAF_date = set(df[df['type'].str.contains('IncomeAfterTax')]['date'].values)
R_date = set(df[df['type'].str.contains('Revenue')]['date'].values)
TA_date = set(df[df['type'].str.contains('TotalAssets')]['date'].values)
date_range = sorted(IAF_date & R_date & TA_date)

# assemble and calculate time-series Dupont analysis
Dupont = pd.DataFrame({'quarter':[],'profit_margin':[],'total_asset_turnover':[],'financial_leverage':[],'ROE':[]})
for d in date_range:
IncomeAfterTaxes = df[(df['type']=='IncomeAfterTaxes') & (df['date'] == d)]['value'].values[0]
Revenue = df[(df['type']=='Revenue') & (df['date'] == d)]['value'].values[0]
TotalAssets = df[(df['type']=='TotalAssets') & (df['date'] == d)]['value'].values[0]
Equity = df[(df['type']=='Equity') & (df['date'] == d)]['value'].values[0]
pm = profit_margin(IncomeAfterTaxes,Revenue)
tat = total_asset_turnover(Revenue,TotalAssets)
fl = financial_leverage(TotalAssets,Equity)
df_single = pd.DataFrame({'quarter':[d],'profit_margin':[pm],'total_asset_turnover':[tat],'financial_leverage':[fl],'ROE':[pm*tat*fl* 100]})
Dupont = pd.concat([Dupont,df_single])
Dupont.insert(loc=0, column='stock id', value='2330')

The result is in our Dupont data frame. Let’s take a look.

Dupont.head(5)
Tab. 1 Dupont analysis of 2330 台積電

This is the first (1st) section of our “Mastering Financial Analysis of Value Investing with Python for Better Investment Decisions in Taiwan Exchange Market”. In the next section, we are going to demonstrate our discovery of DuPont analysis comparision and establish a stock selection strategy.

Last but not least, we provide a tutorial in Python on GitHub. You can click on this link and play by yourself.

Reference

1.杜邦分析法是什麼?如何用杜邦分析來看公司財報?Last Update at 2022/10/27. https://rich01.com/what-is-dupont-analysis/

2.股東權益報酬率(ROE) 巴菲特最愛指標,教你簡單看穿企業實力。Last Update at 2021/10/10. https://sparksparkfinance.com/investment/investing-basics/return-on-equity-roe/

--

--