{"id":16726,"date":"2022-02-15T02:39:07","date_gmt":"2022-02-14T18:39:07","guid":{"rendered":"https:\/\/www.tejwin.com\/?post_type=insight&#038;p=16726"},"modified":"2023-08-17T09:54:01","modified_gmt":"2023-08-17T01:54:01","slug":"money-management","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/money-management\/","title":{"rendered":"Money Management"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1_1qlObqxTUhOLAgAT-gUcTKA.jpg\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Photo by&nbsp;<a href=\"https:\/\/unsplash.com\/@freegraphictoday?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\" rel=\"noreferrer noopener\" target=\"_blank\">AbsolutVision<\/a>&nbsp;on&nbsp;<a href=\"https:\/\/unsplash.com\/s\/photos\/finance?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\" rel=\"noreferrer noopener\" target=\"_blank\">Unsplash<\/a><\/figcaption><\/figure>\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-69df28fa5b96f\" 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-69df28fa5b96f\"  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\/money-management\/#Highlights\" >Highlights<\/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\/money-management\/#Preface\" >Preface<\/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\/money-management\/#Editing_Environment_and_Modules_Required\" >Editing Environment and Modules Required<\/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\/money-management\/#Database\" >Database<\/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\/money-management\/#Data_Processing\" >Data Processing<\/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\/money-management\/#Kellys_formula\" >Kelly\u2019s formula<\/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\/money-management\/#Conclusion\" >Conclusion<\/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\/money-management\/#Source_Code\" >Source Code<\/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\/money-management\/#Extended_Reading\" >Extended Reading<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.tejwin.com\/en\/insight\/money-management\/#Related_Link\" >Related Link<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"7c03\"><span class=\"ez-toc-section\" id=\"Highlights\"><\/span><strong>Highlights<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Difficulty\uff1a\u2605\u2605\u2606\u2606\u2606<\/li>\n\n\n\n<li>Reminder\uff1a We use PYTHON to implement the Kelly formula. If you are interested in the derivation of the Kelly formula, you can further watch<a href=\"https:\/\/www.youtube.com\/watch?v=v2JGTi5lhY4&amp;t=543s\" rel=\"noreferrer noopener\" target=\"_blank\">&nbsp;the video introduced by Mr. Li Yongle<\/a>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fd71\"><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=\"0fe4\">We are strange and familiar with the winning rates, odds, and betting ratios. We often depend on our sentiment to multiply the winning percentage and odds in our hearts and determine the betting ratio of the investment. Therefore, it\u2019s difficult to explain our subjective betting ratio to someone.<\/p>\n\n\n\n<p id=\"c29c\">It is inevitable in investment that the winning rate and the odds have extremely high subjective judgments. Still, we can use the Kelly formula to determine the betting ratio after determining the winning rate and the odds. Under the condition that the principal will never return to zero and maximize long-term gains.<\/p>\n\n\n\n<p id=\"1ab0\">Next, we use the Kelly formula to determine the betting ratio and reinvest the 0050 ETF at the beginning of each month. Meanwhile, we compare investment groups with the same buy &amp; hold principal.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"7300\"><span class=\"ez-toc-section\" id=\"Editing_Environment_and_Modules_Required\"><\/span><strong>Editing Environment and Modules Required<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"0c98\">Windows OS and Jupyter Notebook<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import matplotlib.pyplot as plt<br>import numpy as npimport tejapi<br>tejapi.ApiConfig.api_key = \"your key\"<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"9381\"><span class=\"ez-toc-section\" id=\"Database\"><\/span><strong>Database<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/api.tej.com.tw\/columns.html?idCode=TWN%2FAAPRCM1\" rel=\"noreferrer noopener\" target=\"_blank\">Adjusted monthly stock price<\/a>: the code of the database is (TWN\/AAPRCM1)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6af3\"><span class=\"ez-toc-section\" id=\"Data_Processing\"><\/span><strong>Data Processing<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"9ffb\">We gather the 0050 ETF monthly return from the TEJ database.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">data_return = tejapi.get('TWN\/AAPRCM1',<br>                         coid = '0050',<br>                         mdate= {'gte': '2010-01-01','lte':'2015-12-31'},<br>                         opts={'columns':['coid','mdate','roi']},<br>                         chinese_column_name=True,paginate=True)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e8a6\"><span class=\"ez-toc-section\" id=\"Kellys_formula\"><\/span><strong>Kelly\u2019s <strong>formula<\/strong><\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"ec43\">We base on the previous 12-month monthly rate of return. If the monthly rate of return is greater than 0, it is considered a success; otherwise, it fails. This way, we can obtain the winning rate and odds when investing in the 0050 ETF at the beginning of each month.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\uff30: Winning rate is the fraction of games or matches a team or individual has won.<\/li>\n\n\n\n<li>\uff42: Odds ratio measures the association between an exposure and an outcome.<\/li>\n\n\n\n<li>\uff46: The ratio of invested capital to principal<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">data_return['\u52dd\u7387'] = np.where(data_return['\u5831\u916c\u7387\uff05_\u6708'] &gt;= 0 ,1,0)<br>data_return['\u52dd\u7387'] = data_return.rolling(12)['\u52dd\u7387'].sum() \/ 12data_return['\u7372\u5229'] = np.where(data_return['\u5831\u916c\u7387\uff05_\u6708'] &gt;= 0 ,data_return['\u5831\u916c\u7387\uff05_\u6708'],np.nan)<br>data_return['\u8667\u640d'] = np.where(data_return['\u5831\u916c\u7387\uff05_\u6708'] &lt; 0 ,data_return['\u5831\u916c\u7387\uff05_\u6708'],np.nan)data_return['\u8ce0\u7387'] = data_return.rolling(12, min_periods=1)['\u7372\u5229'].mean() \\<br>    \/ data_return.rolling(12, min_periods=1)['\u8667\u640d'].mean().abs()<\/pre>\n\n\n\n<p id=\"0be0\">We then use the Kelly formula to get the betting ratio and multiply the principal by the betting ratio, the current bet amount. If the numerator in Kelly\u2019s formula is negative. It means the investment is not worth betting on, and we set the betting ratio for this period to 0.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1boGotrt8Z2SE_5p-q523gQ.png\" alt=\"\"\/><figcaption class=\"wp-element-caption\">Kelly formula<\/figcaption><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">data_return['\u4e0b\u6ce8\u6bd4\u4f8b'] = \\<br>    np.where(data_return['\u52dd\u7387'] * data_return['\u8ce0\u7387'] - (1 - data_return['\u52dd\u7387']) &lt; 0,0,<br>             (data_return['\u52dd\u7387'] * data_return['\u8ce0\u7387'] - (1 - data_return['\u52dd\u7387'])) \/ data_return['\u8ce0\u7387']<br>             )<br><strong># \u524d\u4e00\u500b\u6708\u7684\u4e0b\u6ce8\u6bd4\u4f8b\uff0c\u907f\u514d\u524d\u8996\u504f\u8aa4<br><\/strong>data_return['\u4e0b\u6ce8\u6bd4\u4f8b'] = data_return['\u4e0b\u6ce8\u6bd4\u4f8b'].shift()<\/pre>\n\n\n\n<p id=\"f5f8\">We systematically adjust betting ratios based on win rates and odds.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1DCRhsik42lAu3zQZTcXHXg.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in range(0,len(data_return)):<br>    if i == 0:<br>        data_return['buy &amp; hold\u672c\u91d1'] = 1000000 # \u8d77\u59cb\u672c\u91d1<br>    else:<br>        data_return.loc[i,'buy &amp; hold\u672c\u91d1'] = 1000000 * data_return.loc[i-1,'\u7d2f\u7a4d\u5831\u916c\u7387\uff05_\u6708']for i in range(0,len(data_return)):<br>    if i == 0:<br>        data_return['\u51f1\u5229\u672c\u91d1'] = 1000000 # \u8d77\u59cb\u672c\u91d1<br>    else:<br>        if data_return.loc[i,'\u4e0b\u6ce8\u6bd4\u4f8b'] &gt; 0:<br>            data_return.loc[i,'\u51f1\u5229\u672c\u91d1'] = data_return.loc[i-1,'\u51f1\u5229\u672c\u91d1'] * (1 - data_return.loc[i,'\u4e0b\u6ce8\u6bd4\u4f8b']) \\<br>                + data_return.loc[i-1,'\u51f1\u5229\u672c\u91d1'] * data_return.loc[i,'\u4e0b\u6ce8\u6bd4\u4f8b'] * (1 + data_return.loc[i,'\u5831\u916c\u7387\uff05_\u6708']) <br>                    # - data_return.loc[i-1,'\u51f1\u5229\u672c\u91d1'] * data_return.loc[i,'\u4e0b\u6ce8\u6bd4\u4f8b'] * 0.002 # \u624b\u7e8c\u8cbb<br>        else:<br>            data_return.loc[i,'\u51f1\u5229\u672c\u91d1'] = data_return.loc[i-1,'\u51f1\u5229\u672c\u91d1']<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1_1ozzL-HgTvRdmRj4QrFIbeg.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1_1sTDvZEFLDHV8L1Z1cuDqtw.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"0d81\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"fbce\">We observe the accumulation trend chart of principal from 2011 to 2015 compared the investment groups under Buy &amp; Hold and Kelly\u2019s formula. We find that the accumulated principal amount of the latter doesn\u2019t win the former. The possible reason is the Kelly formula applies to all known possibilities or investments where possibilities can be estimated. The uncertain odds in the stock market make it difficult for Kelly\u2019s formula to work. However, the thinking of Kelly\u2019s formula is still worth learning. The betting ratio controls risk. Even with a high winning rate and high odds, do not All in to avoid permanent losses.<\/p>\n\n\n\n<p id=\"5d32\">In the future, readers can try to study how to improve the winning rate and odds of the strategy to make the betting ratio more accurate. When we enlarge our position with the thinking of risk control, which will help us survive in the market a long time. Finally, readers are welcome to visit our&nbsp;<a href=\"https:\/\/api.tej.com.tw\/datatables.html?db=TWN&amp;t=%E5%8F%B0%E7%81%A3%E8%B3%87%E6%96%99%E5%BA%AB\" rel=\"noreferrer noopener\" target=\"_blank\"><strong>official website<\/strong><\/a>, which provides more financial, trading, and other financial information to help readers make better stock selection strategies!<\/p>\n\n\n\n<p id=\"5775\">The content of this webpage is not an investment device. It does not constitute an offer or solicitation to offer or recommendation of any investment product. It is for learning purposes only and does not consider your individual needs, investment objectives, and specific financial circumstances. Investment involves risk. Past performance is not indicative of future performance. Readers are requested to use their independent thinking skills to make investment decisions independently. The author will not be involved if losses are incurred due to relevant suggestions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5638\"><span class=\"ez-toc-section\" id=\"Source_Code\"><\/span><strong>Source Code<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/gist.github.com\/tej87681088\/675db3702003aa1f83de69a44ccbaa15#file-tejapi_medium-12-ipynb\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">Click here to go Github<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e4df\"><span class=\"ez-toc-section\" id=\"Extended_Reading\"><\/span><strong>Extended Reading<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.tejwin.com\/en\/insight\/martingale-strategy\/\" class=\"ek-link\">Martingale Strategy<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.tejwin.com\/en\/insight\/brinson-model-performance-attribution\/\" class=\"ek-link\">Brinson Model Performance attribution<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"34c4\"><span class=\"ez-toc-section\" id=\"Related_Link\"><\/span><strong>Related Link<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/medium.com\/r?url=https%3A%2F%2Fapi.tej.com.tw%2Fdatatables.html%3Fdb%3DTWN%26t%3D%25E5%258F%25B0%25E7%2581%25A3%25E8%25B3%2587%25E6%2596%2599%25E5%25BA%25AB\" target=\"_blank\" rel=\"noopener\">TEJ API<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_intro\" rel=\"noreferrer noopener\" target=\"_blank\">TEJ E-Shop<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Highlights Preface We are strange and familiar with the winning rates, odds, and betting ratios. We often depend on our sentiment to multiply the winning percentage and odds in our hearts and determine the betting ratio of the investment. Therefore, it\u2019s difficult to explain our subjective betting ratio to someone. It is inevitable in investment [&hellip;]<\/p>\n","protected":false},"featured_media":16734,"template":"","tags":[2371,3005,2700],"insight-category":[690,50],"class_list":["post-16726","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-python","tag-tejapi-application","tag-2700","insight-category-data-analysis","insight-category-fintech"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/16726","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":1,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/16726\/revisions"}],"predecessor-version":[{"id":16741,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/16726\/revisions\/16741"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/16734"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=16726"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=16726"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=16726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}