{"id":15484,"date":"2021-03-29T00:41:35","date_gmt":"2021-03-28T16:41:35","guid":{"rendered":"https:\/\/www.tejwin.com\/?post_type=insight&#038;p=15484"},"modified":"2024-06-19T16:40:55","modified_gmt":"2024-06-19T08:40:55","slug":"%e3%80%8cgarbage-in-garbage-out-%e3%80%8d","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/","title":{"rendered":"\u300cGarbage in, garbage out.\u300d"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"682\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\/image-216-1024x682.png\" alt=\"\" class=\"wp-image-15485\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-216-1024x682.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-216-300x200.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-216-150x100.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-216-768x512.png 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-216.png 1400w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p id=\"e1b1\">&#8211; Explaining the importance of data quality \u2014 Free data api versus TEJ API<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"52bf\">People who do quantitative investing might be familiar with open data source\/API such as Yahoo Finance, Google Finance, etc. which we usually get data from their websites for backtesting. However,&nbsp;<strong>free data sources we mentioned above are not database companies specialized in Taiwan. Therefore, comparing to the market in the US, they do worse on maintaining the database of the stock market in Taiwan. Moreover, if there is a flaw in the data for backtesting, it will strongly affect the performance of the models or strategies.<\/strong>&nbsp;Under this condition, we will emphasize the importance of quality of data, but how can you know whether your data is qualified enough? So, in this episode, we will share our methods for checking the quality of data with you.<\/p>\n<\/blockquote>\n<\/blockquote>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f76988da974\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69f76988da974\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#Highlights_of_this_article\" >Highlights of this article<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#Links_related_to_this_article\" >Links related to this article<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#Adjusted_vs_non-adjusted_stock_price\" >Adjusted v.s non-adjusted stock price<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#Summary\" >Summary<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#1_Import_packages\" >1. Import packages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#2_Extract_adjusted_non-adjusted_stock_prices_from_TEJ\" >2. Extract adjusted &amp; non-adjusted stock prices from TEJ.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#3_Data_visualization\" >3. Data visualization<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#4_View_the_return\" >4. View the return<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#Free_data_API_vs_TEJ_API\" >Free data API vs TEJ API<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#1_Import_packages-2\" >1. Import packages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#2_Grab_data_from_both_API\" >2. Grab data from both API<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#3_Data_visualization-2\" >3. Data visualization<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#4_View_the_return-2\" >4. View the return<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#Quality_of_data\" >Quality of data<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.tejwin.com\/en\/insight\/%e3%80%8cgarbage-in-garbage-out-%e3%80%8d\/#Links_related_to_this_article_again\" >Links related to this article again!<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"6c65\"><span class=\"ez-toc-section\" id=\"Highlights_of_this_article\"><\/span><strong> Highlights of this article <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Adjusted stock price &amp; non-adjusted stock price Intro\/Application<\/strong><\/li>\n\n\n\n<li><strong> Free data v.s. TEJ API &#8211; The difference in the quality of data<\/strong><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"439d\"><span class=\"ez-toc-section\" id=\"Links_related_to_this_article\"><\/span><strong>Links related to this article<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>1\ufe0f\u20e3 API Official Website:&nbsp;<a href=\"https:\/\/api.tej.com.tw\/\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>TEJ API Official Website<\/strong><\/a><\/li>\n\n\n\n<li>2\ufe0f\u20e3 The Product Package:<strong>&nbsp;<\/strong><a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_caseIntro\/1\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>TEJ E SHOP<\/strong><\/a><\/li>\n\n\n\n<li>3\ufe0f\u20e3 Source Code:&nbsp;<a href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_DataAnalysis\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>TEJ GITHUB<\/strong><\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e9b9\"><span class=\"ez-toc-section\" id=\"Adjusted_vs_non-adjusted_stock_price\"><\/span>Adjusted v.s non-adjusted stock price<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"e9bc\">Using 0050 as an example:<\/h4>\n\n\n\n<p id=\"c1f2\">Assume that 0050 was priced at 30 dollars 10 years before, and the current price of 0050 is 120 dollars. Therefore, we can say that the return on it is 300%. However, it doesn\u2019t consider cash dividends, so the real return on 0050 is not precise.&nbsp;<strong>Using non-adjusted stock prices to calculate the return ignores the distribution of cash dividends,<\/strong>&nbsp;but people who deposit their money into the stock do care about dividend yields. As a result, the method that we calculate the return by non-adjusted stock price is not accurate.<\/p>\n\n\n\n<p id=\"5b94\">However,&nbsp;<strong>the adjusted stock price is the price that has taken cash dividends\/ stock dividends\/cash capital increase into account.<\/strong>&nbsp;Assume that the adjusted price of 0050 was 10 dollars 10 years before, and the current adjusted price of 0050 is 100 dollars, which means increasing 900% in total.&nbsp;<strong>In this case, we can find the return calculate by the adjusted stock price is much more accurate!<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"9e93\">The individual stock has to consider much more factors than ETFs, and we will provide a comprehensive introduction in the future. If you want to learn more please<strong>&nbsp;follow us<\/strong>&nbsp;and keep focusing on our articles.<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4eb7\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Non-Adjusted Stock Price \u27a1\ufe0f Market Price<\/strong><\/li>\n\n\n\n<li><strong>Adjusted Stock Price \u27a1\ufe0f The price which is converted from cash dividends\/ stock dividends\/Cash Capital Increase.<\/strong><\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"44df\">Using 0050 as an example to see the difference of the return from adjusted &amp; non-adjusted stock prices.<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"f638\"><span class=\"ez-toc-section\" id=\"1_Import_packages\"><\/span>1. Import packages<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"0a25\">If you do not have an api_key yet, you can&nbsp;<strong><em>\ud83c\udd93<\/em><\/strong><a href=\"https:\/\/api.tej.com.tw\/trial.html\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>register an account on TEJ for a free trial<\/strong><\/a><strong><em>\ud83c\udd93<\/em><\/strong>,<strong>&nbsp;but the trial account has a limit on getting data<\/strong>\u2757\ufe0f The database used in this episode is from \u659c\u69d3\u65b9\u6848\u7684\u8b49\u5238\u4ea4\u6613\u8cc7\u6599\u8868 (TWN\/EWPRCD).<strong>&nbsp;If you want to use data without limit, check it on&nbsp;<a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/\" target=\"_blank\" aria-label=\"TEJ E Shop (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">TEJ E Shop<\/a>\ud83c\udf81.<\/strong><\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd \nimport numpy as np\nimport matplotlib.pyplot as plt\nimport pandas_datareader as pdr\nimport tejapi\ntejapi.ApiConfig.api_key = 'your key'<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"e732\"><span class=\"ez-toc-section\" id=\"2_Extract_adjusted_non-adjusted_stock_prices_from_TEJ\"><\/span>2. Extract adjusted &amp; non-adjusted stock prices from TEJ.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>stk_num = '0050'\nstk_data = tejapi.get('TWN\/EWPRCD',coid = stk_num,paginate = True\n                      ,opts= {'columns':&#91;'coid','mdate','open_d','high_d','low_d','close_d']}) \n# non-adjusted\nstk_adj = tejapi.get('TWN\/EWPRCD',coid = stk_num,paginate = True\n                    ,opts= {'columns':&#91;'coid','mdate','open_adj','high_adj','low_adj','close_adj']}) \n# adjusted<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img decoding=\"async\" width=\"507\" height=\"202\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-217.png\" alt=\"\" class=\"wp-image-15488\" style=\"width:547px;height:218px\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-217.png 507w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-217-300x120.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-217-150x60.png 150w\" sizes=\"(max-width: 507px) 100vw, 507px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"527\" height=\"201\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-219.png\" alt=\"\" class=\"wp-image-15492\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-219.png 527w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-219-300x114.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-219-150x57.png 150w\" sizes=\"(max-width: 527px) 100vw, 527px\" \/><figcaption class=\"wp-element-caption\">non-adjusted (up)\/ adjusted(down)<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Data_visualization\"><\/span>3. Data visualization<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>plt.style.use('seaborn')\nplt.figure(figsize=(10,5))\nplt.title('0050',fontsize = 20)\nl1 = plt.plot(stk_data.mdate,stk_data.close_d,label = 'market_price')\nl2 = plt.plot(stk_adj.mdate,stk_adj.close_adj,label = 'adjusted_price')\nparams = {'legend.fontsize': 14,\n          'legend.handlelength': 3,\n         'axes.labelsize': 25}\nplt.rcParams.update(params)\nplt.legend(loc=\"upper left\")\nplt.xlabel('Date', fontsize=20)\nplt.ylabel('Price', fontsize=20)\nplt.show()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"646\" height=\"349\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-220.png\" alt=\"\" class=\"wp-image-15494\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-220.png 646w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-220-300x162.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-220-150x81.png 150w\" sizes=\"(max-width: 646px) 100vw, 646px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"d98d\"><span class=\"ez-toc-section\" id=\"4_View_the_return\"><\/span>4. View the return<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"0a1b\">The Return Formula\uff1a<br>The close price of the start date is our buy price(buy_price), and the close price of the most recent trading date is our sell price(sell_price).<\/p>\n\n\n\n<p id=\"cabb\">Return = (sell_price-buy_price)\/buy_price<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code># Difference of return\nbuy_price_mp, buy_price_adj = stk_data.close_d.values&#91;0], stk_adj.close_adj.values&#91;0]\nsell_price_mp, sell_price_adj = stk_data.close_d.values&#91;-1], stk_adj.close_adj.values&#91;-1]\nreturn_mp, return_adj = ((sell_price_mp-buy_price_mp)\/buy_price_mp), ((sell_price_adj-buy_price_adj)\/buy_price_adj)\nprint(\"\u672a\u8abf\u6574\u80a1\u50f9\u5831\u916c\u7387:\",return_mp,\"\u8abf\u6574\u80a1\u50f9\u5831\u916c\u7387:\", return_adj)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/11hRz9JC4pi_bmx-l3GJlnQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"5ec3\"><strong>We can tell from the result, the difference between adjusted &amp; non-adjusted stock return is more than 40%!!<\/strong><\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"84d4\"><span class=\"ez-toc-section\" id=\"Free_data_API_vs_TEJ_API\"><\/span>Free data API vs TEJ API<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"beae\">Besides TEJ API, free data API also provides adjusted stock prices (we use Yahoo Finance API in this episode), so we would like to make a comparison between both.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1907\"><span class=\"ez-toc-section\" id=\"1_Import_packages-2\"><\/span>1. Import packages<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd \nimport numpy as np\nimport matplotlib.pyplot as plt\nimport pandas_datareader as pdr\nimport tejapi\ntejapi.ApiConfig.api_key = 'your key'<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Grab_data_from_both_API\"><\/span>2. Grab data from both API<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>stk_num = '0050'\n\nstk_adj = tejapi.get('TWN\/EWPRCD',coid = stk_num,paginate = True\n                    ,opts= {'columns':&#91;'coid','mdate','open_adj','high_adj','low_adj','close_adj']}) \n# adjusted\nyf_data = pdr.DataReader(stk_num+'.tw','yahoo') # Yahoo Finance<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1fw1wyFWJau-SR66I_tP-lw.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1OT2hbqs9osrRazWA8YTOcA.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">TEJ adjusted price(up)\/YF adjusted price(down)<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"a68a\"><span class=\"ez-toc-section\" id=\"3_Data_visualization-2\"><\/span>3. Data visualization<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>plt.style.use('seaborn')\nplt.figure(figsize=(10,5))\nplt.title('0050',fontsize = 20)\nl1 = plt.plot(yf_data.index,yf_data&#91;'Adj Close'],label = 'yf_adjusted')\nl2 = plt.plot(stk_adj.mdate,stk_adj.close_adj,label = 'tej_adjusted')\nparams = {'legend.fontsize': 14,\n          'legend.handlelength': 3,\n         'axes.labelsize': 25}\nplt.rcParams.update(params)\nplt.legend(loc=\"upper left\")\nplt.xlabel('Date', fontsize=20)\nplt.ylabel('Price', fontsize=20)\nplt.show()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1gf6biILCCPfkclnG4NykwQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"5f40\">Because there(\u659c\u69d3\u65b9\u6848) is a 5-year limit on our data, the difference in the figure above is not clear. We further try to get data from the TEJ advanced database, now we can find\uff1a<\/p>\n\n\n\n<p id=\"07c1\"><strong>\u2757\ufe0f\u2757\ufe0fthe start date of the free data is around 2016, but TEJ already has the data before 2004. \u2757\ufe0f\u2757\ufe0f<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"c9ae\"><strong>If you require data for a longer period, please<\/strong><a href=\"https:\/\/www.tej.com.tw\/contact\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\"><strong>&nbsp;<\/strong><\/a><strong><a href=\"https:\/\/www.tejwin.com\/contact\/\" target=\"_blank\" aria-label=\"contact us (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">contact us<\/a>.<\/strong><\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1dzEOy8q_rg8hUTKdEMuRBA.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">TEJ database<\/figcaption><\/figure>\n\n\n\n<p id=\"e105\">According to the\u00a0<a href=\"https:\/\/www.twse.com.tw\/zh\/index.html\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\"><strong>public information on Taiwan Securities Exchange\u2019s website<\/strong><\/a>,\u00a0<strong>the listing date of 0050 is 2003\/6\/30<\/strong>, so we can know the quality of data is important.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1qzwNKRJPNIMUJUNil1ygSw.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">0050 listing date<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"394b\"><span class=\"ez-toc-section\" id=\"4_View_the_return-2\"><\/span>4. View the return<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"464e\">The Return Formula\uff1a<br>The close price of the start date is our buy price(buy_price), the close price of the most recent date is our sell price(sell_price).<\/p>\n\n\n\n<p id=\"e311\">Return = (sell_price-buy_price)\/buy_price<\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1SZCWt7N1uEnV4vM1MIWGtA.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5b72\"><span class=\"ez-toc-section\" id=\"Quality_of_data\"><\/span>Quality of data<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Start date of the data<\/li>\n\n\n\n<li>Difference on the Adjusted Return<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"f140\"><strong>* Checking the data period of the component stocks of 0050<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p id=\"b51c\">&#8211;&nbsp;<strong>start_date_tej&nbsp;<\/strong>\uff1aThe start date of the TEJ data api.<br>&#8211;&nbsp;<strong>end_date_tej&nbsp;<\/strong>\uff1aThe most recent trading date of the TEJ data api.<\/p>\n\n\n\n<p id=\"80c8\">&#8211;&nbsp;<strong>start_date_yf&nbsp;<\/strong>\uff1aThe start date of the free data api.<br>&#8211;&nbsp;<strong>end_date_yf&nbsp;<\/strong>\uff1aThe most recent trading date of the free data api.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1RNrGg3vOCSCPcd54SU06Dw.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"e498\">According to the&nbsp;<a href=\"https:\/\/mops.twse.com.tw\/mops\/web\/t05st03\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>public information on Taiwan Securities Exchange\u2019s website<\/strong><\/a>, the listing date of \u53f0\u7063\u9ad8\u9435 &amp; \u6c38\u8c50\u91d1 is<strong>&nbsp;<\/strong>2016\/10\/27, 2002\/05\/09 respectively which is consistent with \u201cstart_date_tej\u201d, so we can say that&nbsp;<strong>TEJ Data API has a better quality.<\/strong>&nbsp;<strong>Choosing the qualified database won\u2019t let your model to buy the unlisted stock in order to provide an accurate result while backtesting.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1QeIOCNssxn61KoeDLJOyQA.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/117FCimXbUcYAayGZmDCoXg.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">2633(up) \/ 2890(down)<\/figcaption><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"bea5\"><strong>* Checking the difference on the adjusted return of component stocks of 0050<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p id=\"4495\">&#8211;&nbsp;<strong>ret_yf&nbsp;<\/strong>\uff1aThe return calculated by free data api.<br>&#8211;&nbsp;<strong>ret_tej<\/strong>\uff1aThe return calculated by TEJ data api.<\/p>\n\n\n\n<p id=\"9cfa\">Formulas\uff1a<\/p>\n\n\n\n<p id=\"a0f0\">&#8211;&nbsp;<strong>ret_yf&nbsp;<\/strong>= (the adjusted close of&nbsp;<strong>end_date_yf&nbsp;<\/strong>\u2014the adjusted close of&nbsp;<strong>start_date_yf&nbsp;<\/strong>)\/the adjusted close of&nbsp;<strong>start_date_yf<\/strong><\/p>\n\n\n\n<p id=\"1dab\">&#8211;&nbsp;<strong>ret_tej&nbsp;<\/strong>= (the adjusted close of&nbsp;<strong>end_date_tej&nbsp;<\/strong>\u2014 the adjusted close of&nbsp;<strong>start_date_tej<\/strong>)\/the adjusted close of&nbsp;<strong>start_date_tej<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"c2ef\"><strong>difference = abs\u3010 (ret_yf \u2014 ret_tej)\/ret_tej \u3011<\/strong><\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1_1aeYvT5WpbP4GJl2gTUkkOQ.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Take the top 10 rankings as an example<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7d45\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"9cf5\">What we share with you this time is the difference between adjusted &amp; non-adjusted stock prices, and we will provide a more comprehensive introduction in the future. Second, we compare the data quality between the TEJ API and the free data API.&nbsp;<strong>From the aspect of the data period and the adjusted return, free data is indeed unstable(the free one is the most expensive one\ud83d\ude02)<\/strong>.&nbsp;<strong>If the data quality is unstable may generate additional variables and increase the risk of the models\/ strategies, so we recommend you use a stable data source while backtesting.<\/strong><\/p>\n\n\n\n<p id=\"14cc\">Besides, if you have any question or interested in any topic, please leave the message below \u2757\ufe0f\u2757\ufe0f Then, we will&nbsp;<strong>go further into financial data analysis and applications in the next article<\/strong>, please look forward to it \u2757\ufe0f\u2757\ufe0f<\/p>\n\n\n\n<p id=\"2e61\">Finally, if you like this topic, please click \ud83d\udc4f below, giving us more support and encouragement. Additionally, if you have any questions or suggestions, please leave a message or email us, we will try our best to reply to you.\ud83d\udc4d\ud83d\udc4d<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"0fe2\"><span class=\"ez-toc-section\" id=\"Links_related_to_this_article_again\"><\/span>Links related to this article again!<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>1\ufe0f\u20e3 API Official Website:&nbsp;<a href=\"https:\/\/api.tej.com.tw\/\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>TEJ API Official Website<\/strong><\/a><\/li>\n\n\n\n<li>2\ufe0f\u20e3 The Product Package:<strong>&nbsp;<\/strong><a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_caseIntro\/1\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>TEJ E SHOP<\/strong><\/a><\/li>\n\n\n\n<li>3\ufe0f\u20e3 Source Code:&nbsp;<a href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_DataAnalysis\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>TEJ GITHUB<\/strong><\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>&#8211; Explaining the importance of data quality \u2014 Free data api versus TEJ API Highlights of this article Links related to this article Adjusted v.s non-adjusted stock price Using 0050 as an example: Assume that 0050 was priced at 30 dollars 10 years before, and the current price of 0050 is 120 dollars. Therefore, we [&hellip;]<\/p>\n","protected":false},"featured_media":6421,"template":"","tags":[2371,2634,2640,3007],"insight-category":[690,50],"class_list":["post-15484","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-python","tag-stock-price","tag-tej-api","tag-tejapi-data-analysis","insight-category-data-analysis","insight-category-fintech"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/15484","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"}],"version-history":[{"count":2,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/15484\/revisions"}],"predecessor-version":[{"id":24387,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/15484\/revisions\/24387"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/6421"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=15484"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=15484"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=15484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}