{"id":15971,"date":"2021-06-08T03:17:43","date_gmt":"2021-06-07T19:17:43","guid":{"rendered":"https:\/\/www.tejwin.com\/?post_type=insight&#038;p=15971"},"modified":"2023-08-10T10:03:58","modified_gmt":"2023-08-10T02:03:58","slug":"roger-e-king-s-investing-strategy","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/roger-e-king-s-investing-strategy\/","title":{"rendered":"Roger E. King\u2019 s investing strategy"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\/image-243-1024x768.png\" alt=\"\" class=\"wp-image-15972\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-243-1024x768.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-243-300x225.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-243-150x113.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-243-768x576.png 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-243.png 1400w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Fulfill Roger E. King\u2019 s investing strategy through python.<\/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-69f33f7dca089\" 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-69f33f7dca089\"  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\/roger-e-king-s-investing-strategy\/#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\/roger-e-king-s-investing-strategy\/#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\/roger-e-king-s-investing-strategy\/#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\/roger-e-king-s-investing-strategy\/#Roger_King_s_investing_strategy\" >Roger King\u2019 s investing strategy<\/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\/roger-e-king-s-investing-strategy\/#Adjusted_Strategy\" >Adjusted Strategy<\/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\/roger-e-king-s-investing-strategy\/#Python_code\" >Python code<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.tejwin.com\/en\/insight\/roger-e-king-s-investing-strategy\/#Data_collectionData_preprocessing\" >Data collection\/Data preprocessing<\/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\/roger-e-king-s-investing-strategy\/#Stock_selection\" >Stock selection<\/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\/roger-e-king-s-investing-strategy\/#Backtest\" >Backtest<\/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\/roger-e-king-s-investing-strategy\/#Cumulative_return\" >Cumulative return<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.tejwin.com\/en\/insight\/roger-e-king-s-investing-strategy\/#Performance_visualization\" >Performance visualization<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.tejwin.com\/en\/insight\/roger-e-king-s-investing-strategy\/#Plot_cumulative_return\" >Plot cumulative return<\/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\/roger-e-king-s-investing-strategy\/#Performance_indicator_report\" >Performance indicator\/ report<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.tejwin.com\/en\/insight\/roger-e-king-s-investing-strategy\/#The_latest_portfolio\" >The latest portfolio<\/a><\/li><\/ul><\/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\/roger-e-king-s-investing-strategy\/#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\/roger-e-king-s-investing-strategy\/#Links_related_to_this_article_again\" >Links related to this article again!<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"5e5a\"><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=\"fad6\">Roger E. King is a well-known value fund manager in the United States. He used to be the senior vice president and chief investment officer of Sun Insurance Services and senior vice president of GULFCO Investment Management. He founded King Investment Advisors Inc. in 1981. By 2001, he had an investment experience of 30 years.<\/p>\n\n\n\n<p id=\"4b91\">Originally, King Investment Consultants only managed institutional investors\u2019 funds and individual retirement funds. At the end of 1996, it issued the first stock mutual fund-Fountainhead Special Value Fund. It was a blockbuster in 1997 and received 36.65% of investment returns.<strong>&nbsp;In 1999, the return on investment reached 133.44%. Although the stock market performed poorly in 2000, the fund performance only lost 15.71%.<\/strong>&nbsp;As of May 2001, the 3-year average return rate reached 18.22%, surpassing the performance of the S&amp;P 500 index by 12.92% over the same period. As a result, it has received a 5-star rating from the Morning star Co. Fund, and its investment performance is very good.<\/p>\n\n\n\n<p id=\"49ba\">He developed a stock selection strategy called \u201cBusiness Valuation Approach\u201d by himself, which is based on the bottom-up stock selection method, which is divided into three valuation methods:<\/p>\n\n\n\n<p id=\"38d0\"><strong>(1) Private-market Valuation, Liquidation or acquired in a cash transaction\uff1b<br>(2) Historical Valuation\uff1b<\/strong><br><strong>(3) Superior Earning Growth, Buy growth at a reduced price: GARP<\/strong><\/p>\n\n\n\n<p id=\"9bd2\">The companies selected by the three methods can all be investment targets, which are then screened based on indicators such as financial strength and insider entry and exit; although Roger King is positioned as a value investor by the market, he emphasized that buying has investment value. In an interview with the media, he once said, \u201cThe secret of success is to buy at an inexpensive price (The secret of success is to buy at an inexpensive price). This time I introduce the second stock selection method \u201cHistory Evaluation\u201d.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e519\"><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>Master strategy\/ adjusted strategy intro<\/li>\n\n\n\n<li>Adjusted strategy construct &amp; performance display<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fac0\"><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><strong>API Official Website:\u00a0<\/strong><a href=\"https:\/\/api.tej.com.tw\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>TEJ API Official Website<\/strong><\/a><\/li>\n\n\n\n<li><strong>The Product Package:\u00a0<\/strong><a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_caseIntro\/1\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>TEJ E-SHOP<\/strong><\/a><\/li>\n\n\n\n<li><strong>Source Code:\u00a0<\/strong><a href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Application\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>TEJ GITHUB<\/strong><\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"58fa\"><span class=\"ez-toc-section\" id=\"Roger_King_s_investing_strategy\"><\/span><strong>Roger King\u2019 s investing strategy<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"d689\">All the indicators below were calculated by 7-year historical data to determine the potential upside return and potential downside risk.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"627f\"><strong>Average of highest and lowest PE ratio per 7 years.<\/strong><\/p>\n\n\n\n<p id=\"9465\"><strong>Average of highest and lowest PB ratio per 7 years.<\/strong><\/p>\n\n\n\n<p id=\"d985\"><strong>Average of highest and lowest PCF ratio per 7 years.<\/strong><\/p>\n\n\n\n<p id=\"c14c\"><strong>Average of highest and lowest PS ratio per 7 years.<\/strong><\/p>\n\n\n\n<p id=\"d54f\"><strong>Solid financial condition.<\/strong><\/p>\n\n\n\n<p id=\"dbf8\"><strong>Shareholder of internal staff .<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p id=\"5466\">To calculate the average highest and lowest PE, PB, PCF, and PS ratio, we will have to find the highest and lowest point each year, then take an average of them. To determine whether to buy the stocks, we estimate the potential upside and downside through the indicators.<\/p>\n\n\n\n<p id=\"656e\">For the change in time and location, we made an adjustment to the above conditions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7170\"><span class=\"ez-toc-section\" id=\"Adjusted_Strategy\"><\/span><strong>Adjusted Strategy<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"794b\"><strong>PE ratio upside target price = 7-year average of highest PE ratio * recent EPS<\/strong><\/p>\n\n\n\n<p id=\"6d85\"><strong>PE ratio downside target price = 7-year average of lowest PE ratio * recent EPS<\/strong><\/p>\n\n\n\n<p id=\"4e2d\"><strong>PB ratio upside target price = 7-year average of highest PB ratio * recent book value<\/strong><\/p>\n\n\n\n<p id=\"ee83\"><strong>PB ratio downside target price = 7-year average of lowest PB ratio * recent book value<\/strong><\/p>\n\n\n\n<p id=\"eafd\"><strong>PCF ratio upside target price = 7-year average of highest PCF ratio * recent cash flow<\/strong><\/p>\n\n\n\n<p id=\"8174\"><strong>PCF ratio downside target price = 7-year average of lowest PE ratio * recent cash flow<\/strong><\/p>\n\n\n\n<p id=\"d8ee\"><strong>PS ratio upside target price = 7-year average of highest PS ratio * recent sales revenue<\/strong><\/p>\n\n\n\n<p id=\"23b9\"><strong>PS ratio downside target price = 7-year average of lowest PS ratio * recent sales revenue<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p id=\"4f9a\"><strong>Standards of stock selection\uff1a<\/strong><\/p>\n\n\n\n<p id=\"899d\">The standards below shows the distance between stock price and downside target price,&nbsp;<strong>the closer means the stock is under value and have a greater potential return.<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"a8dd\"><strong>PE return\/risk ratio = [(PE ratio upside target price- recent stock price)\/(recent stock price &#8211; PE ratio downside target price)]&gt;1<\/strong><\/p>\n\n\n\n<p id=\"b15d\"><strong>PB return\/risk ratio = [(PB ratio upside target price- recent stock price)\/(recent stock price &#8211; PB ratio downside target price)]&gt;1<\/strong><\/p>\n\n\n\n<p id=\"c8c2\"><strong>PCF return\/risk ratio = [(PCF ratio upside target price- recent stock price)\/(recent stock price &#8211; PCF ratio downside target price)]&gt;1<\/strong><\/p>\n\n\n\n<p id=\"6561\"><strong>PS return\/risk ratio = [(PS ratio upside target price- recent stock price)\/(recent stock price &#8211; PS ratio downside target price)]&gt;1<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p id=\"2800\">If one of the above 4 indicators is met, it is the stock selection target. Additional filter by the following conditions:<\/p>\n\n\n\n<p id=\"71d6\"><strong>kick off the stock with debt to asset ratio in most recent quarter &gt; 65%.<\/strong><\/p>\n\n\n\n<p id=\"58d1\">Roger King\u2019s&nbsp;<strong>return\/risk ratio measured the distance among the recent stock price, upside target price, and downside target price.<\/strong>&nbsp;If the stock price is closer to the downside target price than the upside target price, it means the stock is cheap now, vice versa.&nbsp;<strong>According to the aim of value investment, we will buy the undervalued one.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ec5e\"><span class=\"ez-toc-section\" id=\"Python_code\"><\/span><strong>Python code<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Data collection\/Data preprocessing<\/li>\n\n\n\n<li>Stock selection<\/li>\n\n\n\n<li>Backtest<\/li>\n\n\n\n<li>Performance visualization<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"7941\"><span class=\"ez-toc-section\" id=\"Data_collectionData_preprocessing\"><\/span><strong>Data collection\/Data preprocessing<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"bb1c\"><strong>Import packages<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nplt.style.use('seaborn')\nimport tejapi\ntejapi.ApiConfig.api_key = 'your_key'\ntejapi.ApiConfig.ignoretz = True<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"21e1\"><strong>Getting financial data<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Getting all security codes from TWN\/ANPRCSTD table, and filtering \u201cListed\u201d and \u201ccommon\u201d ones.<\/li>\n\n\n\n<li>Getting financial data: book value per share, earning per share, debt ratio, cash flow per share, sales revenue per share from TWN\/AIM1A table.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># \u7372\u53d6\u4e0a\u5e02\u666e\u901a\u80a1\u4ee3\u78bc #\nstk_info = tejapi.get('TWN\/ANPRCSTD',\n           paginate=True,\n           chinese_column_name=True\n          )\nstk_nums = stk_info&#91;(stk_info&#91;'\u4e0a\u5e02\u5225']=='TSE') &amp; (stk_info&#91;'\u8b49\u5238\u7a2e\u985e\u540d\u7a31']=='\u666e\u901a\u80a1')]&#91;'\u8b49\u5238\u78bc'].to_list()\n# \u6488\u53d6\u8ca1\u52d9\u8cc7\u6599 #\nzz = pd.DataFrame()\nfor code in stk_nums:\n    zz = zz.append(\n         tejapi.get('TWN\/AIM1A',\n                   coid=code,\n                   paginate=True,\n                   chinese_column_name=True,\n                   opts= {'pivot':True,'columns':&#91;'coid','mdate','200D','R535','R505','R303','R304','MV']}).reset_index(drop=True)\n    ).reset_index(drop=True)\n    print(code)<\/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\/04xmqyFO2plTBRsse.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Data Display<\/figcaption><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p id=\"2cdb\"><strong><em>Tips :<\/em><\/strong><em>&nbsp;<\/em>The way to find the codes of the wanted column. Just enter the keyword and run the code below, tejapi will help to search for you.<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code># IFRS\u8ca1\u52d9\u6703\u8a08\u79d1\u76ee\u8aaa\u660e\u6a94 #\nacc = tejapi.get(\u2018TWN\/AIACC\u2019,paginate=True) \n# \u641c\u5c0b\u6b04\u4f4d\u4ee3\u78bc #\nkey_word = '\u8f38\u5165\u95dc\u9375\u5b57'\nacc&#91;acc&#91;\u2018cname\u2019].str.find(key_word)!=-1]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"57b6\"><strong>Data preprocessing<\/strong><\/h4>\n\n\n\n<p id=\"a795\">For example, when calculating PE, PB, PCF, and PS at the end of 2010\u201312\u201331, we use the stock price from 2010\u20133\u201331 to 2011\u20133\u201331.<\/p>\n\n\n\n<p id=\"3620\">PS. The run time is about 40 minutes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>results = pd.DataFrame()\n#coid = str(1101)\nfor coid in data&#91;'\u516c\u53f8\u4ee3\u78bc'].unique():\n    stock = tejapi.get('TWN\/APRCD1',coid = coid, chinese_column_name = True)\n    for year in data&#91;'year'].unique():\n        condition = (data&#91;'year']==year) &amp; (data&#91;'\u516c\u53f8\u4ee3\u78bc']== coid)\n        if (data&#91;condition].size !=0):\n            indicator_start = data&#91;'indicator_start']&#91;condition].to_list()&#91;0]\n            stk_start = data&#91;'start']&#91;condition].to_list()&#91;0]\n            stk_end = data&#91;'end']&#91;condition].to_list()&#91;0]\n            # \u6293\u53d6\u8ca1\u5831\u5b63\u5ea6\u524d\u4e00\u5e74\u7684\u8cc7\u6599 #\n            selected = stock&#91;(stock&#91;'\u5e74\u6708\u65e5'] &gt; indicator_start) &amp; (stock&#91;'\u5e74\u6708\u65e5'] &lt; stk_start)].reset_index(drop=True)\n            back_test = stock&#91;(stock&#91;'\u5e74\u6708\u65e5'] &gt;= stk_start) &amp; (stock&#91;'\u5e74\u6708\u65e5'] &lt; stk_end)].reset_index(drop=True)\n            if (selected.size!=0) and (back_test.size!=0):\n                # \u8a08\u7b97\u500b\u5e74\u5ea6\u6700\u9ad8\u8207\u6700\u4f4e \u672c\u76ca\u6bd4\u3001\u80a1\u50f9\u6de8\u503c\u6bd4\u3001\u80a1\u50f9\u73fe\u91d1\u6d41\u91cf\u6bd4\u548c\u80a1\u50f9\u71df\u6536\u6bd4 #\n                price = selected&#91;'\u6536\u76e4\u50f9(\u5143)'].tail(1).to_list()&#91;0]\n                stk_start_price = back_test&#91;'\u6536\u76e4\u50f9(\u5143)'].head(1).to_list()&#91;0]\n                ## \u672c\u76ca\u6bd4 ##\n                EPS = data&#91;'\u5e38\u7e8c\u6027EPS']&#91;condition].to_list()&#91;0]\n                PE = selected&#91;'\u6536\u76e4\u50f9(\u5143)']\/EPS\n                PE_max = PE.max()\n                PE_min = PE.min()\n                ## \u80a1\u50f9\u6de8\u503c\u6bd4 ##\n                BV = data&#91;'\u6bcf\u80a1\u6de8\u503c(F)\uff0dTSE\u516c\u544a\u6578']&#91;condition].to_list()&#91;0]\n                PB = selected&#91;'\u6536\u76e4\u50f9(\u5143)']\/BV\n                PB_max = PB.max()\n                PB_min = PB.min()\n                ## \u80a1\u50f9\u73fe\u91d1\u6d41\u91cf\u6bd4 ##\n                CFP = data&#91;'\u6bcf\u80a1\u73fe\u91d1\u6d41\u91cf']&#91;condition].to_list()&#91;0]\n                PC = selected&#91;'\u6536\u76e4\u50f9(\u5143)']\/CFP\n                PC_max = PC.max()\n                PC_min = PC.min()\n                ## \u80a1\u50f9\u71df\u6536\u6bd4 ##\n                SP = data&#91;'\u6bcf\u80a1\u71df\u696d\u984d']&#91;condition].to_list()&#91;0]\n                PS = selected&#91;'\u6536\u76e4\u50f9(\u5143)']\/SP\n                PS_max = PS.max()\n                PS_min = PS.min()\n                # \u5f59\u6574 # \n                result = pd.DataFrame({\n                    'year':year,\n                    '\u516c\u53f8\u4ee3\u78bc':coid,\n                    'stk_start':stk_start,\n                    'stk_end':stk_end,\n                    'stk_start_price':stk_start_price,\n                    'PE_max':PE_max,'PE_min':PE_min,\n                    'PB_max':PB_max,'PB_min':PB_min,\n                    'PC_max':PC_max,'PC_min':PC_min,\n                    'PS_max':PS_max,'PS_min':PS_min\n                },index=&#91;0])\n                results = results.append(result).reset_index(drop=True)\n    print(coid)<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"896b\"><strong>Rolling mean<\/strong><\/h4>\n\n\n\n<p id=\"3154\">Using the result of maximum and minimum of PE, PB, PCF, and PS each year to compute the 7-year rolling mean. Also, combine the the most recent EPS, book value, cash flow, and sales revenue. Finally, we will get the&nbsp;<strong>upside target price, downside target price, and return risk ratio.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mean_7 = results.groupby(by=&#91;'\u516c\u53f8\u4ee3\u78bc']).rolling(7).mean()&#91;&#91;'PE_max','PE_min','PB_max','PB_min','PC_max','PC_min','PS_max','PS_min']]\nmean_7 = mean_7.reset_index(drop=True)\nmean_7&#91;'year'],mean_7&#91;'\u516c\u53f8\u4ee3\u78bc'],mean_7&#91;'stk_start_price'] = results&#91;'year'], results&#91;'\u516c\u53f8\u4ee3\u78bc'],results&#91;'stk_start_price']\n# \u5408\u4f75 #\nmean_7 = pd.merge(mean_7.dropna(),data,on=&#91;'\u516c\u53f8\u4ee3\u78bc','year'])\n# \u53bb\u9664\u5e02\u503c\u5c0f\u65bc\u4e2d\u4f4d\u6578\u8005 #\nmean_7 = mean_7&#91;(mean_7&#91;'\u5b63\u5e95\u666e\u901a\u80a1\u5e02\u503c']&gt;mean_7&#91;'mv_median'])].reset_index(drop=True)<\/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\/17LNnvUz03W8CSVYI5pTEzg.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Data Display<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4bd4\"><span class=\"ez-toc-section\" id=\"Stock_selection\"><\/span>Stock selection<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=\"301d\"><strong>PE return\/risk ratio = [(PE ratio upside target price- recent stock price)\/(recent stock price \u2014 PE ratio downside target price)]&gt;1<\/strong><\/p>\n\n\n\n<p id=\"152e\"><strong>PB return\/risk ratio = [(PB ratio upside target price- recent stock price)\/(recent stock price \u2014 PB ratio downside target price)]&gt;1<\/strong><\/p>\n\n\n\n<p id=\"4ab7\"><strong>PCF return\/risk ratio = [(PCF ratio upside target price- recent stock price)\/(recent stock price \u2014 PCF ratio downside target price)]&gt;1<\/strong><\/p>\n\n\n\n<p id=\"8f85\"><strong>PS return\/risk ratio = [(PS ratio upside target price- recent stock price)\/(recent stock price \u2014 PS ratio downside target price)]&gt;1<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p id=\"2426\">If one of the above 4 indicators is met, it is the stock selection target. Additional filter by the following conditions:<\/p>\n\n\n\n<p id=\"e144\"><strong>kick off the stock with debt to asset ratio in most recent quarter &gt; 65%.<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u76ee\u6a19\u50f9\u8a08\u7b97 #\n## \u672c\u76ca\u6bd4 ##\nmean_7&#91;'PE_TP_upper'] = mean_7&#91;'PE_max']*mean_7&#91;'\u5e38\u7e8c\u6027EPS']\nmean_7&#91;'PE_TP_bottom'] = mean_7&#91;'PE_min']*mean_7&#91;'\u5e38\u7e8c\u6027EPS']\nmean_7&#91;'PE_ret_risk'] = (mean_7&#91;'PE_TP_upper']-mean_7&#91;'stk_start_price'])\/(mean_7&#91;'stk_start_price']-mean_7&#91;'PE_TP_bottom'])\n## \u80a1\u50f9\u6de8\u503c\u6bd4 ##\nmean_7&#91;'PB_TP_upper'] = mean_7&#91;'PB_max']*mean_7&#91;'\u6bcf\u80a1\u6de8\u503c(F)\uff0dTSE\u516c\u544a\u6578']\nmean_7&#91;'PB_TP_bottom'] = mean_7&#91;'PB_min']*mean_7&#91;'\u6bcf\u80a1\u6de8\u503c(F)\uff0dTSE\u516c\u544a\u6578']\nmean_7&#91;'PB_ret_risk'] = (mean_7&#91;'PB_TP_upper']-mean_7&#91;'stk_start_price'])\/(mean_7&#91;'stk_start_price']-mean_7&#91;'PB_TP_bottom'])\n## \u80a1\u50f9\u73fe\u91d1\u6d41\u91cf\u6bd4 ##\nmean_7&#91;'PC_TP_upper'] = mean_7&#91;'PC_max']*mean_7&#91;'\u6bcf\u80a1\u73fe\u91d1\u6d41\u91cf']\nmean_7&#91;'PC_TP_bottom'] = mean_7&#91;'PC_min']*mean_7&#91;'\u6bcf\u80a1\u73fe\u91d1\u6d41\u91cf']\nmean_7&#91;'PC_ret_risk'] = (mean_7&#91;'PC_TP_upper']-mean_7&#91;'stk_start_price'])\/(mean_7&#91;'stk_start_price']-mean_7&#91;'PC_TP_bottom'])\n## \u672c\u76ca\u6bd4 ##\nmean_7&#91;'PS_TP_upper'] = mean_7&#91;'PS_max']*mean_7&#91;'\u6bcf\u80a1\u71df\u696d\u984d']\nmean_7&#91;'PS_TP_bottom'] = mean_7&#91;'PS_min']*mean_7&#91;'\u6bcf\u80a1\u71df\u696d\u984d']\nmean_7&#91;'PS_ret_risk'] = (mean_7&#91;'PS_TP_upper']-mean_7&#91;'stk_start_price'])\/(mean_7&#91;'stk_start_price']-mean_7&#91;'PS_TP_bottom'])\n# \u8a55\u5206 #\nmean_7.loc&#91;:,'score'] = 0\nmean_7&#91;'score'] = np.where(mean_7&#91;'PE_ret_risk'] &gt; 1, 1+mean_7&#91;'score'], mean_7&#91;'score'])\nmean_7&#91;'score'] = np.where(mean_7&#91;'PB_ret_risk'] &gt; 1, 1+mean_7&#91;'score'], mean_7&#91;'score'])\nmean_7&#91;'score'] = np.where(mean_7&#91;'PC_ret_risk'] &gt; 1, 1+mean_7&#91;'score'], mean_7&#91;'score'])\nmean_7&#91;'score'] = np.where(mean_7&#91;'PS_ret_risk'] &gt; 1, 1+mean_7&#91;'score'], mean_7&#91;'score'])\n<\/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\/1GAvxCYJ9UlRx7NtsRVmRdg.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Data Display<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e140\"><span class=\"ez-toc-section\" id=\"Backtest\"><\/span><strong>Backtest<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If one of four conditions is met, we will buy the stock.<\/li>\n\n\n\n<li>Rebalancing portfolio per.<\/li>\n\n\n\n<li>Equally weighted.<\/li>\n\n\n\n<li>The benchmark is twse.<\/li>\n\n\n\n<li>The buy date is t+90, holding period is one year, and the sell date is one year after the buy date.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1xpCQSbz1ac2aChjHqLY0HA.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Date\/Buy_date\/Sell_date\/date of yearly return -explanation<\/figcaption><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>%%time\nreturn_=pd.DataFrame()\nfor year in range(2011,2020):\n    pf = mean_7&#91;(mean_7&#91;'year']==year) &amp; (mean_7&#91;'\u8ca0\u50b5\u6bd4\u7387'] &lt; 65) &amp; (mean_7&#91;'score']&gt;=1)]#.sort_values(by = 'score', ascending = False).reset_index(drop=True)\n    ## \u5c07\u8cb7\u9032\u65e5\u671f\u8a2d\u5728\u5b63\u5e95+90\u65e5 ##\n    buy_date = mean_7&#91;'start']&#91;mean_7&#91;'year']==year].head(1).to_list()&#91;0]\n    sell_date = mean_7&#91;'end']&#91;mean_7&#91;'year']==year].head(1).to_list()&#91;0]\n    ret = pd.DataFrame()\n    pf_H = pf&#91;'\u516c\u53f8\u4ee3\u78bc'].to_list()\n    print('\u6295\u8cc7\u7d44\u5408\u5171\u6709{}\u6a94\u80a1\u7968'.format(len(pf_H)))\n    ## \u81ea tejapi\u6488\u53d6\u65e5\u5831\u916c\u8cc7\u6599\uff0c\u65e5\u671f\u8a2d\u5b9a\u70ba buy_date(\u4e0d\u542b)\u81f3 sell_date(\u542b) ##\n    print('getting data')\n    stk_data = tejapi.get('TWN\/APRCD2',\n                          coid = pf_H,\n                          paginate = True,\n                          mdate={'gt':buy_date,'lt':sell_date},\n                          chinese_column_name=True)\n    # \u8a08\u7b97\u5831\u916c\u7387 #\n    print('calculating return')\n    pf_ret = stk_data.groupby(by = '\u5e74\u6708\u65e5').mean()&#91;'\u65e5\u5831\u916c\u7387 %']\n    pf_ret = pf_ret.reset_index(drop=True)\n#     ret&#91;ranking&#91;i]] = pf_ret\n    ret&#91;'portfolio'] = pf_ret\n#     i+=1\n    ## \u6488\u53d6\u53f0\u7063\u52a0\u6b0a\u6307\u6578\u7684\u65e5\u5831\u916c\u7387\uff0c\u65e5\u671f\u8a2d\u5b9a\u70ba buy_date(\u4e0d\u542b)\u81f3 sell_date(\u4e0d\u542b) ##\n    twse = tejapi.get('TWN\/APRCD2',coid ='Y9999' ,paginate = True,mdate={'gt':buy_date,'lt':sell_date},chinese_column_name=True)\n    bm_return = twse.groupby('\u5e74\u6708\u65e5').mean()&#91;'\u65e5\u5831\u916c\u7387 %'].reset_index(drop=True)\n    ret&#91;'twse_return'] = bm_return\n    ret&#91;'Date'] = twse&#91;'\u5e74\u6708\u65e5']\n    return_ = return_.append(ret).reset_index(drop=True)\n    print(return_)<\/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\/1gxmav3Os6eIGwZLanTFkFg.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Daily return<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"a21b\"><span class=\"ez-toc-section\" id=\"Cumulative_return\"><\/span><strong>Cumulative return<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>cum_ret = return_&#91;&#91;'portfolio','twse_return']].astype(float).apply(lambda x:x*0.01+1).cumprod().reset_index(drop=True)\ncum_ret&#91;'Date'] = return_&#91;'Date']\ncum_ret<\/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\/1Q5etuJbKX-uTcuu_BHNpkg.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Cumulative return<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"cffe\"><span class=\"ez-toc-section\" id=\"Performance_visualization\"><\/span><strong>Performance visualization<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"e07f\"><span class=\"ez-toc-section\" id=\"Plot_cumulative_return\"><\/span><strong>Plot cumulative return<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>cum_ret.plot(x='Date',figsize=(10,6))<\/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\/10ll2TamVD1Ox2iriT8-5Uw.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Cumulative Returns Line Chart<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"937e\"><span class=\"ez-toc-section\" id=\"Performance_indicator_report\"><\/span><strong>Performance indicator\/ report <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># \u7e3e\u6548\u5831\u8868 #\nyearly_mean_ret = (((cum_ret&#91;&#91;'portfolio','twse_return']].tail(1)**(1\/len(cum_ret)))**252-1)*100).reset_index(drop=True)\nyearly_std = cum_ret&#91;&#91;'portfolio','twse_return']].std()*(252**(0.5))\nRf = 1\nsp_ratio = (yearly_mean_ret-Rf)\/yearly_std\nroll_max = cum_ret&#91;&#91;'portfolio','twse_return']].cummax()\ndraw_down = (cum_ret&#91;&#91;'portfolio','twse_return']]-roll_max)\/roll_max\nMDD = draw_down.min()*100\nperformace_report = pd.DataFrame({\n    'portfolio':&#91;yearly_mean_ret&#91;'portfolio'].values&#91;0],\n                 yearly_std&#91;'portfolio'],\n                 sp_ratio&#91;'portfolio'].values&#91;0],\n                 MDD&#91;'portfolio']],\n    'twse_return':&#91;yearly_mean_ret&#91;'twse_return'].values&#91;0],\n                   yearly_std&#91;'twse_return'],\n                   sp_ratio&#91;'twse_return'].values&#91;0],\n                   MDD&#91;'twse_return']]}\n    ,index= &#91;'\u5e74\u5316\u5831\u916c','\u5e74\u5316\u6ce2\u52d5\u5ea6','\u590f\u666e\u6307\u6a19','\u6700\u5927\u56de\u6a94'])\nperformace_report<\/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\/1uqT59OwOYeJOynmwRXbtrQ.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Performance report<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"61f0\"><span class=\"ez-toc-section\" id=\"The_latest_portfolio\"><\/span><strong>The latest portfolio <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>pf2020 = mean_7&#91;(mean_7&#91;'year']==2020) &amp; (mean_7&#91;'\u8ca0\u50b5\u6bd4\u7387'] &lt; 65) &amp; (mean_7&#91;'score']&gt;=1)]&#91;'\u516c\u53f8\u4ee3\u78bc'].to_list()\nstk_info&#91;&#91;'\u8b49\u5238\u78bc','\u8b49\u5238\u540d\u7a31']]&#91;stk_info&#91;'\u8b49\u5238\u78bc'].isin(pf2020)].reset_index(drop=True)\n<\/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\/12mUpoVYgVJsEY28hYg_ZTw.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">the latest port<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3a49\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"d67a\"><strong>Our portfolio outperforms the twse index at the aspect of cumulative return, but after taking risk into account, the benchmark beats the portfolio at volatility, Sharpe ratio, and max drawdown.<\/strong><\/p>\n\n\n\n<p id=\"6aaf\">Roger King\u2019s investing strategy wins the benchmark by a narrow margin at return, but fail to exceed the benchmark after considering the risk. The result is quite different as our expect, however there doesn\u2019t have a stable holy grail for the long-time, all the criteria should adjust along with time.<\/p>\n\n\n\n<p id=\"cb33\"><strong>The most important is to extract thinking and experience from the investment master like Roger King and Benjamin Graham. Finally, construct your own strategy<\/strong><strong>.<\/strong><\/p>\n\n\n\n<p id=\"376e\">Next time, we will share the investing concept of&nbsp;<strong>Trinity Investment Management !!<\/strong><\/p>\n\n\n\n<p id=\"c3ef\">Finally, if you like this article, please click below, giving us more support and encouragement. Besides, if you have any questions or suggestions, please leave a message or email us, we will try our best to reply to you.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3426\"><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>API Official Website:\u00a0<\/strong><a href=\"https:\/\/api.tej.com.tw\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>TEJ API Official Website<\/strong><\/a><\/li>\n\n\n\n<li><strong>The Product Package:\u00a0<\/strong><a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_caseIntro\/1\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>TEJ E SHOP<\/strong><\/a><\/li>\n\n\n\n<li><strong>Source Code:\u00a0<\/strong><a href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Application\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>TEJ GITHUB<\/strong><\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Fulfill Roger E. King\u2019 s investing strategy through python. Preface Roger E. King is a well-known value fund manager in the United States. He used to be the senior vice president and chief investment officer of Sun Insurance Services and senior vice president of GULFCO Investment Management. He founded King Investment Advisors Inc. in 1981. [&hellip;]<\/p>\n","protected":false},"featured_media":15972,"template":"","tags":[2371,3005,2537],"insight-category":[690,50],"class_list":["post-15971","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-python","tag-tejapi-application","tag-2537","insight-category-data-analysis","insight-category-fintech"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/15971","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\/15971\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/15972"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=15971"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=15971"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=15971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}