Table of Contents
January 2024 is the time for the presidential election in Taiwan. During this period, the internet is full of election-related news; some even make relevant expectations on the stock market, affecting investor’s sentiment. However, does the so-called “election market trend” really exist? In this article, we will conduct a quantitative analysis on Taiwan stock index in previous presidential elections using TEJ API.
This article uses the Mac operating system and VScode as the editor.
Data period from January 5, 1971, to December 22, 2023, fetching adjusted closing prices of Taiwan Weighted Stock Index (Y9999) for analysis and comparison.
import tejapi
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
tejapi.ApiConfig.api_key = "Your Key"
tejapi.ApiConfig.ignoretz = True
data = tejapi.get('TWN/APRCD1',
coid = 'Y9999',
paginate = True,
)
data.reset_index(inplace=True, drop=True)
data
And then we recorded the election dates of previous presidential elections.
election_date = [pd.Timestamp('1972-03-21', tz = 'UTC'),
pd.Timestamp('1978-03-21', tz = 'UTC'),
pd.Timestamp('1984-03-21', tz = 'UTC'),
pd.Timestamp('1990-03-21', tz = 'UTC'),
pd.Timestamp('1996-03-23', tz = 'UTC'),
pd.Timestamp('2000-03-18', tz = 'UTC'),
pd.Timestamp('2004-03-20', tz = 'UTC'),
pd.Timestamp('2008-03-22', tz = 'UTC'),
pd.Timestamp('2012-01-14', tz = 'UTC'),
pd.Timestamp('2016-01-16', tz = 'UTC'),
pd.Timestamp('2020-01-11', tz = 'UTC')]
We extracted the Taiwan stock index’s closing prices and time series and then combined them to create a chart. Furthermore, we mark the election date on the chart to see whether the “election market trend” exists during the election period.
close = data.loc[:,'close_adj']
close_d = close.to_frame()
time = data.loc[:, 'mdate']
timeline = time.to_frame()
close_d, timeline
Plotting the above closing prices and election dates together, we can get the chart below.
We can tell from this chart that there is no apparent election market trend after the election, and it seems inconsistent. For example, the post-election performance in 1996 and 2016 was better, while the performance in 2000, 2008, and 2020 was poor. However, the declines in these three years are actually caused by the technology bubble, financial crisis, and the outbreak of COVID-19. Because those severe recessions coincidently happened in the election year. It’s hard to find the particular impact of the election on the stock market.
If we want to know whether a specific period before and after the election date has been affected by the election, we can use the ‘count_return‘ function provided below.
The ‘count_return‘ function will determine whether the time window(n) we want is positive or negative. If n is positive, it means counting forwards (defaulted n is 90). If n is negative, it means counting backward. Finally, it will return the rate of return between each election date and our target period.
def count_return(time, n = 90):
if n < 0:
test = tejapi.get('TWN/APRCD1',
coid = 'Y9999',
mdate = {'gte': time - pd.Timedelta(days = abs(n)), 'lte': time})
if len(test) == 0 or (test['mdate'].iloc[-1]!= time):
test = tejapi.get('TWN/APRCD1',
coid = 'Y9999',
mdate = {'gte': time - pd.Timedelta(days = abs(n) + 1), 'lte': time + pd.Timedelta(days = 2)})
first_value = test['close_adj'].iloc[0]
last_value = test['close_adj'].iloc[-1]
else:
test = tejapi.get('TWN/APRCD1',
coid = 'Y9999',
mdate = {'gte': time, 'lte': time + pd.Timedelta(days = n)})
if len(test) == 0 or (test['mdate'].iloc[0]!= time):
test = tejapi.get('TWN/APRCD1',
coid = 'Y9999',
mdate = {'gte': time - pd.Timedelta(days = 2), 'lte': time + pd.Timedelta(days = n + 1)})
first_value = test['close_adj'].iloc[0]
last_value = test['close_adj'].iloc[-1]
final = ((last_value - first_value) / first_value) * 100
return round(final, 2)
We can obtain the return performances on each election year by setting various time window(n) before (or after) the election date in the ‘count_return‘ function.
data_last_90 = []
data_last_60 = []
data_last_30 = []
data_last_7 = []
data_7 = []
data_30 = []
data_60 = []
data_90 = []
data_180 = []
for i in range(7):
data_last_90.append(count_return(election_date[i], n = -90))
data_last_60.append(count_return(election_date[i], n = -60))
data_last_30.append(count_return(election_date[i], n = -30))
data_last_7.append(count_return(election_date[i], n = -7))
data_7.append(count_return(election_date[i], n = 7))
data_30.append(count_return(election_date[i], n = 30))
data_60.append(count_return(election_date[i], n = 60))
data_90.append(count_return(election_date[i], n = 90))
data_180.append(count_return(election_date[i], n = 180))
By setting different time windows(7, 30, 60, 90, 180) in the ‘count_return‘ function, and combining the multiple results together in a chart, we can further discuss the election market trend.
The chart above illustrates the percentage change in the stock market for a specific number of days before and after the election date. Within the first 30 days after the election, there is a short-term upward election market trend, reaching its peak around the 30th day. Subsequently, the stock market weakens, experiencing a continuous decline for up to 180 days after the election. Even on the 200th day, declines are expected to exceed 10%. The author speculates that this trend is because elections are concentrated in Q1, coinciding with the peak season for consumption and a bullish trend during the Chinese New Year. On the other hand, historical economic recessions, such as those in 2000 and 2008, occurred around Q3 and overlapped with election years, thus contributing to the above phenomenon.
The data shows that the stock market has a short-term rise after the elections. However, the timing to enter the market becomes crucial. Moreover, even with more detailed statistical data, it is insufficient to improve our win rate significantly. Thus, relying solely on election market trend to make significant market decisions is not advisable. On a long-term basis, an election is merely a single event that occurs within a holding period, and its impact on the Taiwan stock market is minimal. Considering company fundamentals and moats when making strategic decisions is still preferable.
This implementation utilizes TEJ API to analyze presidential election market trends. Simply using the data provided by TEJ API, we can implement various types of analysis as far as we can imagine. This approach not only saves time and effort but also furnishes investors with a more diversified evaluation method. Explore more related solutions in TEJ E Shop. Construct your trading strategy with the high-quality database.
Reminder: The strategy is only for reference and does not represent recommendations or advice on any financial products and investments.
Research on Presidential Election Market Trend
Subscribe to newsletter