【Application】TQuant Lab Warren E. Buffett’s Business Investment Rules

Buffett’s Business Investment Rules
Photo by Scott Graham on Unsplash

Highlight

  • Article Difficulty: ★★☆☆☆
  • This article is adapted from Warren E. Buffett’s Value Investing, using TejToolAPI to fetch the financial data required for Buffett’s Business Investment Rules. After organizing the data, targets that meet the criteria of Business Investment Rules are identified.
  • Utilizing TQuant Lab to buy and hold targets that align with the Business Investment Rules for one year ( 2023 ), observing their risk and return performance.

Preface

Warren E. Buffett adhered to rational investment principles throughout his lifetime. His Business Investment Rules stress investing with the mindset of acquiring a whole business rather than simply investing in stocks.

This article selects five critical stock selection criteria from Buffett’s Business Investment Rules. From utilizing TejToolAPI to fetch financial data and screen targets to using TQuant Lab to backtest investment risks and performance, we will explore Buffett’s investment style and appreciate the ability of Business Investment Rules to generate excess returns.

Buffett’s Business Investment Principles — Five Main Stock Selection Criteria

Because certain aspects of Buffett’s Business Investment Principles are non-quantifiable, we have chosen only the quantifiable stock selection criteria, all rooted in the underlying principle of a company’s ability to generate profits for its shareholders. The stock selection criteria are as follows:

  1. Return on equity for the latest fiscal year > the industry average.
  2. 3-year average return on equity > 15%.
  3. Gross margin for the latest fiscal year > the industry average.
  4. ( Market value increase over 7 years / retained earnings increase over 7 years ) > 1.
  5. ( Free cash flow for the latest fiscal year / free cash flow 7 years ago ) — 1 > 1.

Coding Environment

This article is written using Windows 11 and Jupyter Lab as the editor.

Financial Data Collection

By importing the basic packages and inputting the API key, we can access the TEJ financial database.

import os
import numpy as np
import pandas as pd

# tej_key
tej_key = 'your key'
api_base = 'https://api.tej.com.tw'

os.environ['TEJAPI_KEY'] = tej_key
os.environ['TEJAPI_BASE'] = api_base

Before we access the TEJ database, we use the get_universe() function to get our stock pool. In this case, we have chosen ordinary shares listed by the end of 2015 while excluding highly leveraged financial industries.

from zipline.sources.TEJ_Api_Data import get_universe

pool = get_universe(start = '2015-12-31',
end = '2015-12-31',
mkt_bd_e = 'TSE', # listed stocks in TWSE
stktp_e = 'Common Stock',
main_ind_e = 'General Industry') # general industry can exclude financial industry

Then, we use TejToolAPI to collect the following financial items required in the Business Investment Rules.

  1. Industry
  2. Return on equity
  3. Gross margin
  4. Market value
  5. Retained earnings
  6. Cash flow from operating activities
  7. Cash flow from investing activities

Note: The cash flow from operating activities and the cash flow from investing activities can be used to calculate free cash flow.

import TejToolAPI

start_time = pd.Timestamp('2015-12-31')
end_time = pd.Timestamp('2022-12-30')

data = TejToolAPI.get_history_data(start = start_time,
end = end_time,
ticker = pool,
fin_type = 'A', # Cumulative data
columns = ['Industry_Eng', 'Return_Rate_on_Equity_A_percent', 'Gross_Margin_Rate_percent', 'Market_Cap_Dollars', 'Total_Retained_Earnings', 'Cash_Flow_from_Operating_Activities', 'Cash_Flow_from_Investing_Activities'])
Buffett’s Business Investment Rules
The Overall Financial Data Extracted from TejToolAPI

Target Screening

After data analysis, we can obtain our final 17 targets that meet all the five stock-selecting criteria.

Buffett’s Business Investment Rules
Targets that Meet the Five Criteria

TQuant Lab Buy & Hold Strategy

Next, we use TQuant Lab to execute a buy-and-hold strategy for the above targets for one year ( 2023 ) and observe the risk and return performance.

