{"id":2394,"date":"2022-02-15T02:39:07","date_gmt":"2022-02-15T02:39:07","guid":{"rendered":"https:\/\/www.tejwin.com\/en\/insights\/money-management\/"},"modified":"2022-02-15T02:39:07","modified_gmt":"2022-02-15T02:39:07","slug":"money-management","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insights\/money-management\/","title":{"rendered":"Money Management"},"content":{"rendered":"<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/1_1qlObqxTUhOLAgAT-gUcTKA.jpg\"\/><figcaption class=\"wp-element-caption\">Photo by\u00a0<a href=\"https:\/\/unsplash.com\/@freegraphictoday?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\" rel=\"noreferrer noopener\" target=\"_blank\">AbsolutVision<\/a>\u00a0on\u00a0<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<h2 class=\"wp-block-heading\" id=\"7c03\"><strong>Highlights<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li>Difficulty\uff1a\u2605\u2605\u2606\u2606\u2606<\/li>\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\">\u00a0the video introduced by Mr. Li Yongle<\/a>.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"fd71\"><strong>Preface<\/strong><\/h2>\n<p class=\"wp-block-paragraph\" 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<p class=\"wp-block-paragraph\" 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<p class=\"wp-block-paragraph\" 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<h2 class=\"wp-block-heading\" id=\"7300\"><strong>Editing Environment and Modules Required<\/strong><\/h2>\n<p class=\"wp-block-paragraph\" id=\"0c98\">Windows OS and Jupyter Notebook<\/p>\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<h2 class=\"wp-block-heading\" id=\"9381\"><strong>Database<\/strong><\/h2>\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<h2 class=\"wp-block-heading\" id=\"6af3\"><strong>Data Processing<\/strong><\/h2>\n<p class=\"wp-block-paragraph\" id=\"9ffb\">We gather the 0050 ETF monthly return from the TEJ database.<\/p>\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<h2 class=\"wp-block-heading\" id=\"e8a6\"><strong>Kelly\u2019s <strong>formula<\/strong><\/strong><\/h2>\n<p class=\"wp-block-paragraph\" 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<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<li>\uff42: Odds ratio measures the association between an exposure and an outcome.<\/li>\n<li>\uff46: The ratio of invested capital to principal<\/li>\n<\/ul>\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<p class=\"wp-block-paragraph\" 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<figure class=\"wp-block-image aligncenter caption-align-center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/1boGotrt8Z2SE_5p-q523gQ.png\"\/><figcaption class=\"wp-element-caption\">Kelly formula<\/figcaption><\/figure>\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<p class=\"wp-block-paragraph\" id=\"f5f8\">We systematically adjust betting ratios based on win rates and odds.<\/p>\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/1DCRhsik42lAu3zQZTcXHXg.png\"\/><\/figure>\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<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/1_1ozzL-HgTvRdmRj4QrFIbeg.png\"\/><\/figure>\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/1_1sTDvZEFLDHV8L1Z1cuDqtw.png\"\/><\/figure>\n<h2 class=\"wp-block-heading\" id=\"0d81\"><strong>Conclusion<\/strong><\/h2>\n<p class=\"wp-block-paragraph\" 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<p class=\"wp-block-paragraph\" 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\u00a0<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<p class=\"wp-block-paragraph\" 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<h2 class=\"wp-block-heading\" id=\"5638\"><strong>Source Code<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li><a class=\"ek-link\" href=\"https:\/\/gist.github.com\/tej87681088\/675db3702003aa1f83de69a44ccbaa15#file-tejapi_medium-12-ipynb\" rel=\"noopener\" target=\"_blank\">Click here to go Github<\/a><\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"e4df\"><strong>Extended Reading<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li><a class=\"ek-link\" href=\"\/en\/insight\/martingale-strategy\/\">Martingale Strategy<\/a><\/li>\n<li><a class=\"ek-link\" href=\"\/en\/insight\/brinson-model-performance-attribution\/\">Brinson Model Performance attribution<\/a><\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"34c4\"><strong>Related Link<\/strong><\/h2>\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\" rel=\"noopener\" target=\"_blank\">TEJ API<\/a><\/li>\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 [\u2026]<\/p>\n","protected":false},"featured_media":2389,"template":"","tags":[50,65,70,71],"insight_category":[13],"class_list":["post-2394","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-market-data","tag-python","tag-tej-api","tag-quantitative-strategy","insight_category-quant-research"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/2394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight"}],"about":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/types\/insight"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/2389"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=2394"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=2394"},{"taxonomy":"insight_category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight_category?post=2394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}