{"id":15617,"date":"2021-04-26T02:56:37","date_gmt":"2021-04-25T18:56:37","guid":{"rendered":"https:\/\/www.tejwin.com\/?post_type=insight&#038;p=15617"},"modified":"2023-08-04T09:54:20","modified_gmt":"2023-08-04T01:54:20","slug":"customize-your-own-financial-dashboard","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/customize-your-own-financial-dashboard\/","title":{"rendered":"Customize your own financial dashboard"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-225.png\" alt=\"\" class=\"wp-image-15618\" width=\"840\" height=\"560\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-225.png 720w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-225-300x200.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-225-150x100.png 150w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/figure>\n\n\n\n<p>Building the financial dashboard through python. ( the top 5 buy list of the foreign &amp; other investors, and combine the trading volume of foreign investors with the stock price.)<\/p>\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-69f34333dbbc3\" 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-69f34333dbbc3\"  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\/customize-your-own-financial-dashboard\/#Preface\" >Preface<\/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\/customize-your-own-financial-dashboard\/#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-3\" href=\"https:\/\/www.tejwin.com\/en\/insight\/customize-your-own-financial-dashboard\/#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-4\" href=\"https:\/\/www.tejwin.com\/en\/insight\/customize-your-own-financial-dashboard\/#Using_matplotlib_to_construct_a_dashboard\" >Using matplotlib to construct a dashboard<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.tejwin.com\/en\/insight\/customize-your-own-financial-dashboard\/#Import_packages\" >Import packages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.tejwin.com\/en\/insight\/customize-your-own-financial-dashboard\/#Data_extraction\" >Data extraction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.tejwin.com\/en\/insight\/customize-your-own-financial-dashboard\/#Data_summarize\" >Data summarize<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.tejwin.com\/en\/insight\/customize-your-own-financial-dashboard\/#start_to_build_our_dashboard\" >start to build our dashboard<\/a><\/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\/customize-your-own-financial-dashboard\/#Construct_dashboard\" >Construct dashboard<\/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\/customize-your-own-financial-dashboard\/#The_top_5_buy_sell_list_of_foreign_investors\" >The top 5 buy\/ sell list of foreign investors<\/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\/customize-your-own-financial-dashboard\/#trading_volumes_stock_price\" >trading volumes\/ stock price<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.tejwin.com\/en\/insight\/customize-your-own-financial-dashboard\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.tejwin.com\/en\/insight\/customize-your-own-financial-dashboard\/#Links_related_to_this_article_again\" >Links related to this article again!<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"f398\"><span class=\"ez-toc-section\" id=\"Preface\"><\/span><strong>Preface<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"85b5\">We have introduced some functions of the most-used python packages such as matplotlib, numpy, and pandas in previous articles.&nbsp;<strong>In this episode, we will further introduce the application of those packages.<\/strong><\/p>\n\n\n\n<p id=\"ef62\">As an investor, it\u2019s your daily routine to spend time watching some statistical data or summary reports of the market after the market is closed. Therefore, each time before you start to observe these data, you will have to go to the TWSE\u2019s website to download the most recent data, then open it on excel to plot and summarize. This kind of work sometimes annoys people because you do the same thing every day. To be honest, it\u2019s totally a waste of time.&nbsp;<strong>Compared to execute the same action daily by ourselves, using python seems much more attractive and efficient.<\/strong><\/p>\n\n\n\n<p id=\"383e\">The purpose of this article is to share how we process data, make a plot, and customize your financial dashboard through python\ud83c\udfc4\ud83c\udfc4~<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a0cd\"><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>\ud83c\udf1f Matplotlib \/construct dashboard<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2724\"><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:&nbsp;<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=\"2d34\"><span class=\"ez-toc-section\" id=\"Using_matplotlib_to_construct_a_dashboard\"><\/span><strong>Using matplotlib to construct a dashboard <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3411\"><span class=\"ez-toc-section\" id=\"Import_packages\"><\/span>Import packages<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import tejapi\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport datetime\ntejapi.ApiConfig.api_key = \u2018your key\u2019<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4066\"><span class=\"ez-toc-section\" id=\"Data_extraction\"><\/span>Data extraction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The stock code of the listed company \u27a1\ufe0f&nbsp;<a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_caseIntro\/1\" rel=\"noreferrer noopener\" target=\"_blank\">TEJ E SHOP \u5c0f\u8cc7\u65b9\u6848<\/a>&nbsp;\u8b49\u5238\u5c6c\u6027\u8868(TWN\/EWNPRCSTD)<\/li>\n\n\n\n<li>Stock price\u27a1\ufe0f&nbsp;<a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_caseIntro\/1\" rel=\"noreferrer noopener\" target=\"_blank\">TEJ E SHOP \u5c0f\u8cc7\u65b9\u6848<\/a>&nbsp;\u8b49\u5238\u4ea4\u6613\u8cc7\u6599\u8868(TWN\/EWPRCD)<\/li>\n\n\n\n<li>Foreign &amp; other investors daily trading summary \u27a1\ufe0f&nbsp;<a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_caseIntro\/3\" rel=\"noreferrer noopener\" target=\"_blank\">TEJ E SHOP \u9054\u4eba\u65b9\u6848<\/a>&nbsp;\u4e09\u5927\u6cd5\u4eba\u8cc7\u6599(TWN\/EWTINST1)<\/li>\n<\/ul>\n\n\n\n<p id=\"46d3\"><strong>1\ufe0f\u20e3 Get the stock code of the listed company<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6488\u53d6\u4e0a\u5e02\u6240\u6709\u666e\u901a\u80a1\u8b49\u5238\u4ee3\u78bc\nstk = tejapi.get('TWN\/EWNPRCSTD'\n                  ,paginate = True\n                  ,chinese_column_name = True)code = stk&#91;'\u8b49\u5238\u78bc']&#91;(stk&#91;'\u8b49\u5238\u7a2e\u985e\u540d\u7a31']=='\u666e\u901a\u80a1')&amp;(stk&#91;'\u4e0a\u5e02\u5225']=='TSE')].to_list()\ncode<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1_1cY9QsWPDOXhV30Av4VdbbQ.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">the stock code of the listed company<\/figcaption><\/figure>\n\n\n\n<p id=\"7edd\"><strong>2\ufe0f\u20e3 Get foreign &amp; other investors daily trading summary<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6488\u53d6\u6cd5\u4eba\u8cb7\u8ce3\u8d85(\u65e5)\nbuyover = tejapi.get('TWN\/EWTINST1'\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000,coid=code\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000,mdate = {'gte':'2021-01-01'}\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000,paginate = True\n\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000,chinese_column_name = True)\n# \u4fee\u6539\u65e5\u671f\u683c\u5f0f\nbuyover&#91;'\u65e5\u671f'] = buyover&#91;'\u65e5\u671f'].apply(lambda x: pd.to_datetime(x).date())\nbuyover&#91;'\u65e5\u671f'] = buyover&#91;'\u65e5\u671f'].astype('datetime64')\nbuyover&#91;buyover&#91;'\u65e5\u671f']&gt;='2021-03-20']<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter caption-align-default\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1_1u7n7wDnP-j5Rfw16LOrtQg.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">foreign &amp; other investors daily trading summary<\/figcaption><\/figure>\n\n\n\n<p id=\"b7f4\"><strong>3\ufe0f\u20e3 Get stock data<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u6488\u53d6\u80a1\u50f9\u8cc7\u6599\nstock_price =  tejapi.get('TWN\/EWPRCD',\n                          coid = code,\n                          mdate={'gte':'2021-03-20'},\n                          opts={'columns':&#91;'coid','mdate','open_d', 'high_d','low_d','close_d','volume']}\n                          ,paginate = True,chinese_column_name = True)\n# \u8abf\u6574\u65e5\u671f\u683c\u5f0f\nstock_price&#91;'\u65e5\u671f'] = stock_price&#91;'\u65e5\u671f'].apply(lambda x: pd.to_datetime(x).date())\nstock_price&#91;'\u65e5\u671f'] = stock_price&#91;'\u65e5\u671f'].astype('datetime64')\nstock_price<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1hdGjM235Y-L4LNf6WEzJpg.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">stock data<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8549\"><span class=\"ez-toc-section\" id=\"Data_summarize\"><\/span>Data summarize<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"3509\"><strong>Calculating the monthly trading volume and sorting the trading volume of foreign investors, investment trust, and proprietary respectively.<\/strong><\/p>\n\n\n\n<p id=\"7039\">1\ufe0f\u20e3&nbsp;<strong>The top 10 buy list in foreign investors&nbsp;<\/strong>are 6116, 2891, 2344, 2352, 2363, 2882, 3711, 2449, 2881, 1303. Most of them are from&nbsp;<strong>financial, display, and semiconductor-related industry.<\/strong><\/p>\n\n\n\n<p id=\"3ef5\">2\ufe0f\u20e3&nbsp;<strong>The top 10 buy lists in investment trusts<\/strong>&nbsp;are 3481, 2409, 2002, 2610, 2303, 2603, 2344, 1440, 6116, 2606. The investing style of investment trusts is different from<strong>&nbsp;<\/strong>foreign investors. Besides the&nbsp;<strong>display<\/strong>&nbsp;and&nbsp;<strong>memory industry<\/strong>,&nbsp;<strong>the<\/strong>&nbsp;<strong>traditional industry(shipping, iron &amp; textile)accounts for the most<\/strong>.<\/p>\n\n\n\n<p id=\"70da\">3\ufe0f\u20e3<strong>&nbsp;The top 10 buy list in proprietaries<\/strong>&nbsp;are 2002, 2303, 2888, 1314, 2409, 1101, 6116, 3481, 2027, 2883. Their attitude of investing is similar to investment trusts.<strong>&nbsp;Their capitals distribute on the display, traditional, and financial industry at the same time.<\/strong><\/p>\n\n\n\n<p id=\"fa67\">According to the data,&nbsp;<strong>the intersection among the three is the display industry.<\/strong>&nbsp;The domestic investors have the same view based on the trading volumes, and both of them put quite a large percentage of their capital in the traditional industry. However, foreign investors distribute more in the financial and tech sectors.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sorted_fi = buyover&#91;buyover&#91;'\u65e5\u671f']&gt;'2021-03-20'].groupby(by='\u8b49\u5238\u78bc').sum().sort_values(by='\u5916\u8cc7\u8cb7\u8ce3\u8d85(\u5343\u80a1)',ascending = False)\nsorted_fi&#91;:10]\nsorted_it = buyover&#91;buyover&#91;'\u65e5\u671f']&gt;'2021-03-20'].groupby(by='\u8b49\u5238\u78bc').sum().sort_values(by='\u6295\u4fe1\u8cb7\u8ce3\u8d85(\u5343\u80a1)',ascending = False)\nsorted_it&#91;:10]\nsorted_pro = buyover&#91;buyover&#91;'\u65e5\u671f']&gt;'2021-03-20'].groupby(by='\u8b49\u5238\u78bc').sum().sort_values(by='\u81ea\u71df\u8cb7\u8ce3\u8d85(\u5343\u80a1)',ascending = False)\nsorted_pro&#91;:10]<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1RBzkMyz-VVG-9TRjibkIXw.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1ccj-DjA8_1WGpVxIoYR3kw.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1h2wZp9JCtbP0wc4GlSlLNQ.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">The top 10 buy list in investment trusts \/ The top 10 buy list in investment trusts \/ The top 10 buy list in proprietaries<\/figcaption><\/figure>\n\n\n\n<p id=\"0e11\"><strong>Filter\uff1aAll of the monthly trading volume of foreign &amp; other investors are positive.<\/strong><\/p>\n\n\n\n<p id=\"5db4\">After filtering, we also sort the monthly trading volume of foreign investors, investment trusts, and proprietary respectively.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sorted_fi&#91;(sorted_fi&#91;'\u5916\u8cc7\u8cb7\u8ce3\u8d85(\u5343\u80a1)']&gt;0)&amp;(sorted_fi&#91;'\u6295\u4fe1\u8cb7\u8ce3\u8d85(\u5343\u80a1)']&gt;0)&amp;(sorted_fi&#91;'\u81ea\u71df\u8cb7\u8ce3\u8d85(\u5343\u80a1)']&gt;0)]&#91;:10]\nsorted_it&#91;(sorted_it&#91;'\u5916\u8cc7\u8cb7\u8ce3\u8d85(\u5343\u80a1)']&gt;0)&amp;(sorted_it&#91;'\u6295\u4fe1\u8cb7\u8ce3\u8d85(\u5343\u80a1)']&gt;0)&amp;(sorted_it&#91;'\u81ea\u71df\u8cb7\u8ce3\u8d85(\u5343\u80a1)']&gt;0)]&#91;:10]\nsorted_pro&#91;(sorted_pro&#91;'\u5916\u8cc7\u8cb7\u8ce3\u8d85(\u5343\u80a1)']&gt;0)&amp;(sorted_pro&#91;'\u6295\u4fe1\u8cb7\u8ce3\u8d85(\u5343\u80a1)']&gt;0)&amp;(sorted_pro&#91;'\u81ea\u71df\u8cb7\u8ce3\u8d85(\u5343\u80a1)']&gt;0)]&#91;:10]<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1poWNcLG3AfB42idjLzZxsg.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1OIqxOgWbpMpUiUwz7NW30Q.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1loBUWEI1LjJIE9E61ptp9g.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">The top 10 buy list in investment trusts \/ The top 10 buy list in investment trusts \/ The top 10 buy list in proprietaries<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"d760\"><span class=\"ez-toc-section\" id=\"start_to_build_our_dashboard\"><\/span>start to build our dashboard<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1bqqqmKJISYMibgN1hMBE2Q.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"082e\"><span class=\"ez-toc-section\" id=\"Construct_dashboard\"><\/span>Construct dashboard<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"c914\"><span class=\"ez-toc-section\" id=\"The_top_5_buy_sell_list_of_foreign_investors\"><\/span>The top 5 buy\/ sell list of foreign investors<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>5-days the top 5 buy\/ sell list of foreign investors.<\/li>\n\n\n\n<li>20-days the top 5 buy\/ sell list of foreign investors.<\/li>\n\n\n\n<li>60-days the top 5 buy\/ sell list of foreign investors.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"260b\"><strong>buy_table :&nbsp;<\/strong>The data frame for storing top 5 buy list at different periods.<br><strong>sell_table :&nbsp;<\/strong>The data frame for storing top 5 sell list at different periods.<br><strong>xx :<\/strong>&nbsp;Calculate the monthly trading volume of the stocks under 5, 20, 60-days.<br><strong>x.insert() :&nbsp;<\/strong>Insert the column which is named according to its stock code, and the value is xx.<br><strong>x :<\/strong>&nbsp;The data frame for storing the monthly trading volume of the multi-stocks under the same period.<br><strong>x.loc[len(x)-1]&nbsp;<\/strong>: Call the most recent data of x.<br><strong>sort_values(ascending=False)[:5]\uff1a&nbsp;<\/strong>Sorting data and choose the top 5<br><strong>reset_index(drop=True) :<\/strong>&nbsp;Reset the index of data frame.<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>buy_table = pd.DataFrame()\nsell_table = pd.DataFrame()\nfor i in &#91;5,20,60]:\n    x = pd.DataFrame()\n    for stock in code:\n        # i\u65e5\u7d2f\u7a4d\u8cb7\u8ce3\u8d85\n        xx = buyover&#91;'\u5916\u8cc7\u8cb7\u8ce3\u8d85(\u5343\u80a1)']&#91;buyover&#91;'\u8b49\u5238\u78bc']==stock].rolling(i).sum().reset_index(drop=True)\n        x.insert(loc=0,column=stock,value=xx)\n    # \u8cb7\u8d85\u6392\u540d\u524d5\n    buy_table&#91;str(i)+'\u65e5\u7d2f\u7a4d\u5916\u8cc7\u8cb7\u8d85(\u5343\u80a1)'] = x.loc&#91;len(x)-1].sort_values(ascending=False)&#91;:5].reset_index(drop=True)\n    buy_table&#91;str(i)+'\u65e5\u6392\u540d(\u80a1\u7968)'] = x.loc&#91;len(x)-1].sort_values(ascending=False)&#91;:5].index\n    # \u8cb7\u8d85\u6392\u540d\u524d5\n    sell_table&#91;str(i)+'\u65e5\u7d2f\u7a4d\u5916\u8cc7\u8ce3\u8d85(\u5343\u80a1)'] = x.loc&#91;len(x)-1].sort_values(ascending=True)&#91;:5].reset_index(drop=True)\n    sell_table&#91;str(i)+'\u65e5\u6392\u540d(\u80a1\u7968)'] = x.loc&#91;len(x)-1].sort_values(ascending=True)&#91;:5].index\nbuy_table\nsell_table<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1AS2jXt9bF4jLGJMFTLToog.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1GP16OjF8k4Jdqz9jflKI4Q.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">top five buy\/ sell list on 4\/19<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"8734\"><span class=\"ez-toc-section\" id=\"trading_volumes_stock_price\"><\/span>trading volumes\/ stock price<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=\"62da\">plt.style.use : Set the style of plot.<br>plt.rcParams[\u2018font.sans-serif\u2019]=[\u2018Microsoft YaHei\u2019] : Set the font. There is no Chinese font in the python internals. You need to import additional fonts to display Chinese.<br>stock = input() : Input the stock code.<br>FI1.twinx() : Share the x-axis of FI1.<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code># \u8abf\u6574\u756b\u5716\u6a21\u7d44\nplt.style.use('seaborn-darkgrid')\n# \u8abf\u6574\u5b57\u9ad4\nplt.rcParams&#91;'font.sans-serif']=&#91;'Microsoft YaHei']\n# \u53ef\u81ea\u884c\u8f38\u5165\u80a1\u7968\u4ee3\u865f\nstock =input()\ntitle = stock+' '+stk&#91;'\u8b49\u5238\u540d\u7a31']&#91;stk&#91;'\u8b49\u5238\u78bc']==stock].to_list()&#91;0]\nfig, FI1 = plt.subplots(figsize=(10,5))\nplt.title(title,{'fontsize' : 20})\nplt.xlabel('Date', fontsize=14)\nprice = FI1.twinx()\n# \u8a2d\u5b9a\u8cb7\u8ce3\u8d85\u91d1\u984d\nFI1.set_ylabel('\u5916\u8cc7\u8cb7\u8ce3\u8d85(\u5343\u80a1)',color='tab:blue', fontsize=14)\nFI1.bar(x=buyover&#91;'\u65e5\u671f']&#91;buyover&#91;'\u8b49\u5238\u78bc']==stock]\n        ,height=buyover&#91;'\u5916\u8cc7\u8cb7\u8ce3\u8d85(\u5343\u80a1)']&#91;buyover&#91;'\u8b49\u5238\u78bc']==stock]\n        ,width = 0.8)\nFI1.tick_params(axis='y',labelcolor = 'tab:blue')\n# \u8a2d\u5b9a\u6536\u76e4\u50f9\nprice.set_ylabel('\u6536\u76e4\u50f9(\u5143)'\n                 ,color='black'\n                 ,fontsize=14)\nprice.plot(stock_price&#91;'\u65e5\u671f']&#91;stock_price&#91;'\u8b49\u5238\u78bc']==stock]\n           ,stock_price&#91;'\u6536\u76e4\u50f9']&#91;stock_price&#91;'\u8b49\u5238\u78bc']==stock]\n           ,color='orange'\n           ,alpha=3)\n#plt.xticks(rotation=45)\nprice.tick_params(axis='y',labelcolor = 'black')\n# \u53d6\u6d88 price\u7684 grid\nprice.grid(False)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1Wxz7u0dLHpn46My7k4TqoA.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1Xh1UXcaQ6NHawVooM586iQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1oxvG39VzgHY0u3fof1YWTw.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1zWbsUbJSJt6J8pqmAcNcHQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1i__UZLNPSnnqK-hiZshNKQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"dec3\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"cc58\">There are hundreds of ways to make charts and plots. We introduced how to implement the charts we often see through python. After all, one of the great benefits of learning python is that it can reduce tedious routines.&nbsp;<strong>If you like the topic such as integrating charts, you can leave a message below to tell us. In the future, we will continue to share the application of python in the investment field, please wait and see \u2757\ufe0f\u2757\ufe0f<\/strong><\/p>\n\n\n\n<p id=\"292f\">In addition, you can also explore more functions through the official website of these packages~<\/p>\n\n\n\n<p id=\"f613\">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=\"d28a\"><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><strong>1\ufe0f\u20e3 API Official Website:&nbsp;<\/strong><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><strong>2\ufe0f\u20e3 The Product Package:&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><strong>3\ufe0f\u20e3 Source Code:&nbsp;<\/strong><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>Building the financial dashboard through python. ( the top 5 buy list of the foreign &amp; other investors, and combine the trading volume of foreign investors with the stock price.) Preface We have introduced some functions of the most-used python packages such as matplotlib, numpy, and pandas in previous articles.&nbsp;In this episode, we will further [&hellip;]<\/p>\n","protected":false},"featured_media":6449,"template":"","tags":[2572,2371,3007],"insight-category":[690,50],"class_list":["post-15617","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-data-analysis","tag-python","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\/15617","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":0,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/15617\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/6449"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=15617"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=15617"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=15617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}