【Application (14)】The relationship between the yield rate of U.S. bonds and Taiwan stocks

Analyze the relationship between U.S. Treasuries and different types of Taiwan stocks.


  • Difficulty:★☆☆☆☆
  • We use the regression model to find the relationship between the change in the yield of U.S. Treasuries and the Taiwan stock market, electronic stocks, financial stocks, and high dividend stocks.
  • Advice: In terms of models, this article will not delve into the architectural composition, only analyze the information that the model results let us understand, so readers need to have a basic concept of the statistical model; in addition, the fund target mentioned in this article is for illustrative purposes only and does not represent any financial product recommendation or recommendation.


Raw material prices soaring, inflation and interest rate increases are the main issues in the financial market this year. The news media often report that the recent decline in Taiwan’s stock market is related to international capital flows, so this article takes this as a starting point to analyze the relationship between Taiwan’s stock market and the U.S. bond yield through statistical methods.

The Editing Environment and Modules Required

This article uses MacOS and uses Jupyter Notebook as the editor.

# Basic
import numpy as np
import pandas as pd
import tejapi
tejapi.ApiConfig.api_key = 'Your Key'
tejapi.ApiConfig.ignoretz = True


General Economic Statement Table: The description table is used for the accounts of the overall economic table. The data code is (GLOBAL/ABMAR).

Overall Economic Table: The overall economic indicators issued by the government department. Including the IMF and OECD, as well as related professional publications. The data code is (GLOBAL/ANMAR).

Listed (Counter) Adjusted Share Price (Monthly) Ex-Dividend Adjustment: Monthly Information on Listed Securities and Indices (TSE and OTC). The data code is (TWN/AAPRCM1).

U.S. Debt Yield Ratio

Step 1. Read the data name and code id

factor_macro = tejapi.get('GLOBAL/ABMAR',
opts={'columns': ['coid','mdate', 'ename', 'freq']},
select_1 = list(factor_macro['ename'][i] for i in range(0,6214) if 'Yeild' in factor_macro.iloc[i,2])

The above process begins by reading the names of all the general economic database data and setting conditions in Chinese. We use the name contains “殖利率”(yield) to Filter out the “美國十年期公債殖利率”(yield rate of the United States 10-year Treasury).

factor_macro[factor_macro['ename'] == '10 Years Government Bond Yields(Long Term) - U.S.A.']

By setting the condition of the full Chinese name, we can find the data’s coid(code id) — CA15.

Step 2. Read the U.S. Treasury yield data

yield_10yr = tejapi.get('GLOBAL/ANMAR',
mdate={'gte': '2020-01-01', 'lte':'2022-03-01'},
opts={'columns': ['mdate', 'val']},
coid = 'CA15',
yield_10yr = yield_10yr.rename(columns = {'數值':'yield_10yr'})

Taiwan stock data

Step 1. Read indexes, fund remuneration data

index_list = ['Y9997', '0053', '0055', '0056']index_data = tejapi.get('TWN/APRCM',
coid = index_list,
mdate= {'gte': '2020-01-01', 'lte': '2022-03-01'},
opts={'columns': ['coid', 'mdate', 'roi']},
paginate = True,
chinese_column_name = True)

This article selects the Y9997 remuneration index as a representative of the Taiwan stock market. 0053 is a fund for electronic stocks; 0055 is a financial stock fund. Furthermore, 0056 is a high-dividend stock fund.

Note: 0056 is not a pure conventional industry fund; its main constituent stocks also contain high yield targets in electronic shares.

Step 2. Data Arrangement.

index_data = index_data.set_index('年月')roi = {}for i in index_list:
r = index_data[index_data['證券代碼'] == i]
r = r['報酬率%_月']
roi.setdefault(i, r)
roi = pd.concat(roi, axis = 1).reset_index()

Model adaptation process

Step 1. Data Consolidation

final = pd.merge(roi, yield_10yr, how = 'inner', on = ['年月'])
final = final.rename(columns = {'Y9997':'台灣大盤', '0053':'電子股', '0055':'金融股', '0056':'高股息'})

Step 2. Model Adaptation

import statsmodels.formula.api as smf
from statsmodels.stats.anova import anova_lm
for i in list(final.columns)[1:5]:
data = pd.DataFrame(final[[i, 'yield_10yr']])
mdl = smf.ols(i + ' ~ yield_10yr', data=data).fit()

First, the names of each type of index or fund in the final table are obtained through “list ( final.columns ) [ 1:5 ]” and then put into the for-loop. Take each U.S. 10-year Treasury yield for adapting, and the following will explain the model results one by one.

The model results illustrate.

First, we can see the interpretation variable column of the 10-year bond yield (the red box). In the coefficient column, you can know that the two data are negatively correlated; and by the P value of 0.169, you can confidently judge that its role in the Taiwan stock market is not significant; in addition, the R² (the blue box) of 0.074 also indicates that the interpretation ability is quite insufficient.

In the interpretation variable field (the red box), it can be understood that the two data are also negatively correlated, and the P value of 0.042 can be judged that the performance of the U.S. Treasury yield on Taiwan electronic stocks is significant. However, it does not reach the highest standard of 0.01, so considering the R² (the blue box) is 0.156. It is inferred that the explanatory variable has a slight explanatory strength.

In the interpretation variable field (the red box), it can be understood that the two data are positively correlated; and the P value of 0.357 can be confidently judged that its effect on the Taiwan stock market is insignificant. In addition, the R² (the blue box) of 0.034 also indicates that the interpretation ability is quite insufficient.

In the interpretation variable field (the red box), it can be understood that the two data are negatively correlated; and the P value of 0.622 can be confidently judged that its role in the Taiwan stock market is insignificant. In addition, the R² (the blue box) of 0.010 also indicates that the interpretation ability is quite insufficient.


Through the above model results, I believe that readers can know that in addition to electronic related stocks, the interpretation ability of U.S. treasury yields for Taiwan’s broader market, financial stocks, and high dividend targets has not reached a certain level. However, this does not mean that Taiwan stock investors can ignore the overall economic or monetary policy of the Federal Reserve. After all, as a world economic leader, its general economic situation and the central bank’s attitude will still affect the flow of international funds. Taiwan is absolutely no exception because the central axis of Taiwan’s industrial development is electronic technology stocks. The impact of U.S. bond yields on this ethnic group can also be observed from the statements, which reminds us that in the environment of inflation and interest rate increase issues this year. As Taiwan stock investors, we need to pay more attention to the industrial and economic trends in the United States. Therefore, we welcome readers to continue to pay attention to this platform, and there will be more articles on the impact of the overall economy on the stock market. In addition, readers are also welcome to choose the plan in the TEJ E Shop. I believe that readers can quickly grasp the market trend after having a complete database.

Source Code

Extended Reading

Related Link

You could give us encouragement by …
We will share financial database applications every week.
If you think today’s article is good, you can click on the
applause icononce.
If you think it is awesome, you can hold the
applause icon until 50 times.
If you have any feedback, please feel free to leave a comment below.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
TEJ 台灣經濟新報

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