{"id":1689,"date":"2023-12-28T16:39:21","date_gmt":"2023-12-28T16:39:21","guid":{"rendered":"https:\/\/www.tejwin.com\/en\/insights\/election-market-trend\/"},"modified":"2023-12-28T16:39:21","modified_gmt":"2023-12-28T16:39:21","slug":"election-market-trend","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insights\/election-market-trend\/","title":{"rendered":"Is There an Election Market Trend ? Research on Presidential Elections Using TEJ API"},"content":{"rendered":"<figure class=\"wp-block-image aligncenter size-large caption-align-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"Election Market Trend\" class=\"wp-image-19999\" height=\"683\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/element5-digital-T9CXBZLUvic-unsplash.jpg\" style=\"aspect-ratio:1.5;object-fit:cover\" width=\"1024\"\/><figcaption class=\"wp-element-caption\">Photo by <a class=\"ek-link\" href=\"https:\/\/unsplash.com\/@element5digital\" rel=\"noopener\" target=\"_blank\">Element5 Digital<\/a> on <a class=\"ek-link\" href=\"https:\/\/unsplash.com\/\" rel=\"noopener\" target=\"_blank\">Unsplash<\/a><\/figcaption><\/figure>\n<h2 class=\"wp-block-heading\">Highlight<\/h2>\n<ul class=\"wp-block-list\">\n<li>Article Difficulty\uff1a\u2605\u2606\u2606\u2606\u2606<\/li>\n<li>Analyzing the existence of election market trend on Taiwan Weighted Stock Index over the past presidential elections.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">Preface<\/h2>\n<p class=\"wp-block-paragraph\">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\u2019s sentiment. However, does the so-called \u201celection market trend\u201d really exist? In this article, we will conduct a quantitative analysis on Taiwan stock index in previous presidential elections using TEJ API.<\/p>\n<h2 class=\"wp-block-heading\"><strong>Editing Environment and Module Requirements<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">This article uses the Mac operating system and VScode as the editor.<\/p>\n<h2 class=\"wp-block-heading\">Data Import<\/h2>\n<p class=\"wp-block-paragraph\">Data period from January 5, 1971, to December 22, 2023, fetching adjusted closing prices of Taiwan Weighted Stock Index (Y9999) for analysis and comparison.<\/p>\n<pre class=\"wp-block-code\"><code>import tejapi\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport matplotlib.dates as mdates<code>\n<\/code>tejapi.ApiConfig.api_key = \"Your Key\"\ntejapi.ApiConfig.ignoretz = True\n\ndata = tejapi.get('TWN\/APRCD1',\n                coid = 'Y9999',\n                paginate = True,\n                )\ndata.reset_index(inplace=True, drop=True)\ndata<\/code><\/pre>\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" alt=\"Election Market Trend\" class=\"wp-image-20087\" height=\"492\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/data.png\" width=\"1024\"\/><\/figure>\n<p class=\"wp-block-paragraph\">And then we recorded the election dates of previous presidential elections.<\/p>\n<pre class=\"wp-block-code\"><code>election_date = [pd.Timestamp('1972-03-21', tz = 'UTC'),\n                 pd.Timestamp('1978-03-21', tz = 'UTC'),\n                 pd.Timestamp('1984-03-21', tz = 'UTC'),\n                 pd.Timestamp('1990-03-21', tz = 'UTC'),\n                 pd.Timestamp('1996-03-23', tz = 'UTC'),\n                 pd.Timestamp('2000-03-18', tz = 'UTC'),\n                 pd.Timestamp('2004-03-20', tz = 'UTC'),\n                 pd.Timestamp('2008-03-22', tz = 'UTC'),\n                 pd.Timestamp('2012-01-14', tz = 'UTC'),\n                 pd.Timestamp('2016-01-16', tz = 'UTC'),\n                 pd.Timestamp('2020-01-11', tz = 'UTC')]<\/code><\/pre>\n<h2 class=\"wp-block-heading\">Create Election Event Points<\/h2>\n<p class=\"wp-block-paragraph\">We extracted the Taiwan stock index\u2019s 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 \u201celection market trend\u201d exists during the election period.<\/p>\n<h3 class=\"wp-block-heading\">Extract closing price and time series<\/h3>\n<pre class=\"wp-block-code\"><code>close = data.loc[:,'close_adj']\nclose_d = close.to_frame()\ntime = data.loc[:, 'mdate']\ntimeline = time.to_frame()\nclose_d, timeline<\/code><\/pre>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" alt=\"Election Market Trend\" class=\"wp-image-20089\" height=\"688\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/price-time.png\" style=\"object-fit:cover\" width=\"544\"\/><\/figure>\n<h3 class=\"wp-block-heading\">Mark the election date and plot<\/h3>\n<p class=\"wp-block-paragraph\">Plotting the above closing prices and election dates together, we can get the chart below. <\/p>\n<figure class=\"wp-block-image size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"Election Market Trend\" class=\"wp-image-19993\" height=\"582\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/E688AAE59C96-2023-12-27-E4B88BE58D883.02.14.png\" style=\"aspect-ratio:3.7925925925925927;object-fit:cover\" width=\"2210\"\/><figcaption class=\"wp-element-caption\">Taiwan Weighted Stock Index<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">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\u2019s hard to find the particular impact of the election on the stock market.<\/p>\n<h2 class=\"wp-block-heading\">Backtesting Returns on Taiwan Weighted Stock index on previous presidential elections<\/h2>\n<p class=\"wp-block-paragraph\">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 \u2018<em><strong>count_return<\/strong><\/em>\u2018 function provided below. <\/p>\n<p class=\"wp-block-paragraph\">The \u2018<em><strong>count_return<\/strong><\/em>\u2018 function will determine whether the time window(<em>n<\/em>) we want is positive or negative. If <em>n<\/em> is positive, it means counting forwards (defaulted <em>n<\/em> 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.<\/p>\n<pre class=\"wp-block-code\"><code>def count_return(time, n = 90):\n  if n &lt; 0:\n    test = tejapi.get('TWN\/APRCD1',\n                    coid = 'Y9999',\n                      mdate = {'gte': time - pd.Timedelta(days = abs(n)), 'lte': time})\n    if len(test) == 0 or (test['mdate'].iloc[-1]!= time):\n      test = tejapi.get('TWN\/APRCD1',\n                  coid = 'Y9999',\n                    mdate = {'gte': time - pd.Timedelta(days = abs(n) + 1), 'lte': time + pd.Timedelta(days = 2)})\n    first_value = test['close_adj'].iloc[0]\n    last_value = test['close_adj'].iloc[-1]\n  else:\n    test = tejapi.get('TWN\/APRCD1',\n                coid = 'Y9999',\n                  mdate = {'gte': time, 'lte': time + pd.Timedelta(days = n)})\n    if len(test) == 0 or (test['mdate'].iloc[0]!= time):\n      test = tejapi.get('TWN\/APRCD1',\n                  coid = 'Y9999',\n                  mdate = {'gte': time - pd.Timedelta(days = 2), 'lte': time + pd.Timedelta(days = n + 1)})\n    first_value = test['close_adj'].iloc[0]\n    last_value = test['close_adj'].iloc[-1]\n  final = ((last_value - first_value) \/ first_value) * 100\n  return round(final, 2)<\/code><\/pre>\n<p class=\"wp-block-paragraph\">We can obtain the return performances on each election year by setting various time window(<em>n<\/em>) before (or after) the election date in the \u2018<strong><em>count_return<\/em><\/strong>\u2018 function.<\/p>\n<pre class=\"wp-block-code\"><code>data_last_90 = []\ndata_last_60 = []\ndata_last_30 = []\ndata_last_7 = []\ndata_7 = []\ndata_30 = []\ndata_60 = []\ndata_90 = []\ndata_180 = []\n\nfor i in range(7):\n    data_last_90.append(count_return(election_date[i], n = -90))\n    data_last_60.append(count_return(election_date[i], n = -60))\n    data_last_30.append(count_return(election_date[i], n = -30))\n    data_last_7.append(count_return(election_date[i], n = -7))\n    data_7.append(count_return(election_date[i], n = 7))\n    data_30.append(count_return(election_date[i], n = 30))\n    data_60.append(count_return(election_date[i], n = 60))\n    data_90.append(count_return(election_date[i], n = 90))\n    data_180.append(count_return(election_date[i], n = 180))<\/code><\/pre>\n<h3 class=\"wp-block-heading\">Election Market Trend Analysis<\/h3>\n<p class=\"wp-block-paragraph\">By setting different time windows(7, 30, 60, 90, 180) in the \u2018<strong><em>count_return<\/em><\/strong>\u2018 function, and combining the multiple results together in a chart, we can further discuss the election market trend.<\/p>\n<figure class=\"wp-block-image size-large caption-align-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"Election Market Trend\" class=\"wp-image-20091\" height=\"256\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/return-change.png\" style=\"object-fit:cover\" width=\"1024\"\/><figcaption class=\"wp-element-caption\">Return rates in different periods before (and after) election day<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">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.<\/p>\n<figure class=\"wp-block-image size-large caption-align-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"Election Market Trend\" class=\"wp-image-20001\" height=\"787\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/E688AAE59C96-2023-12-27-E4B88BE58D884.44.22.png\" style=\"aspect-ratio:1.301143583227446;object-fit:cover\" width=\"1024\"\/><figcaption class=\"wp-element-caption\">Except for the year 1996, the other three election years coincided with recessionary periods, <br \/>leading to a half-year bearish trend following the elections.<\/figcaption><\/figure>\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n<p class=\"wp-block-paragraph\">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.<\/p>\n<p class=\"wp-block-paragraph\">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\u00a0<a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/index\" rel=\"noreferrer noopener\" target=\"_blank\">TEJ E Shop<\/a>. Construct your trading strategy with the high-quality database.<\/p>\n<p class=\"wp-block-paragraph\">Reminder: <strong>The strategy is only for reference and does not represent recommendations or advice on any financial products and investments.<\/strong><\/p>\n<h2 class=\"wp-block-heading\">Github Source Code<\/h2>\n<p class=\"wp-block-paragraph\"><a class=\"ek-link\" href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Quant\/blob\/f39e540098a3d068a564a75f6455fb9c263e13db\/%E7%B8%BD%E7%B5%B1%E5%A4%A7%E9%81%B8%E8%A1%8C%E6%83%85%E4%BA%8B%E4%BB%B6%E7%A0%94%E7%A9%B6.ipynb\" rel=\"noopener\" target=\"_blank\">Research on Presidential Election Market Trend<\/a><\/p>\n<h2 class=\"wp-block-heading\">Extended Reading<\/h2>\n<ul class=\"wp-block-list\">\n<li><a aria-label=\" (opens in a new tab)\" class=\"ek-link\" href=\"\/en\/insight\/national-stabilization-fund-performances\/\" rel=\"noreferrer noopener\" target=\"_blank\">National Stabilization Fund Performances<\/a><\/li>\n<li><a aria-label=\" (opens in a new tab)\" class=\"ek-link\" href=\"\/en\/insight\/performance-of-taiex-during-chinese-new-year\/\" rel=\"noreferrer noopener\" target=\"_blank\">Performance of TAIEX during Chinese New Year<\/a><\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">Related Links<\/h2>\n<ul class=\"wp-block-list\">\n<li><a class=\"ek-link\" href=\"https:\/\/api.tej.com.tw\/index.html\" rel=\"noopener\" target=\"_blank\">TEJ API HomePage<\/a><\/li>\n<li><a class=\"ek-link\" href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_intro\" rel=\"noopener\" target=\"_blank\">TEJ E-Shop Purchase<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>During the election period, the internet is full of election-related news; some even make relevant expectations on the stock market, affecting investor\u2019s sentiment. However, does the so-called \u201celection market trend\u201d really exist? In this article, we will conduct a quantitative analysis on Taiwan stock index in previous presidential elections using TEJ API.<\/p>\n","protected":false},"featured_media":1688,"template":"","tags":[52,65,70,91],"insight_category":[16],"class_list":["post-1689","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-quantitative-analysis","tag-python","tag-tej-api","tag-beginners-guide","insight_category-quant-data-science"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/1689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight"}],"about":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/types\/insight"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/1688"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=1689"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=1689"},{"taxonomy":"insight_category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight_category?post=1689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}