Data Import

Data Period: January 1, 2023, to December 31, 2023

We import the price data of the 17 targets and the TAIEX-Total Return Index ( IR0001 ) to be the benchmark of our backtest.

start = '2023-01-01'
end = '2023-12-31'

os.environ['mdate'] = start + ' ' + end
os.environ['ticker'] = ' '.join(tickers) + ' ' + 'IR0001'

!zipline ingest -b tquant

Trading Rules

On January 1, 2023, evenly allocate assets to purchase the targets and hold them until the end of the backtesting period.

Execute the Trading Strategy

We executed the configured Buy & Hold strategy with the trading period from 2023–01–01 to 2023–12–31 and with the initial capital of 10,000,000 NTD. The output, or results, will represent the daily performance and detailed transaction records.

from zipline import run_algorithm

start_date = pd.Timestamp(start, tz = 'utc')
end_date = pd.Timestamp(end, tz = 'utc')
capital_base = 1e7

results = run_algorithm(
start = start_date,
end = end_date,
initialize = initialize,
handle_data = handle_data,
analyze = analyze,
bundle = 'tquant',
capital_base = capital_base,
)
results
Buffett’s Business Investment Rules
Transaction Details

Performance Evaluation by Pyfolio

Buffett’s Business Investment Rules
Backtest Performance and the Comparison with benchmark

From the chart above, we can see that in 2023, the overall market is bull, with a market return of around 30%. However, the targets selected by Buffett’s Business Investment Rules outperform the market by approximately 20 percentage points, achieving a cumulative return of 51.525%. Additionally, the portfolio’s Alpha value is 0.24, and the Beta value is 0.8, indicating that Buffett’s Business Investment Rules not only bear less systematic risk than the market but also generate excess returns.

Furthermore, we plotted the Sharpe ratio chart below to observe whether Buffett’s Business Investment Rules can achieve higher excess returns under the same level of risk exposure.

Buffett’s Business Investment Rules
Sharpe Ratio Comparison Chart

Observing the chart above, we can see that the Sharpe ratios of the portfolio based on Buffett’s Business Investment Rules mostly exceed the market, averaging around 2.4. Therefore, the Business Investment Rules indeed assist us in earning higher returns than the market under a certain level of risk.

Conclusion

In this implementation, we utilized the five primary stock selection criteria of Buffett’s Business Investment Rules, combined with TejToolAPI for fundamental stock selection. We then conducted a one-year backtesting performance analysis using TQuant Lab. From the analysis results, whether the return rate, Alpha, Beta, or Sharpe ratio, Buffett’s Business Investment Rules demonstrated excellent stability and the ability to earn excess returns. No wonder this set of principles has stood the test of time.

The author believes the remarkable aspect of Buffett’s Business Investment Rules is that many investors lose their rationality due to short-term market fluctuations, leading to premature exits and missing out on potential returns. In contrast, Buffett’s Business Investment Rules teach us that by carefully selecting outstanding stocks based on the profit characteristics of each company before investing and holding them for the long term, we can confidently achieve excess returns.

Please note that the strategy and target discussed in this article are for reference only and do not constitute any recommendation for specific commodities or investments. In the future, we will also introduce using the TEJ database to construct various indicators and backtest their performance. Therefore, we welcome readers interested in various trading backtesting to consider purchasing relevant solutions from TQuant Lab. With our high-quality databases, you can construct a trading strategy that suits your needs.

Source Code

Extended Reading

About

--

--

TEJ 台灣經濟新報
TEJ-API Financial Data Analysis

TEJ 為台灣本土第一大財經資訊公司,成立於 1990 年,提供金融市場基本分析所需資訊,以及信用風險、法遵科技、資產評價、量化分析及 ESG 等解決方案及顧問服務。鑒於財務金融領域日趨多元與複雜,TEJ 結合實務與學術界的精英人才,致力於開發機器學習、人工智慧 AI 及自然語言處理 NLP 等新技術,持續提供創新服務