{"id":16581,"date":"2021-11-30T02:51:48","date_gmt":"2021-11-29T18:51:48","guid":{"rendered":"https:\/\/www.tejwin.com\/?post_type=insight&#038;p=16581"},"modified":"2023-08-16T13:13:28","modified_gmt":"2023-08-16T05:13:28","slug":"two-factor-weights-portfolio-setting","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/two-factor-weights-portfolio-setting\/","title":{"rendered":"Two-Factor weights portfolio setting"},"content":{"rendered":"\n<p>Does the weights setting affects the performance of the two-factor portfolio?<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter is-resized caption-align-center\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1dylUsOfyIzVMhiLyE1WeyQ.jpg\" alt=\"\" width=\"827\" height=\"504\"\/><figcaption class=\"wp-element-caption\">Photo by&nbsp;<a href=\"https:\/\/unsplash.com\/@hostreviews\" rel=\"noreferrer noopener\" target=\"_blank\">Stephen Phillips<\/a>&nbsp;on&nbsp;<a href=\"https:\/\/unsplash.com\/?utm_source=medium&amp;utm_medium=referral\" rel=\"noreferrer noopener\" target=\"_blank\">Unsplash<\/a><\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Difficulty\uff1a\u2605\u2605\u2605\u2605\u2606<\/li>\n\n\n\n<li>There is no significant difference between the equal-weighted and the Information Coefficient(IC) weighted in the portfolio performance of backtesting.<\/li>\n\n\n\n<li>Advice: Before optimizing the weights of multiple factors, the single factor should be subjected to hierarchical clustering backtesting and cross-sectional regression analysis to test whether the single factor has profitability, stability and interpretability. To find the most comprehensive combination of factors, the article refers to&nbsp;<a href=\"https:\/\/www.books.com.tw\/products\/0010858230\" rel=\"noreferrer noopener\" target=\"_blank\">Ye Yicheng \u3010Taiwan Stock Research Office\u3011<\/a>&nbsp;and selects return on equity(ROE) ratio and Price-to-Earnings(PE)ratio to analyze the impact of weights setting on the factor grouping portfolio.<\/li>\n\n\n\n<li>Linking to&nbsp;<a href=\"https:\/\/gist.github.com\/tej87681088\/cf60a0347f0a88f3c2be5bf80065ad15\" rel=\"noreferrer noopener\" target=\"_blank\">code<\/a><\/li>\n<\/ul>\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-69f4907678cd8\" 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-69f4907678cd8\"  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\/two-factor-weights-portfolio-setting\/#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\/two-factor-weights-portfolio-setting\/#The_Editing_Environment_and_Modules_Required\" >The 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-3\" href=\"https:\/\/www.tejwin.com\/en\/insight\/two-factor-weights-portfolio-setting\/#Database_Used\" >Database Used<\/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\/two-factor-weights-portfolio-setting\/#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-5\" href=\"https:\/\/www.tejwin.com\/en\/insight\/two-factor-weights-portfolio-setting\/#Calculate_IC_value_and_establish_portfolio\" >Calculate IC value and establish portfolio<\/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\/two-factor-weights-portfolio-setting\/#Visualization\" >Visualization<\/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\/two-factor-weights-portfolio-setting\/#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\/two-factor-weights-portfolio-setting\/#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-9\" href=\"https:\/\/www.tejwin.com\/en\/insight\/two-factor-weights-portfolio-setting\/#Related_Link\" >Related Link<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"9b63\"><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=\"5e3a\">The common weights settings are equal-weighted and capitalization-weighted. The former treats all factors as the same, assigns equal weights to different factors, and synthesizes new factor values; the latter weights individual factors with capitalization-weighted to synthesize new factor values at first, assign different factors with equal weights, and then synthesize new factor values. However, neither of the two methods considers the effectiveness of the factors.<\/p>\n\n\n\n<p id=\"e041\">The article considers the effectiveness of factors by adding the IC-weighted, IC describes the correlation between factor value and the subsequent rolling stock returns. If IC value is high, it means the factor is more effective at the moment. When we adjusts dynamically weights at the beginning of each month, factors with higher IC value has higher weights.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"be52\"><span class=\"ez-toc-section\" id=\"The_Editing_Environment_and_Modules_Required\"><\/span><strong>The Editing Environment and Modules Required<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"1418\">Windows OS and Jupyter Notebook<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#Basic function and Visualization<br>import pandas as pd<br>from scipy import stats<br>from collections import OrderedDict<br>import matplotlib.pyplot as plt<br>import copy#TEJ<br>import tejapi<br>tejapi.ApiConfig.api_key = 'Your Key'<br>tejapi.ApiConfig.ignoretz = True<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"e2dd\"><span class=\"ez-toc-section\" id=\"Database_Used\"><\/span><strong>Database Used<\/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\/columndoc.html?subId=110\" rel=\"noreferrer noopener\" target=\"_blank\">ROE(A)\uff0d<\/a><a href=\"https:\/\/terms.naer.edu.tw\/detail\/3542679\/\" rel=\"noreferrer noopener\" target=\"_blank\">after-tax<\/a>\uff1a the code of the database is (TWN\/AIFIN)<\/li>\n\n\n\n<li><a href=\"https:\/\/medium.com\/r?url=https%3A%2F%2Fapi.tej.com.tw%2Fcolumndoc.html%3FsubId%3D111\" target=\"_blank\" rel=\"noopener\">Date the financial statements are issued<\/a>\uff1a the code of the database is (TWN\/AIFINA)<\/li>\n\n\n\n<li><a href=\"https:\/\/api.tej.com.tw\/columndoc.html?subId=46\" rel=\"noreferrer noopener\" target=\"_blank\">Ex-right and Ex-dividend price and PB ratio(listed company)<\/a>\uff1athe code of the database is (TWN\/APRCD1)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"c0e3\"><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=\"f170\"><strong>Step 1.&nbsp;<\/strong>Obtain the stock price, ROE and financial statements date<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u6488\u53d6\u4e0a\u5e02\u6240\u6709\u666e\u901a\u80a1\u8b49\u5238\u4ee3\u78bc<br>code = tejapi.get(\"TWN\/EWNPRCSTD\", paginate=True, chinese_column_name=True)<br>code = code[\"\u8b49\u5238\u78bc\"][(code[\"\u8b49\u5238\u7a2e\u985e\u540d\u7a31\"] == \"\u666e\u901a\u80a1\") &amp; (code[\"\u4e0a\u5e02\u5225\"].isin([\"TSE\"]))].to_list()# \u532f\u5165 ROE\u8b8a\u6578<br>data_ROE = tejapi.get('TWN\/AIFIN',<br>                      coid = code,<br>                      mdate= {'gte': '2019-01-01','lte':'2020-12-31'},<br>                      opts={'pivot':True ,'columns':['coid', 'mdate', 'R103']},<br>                      chinese_column_name=True,<br>                      paginate=True)# \u532f\u5165 \u8ca1\u5831\u767c\u5e03\u65e5<br>data_annouce = tejapi.get('TWN\/AIFINA',<br>                          coid = code,<br>                          mdate= {'gte': '2019-01-01','lte':'2020-12-31'},<br>                          opts={'columns':['coid', 'mdate', 'a0003']},<br>                          chinese_column_name=True,<br>                          paginate=True)# \u532f\u5165 \u8abf\u6574\u5f8c\u958b\u76e4\u50f9\u3001\u6536\u76e4\u50f9\u8207\u80a1\u50f9\u6de8\u503c\u6bd4<br>data_PB_price = tejapi.get('TWN\/APRCD1',<br>                           coid = code,<br>                           mdate= {'gte': '2019-03-01','lte':'2020-03-31'},<br>                           opts={'columns':['coid', 'mdate','open_adj','close_adj','pbr_tej']},<br>                           chinese_column_name=True,<br>                           paginate=True)<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1gAcE2eHGjl7dyPrrATsLCQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"9a11\">First obtain all listed company codes, and use TEJ API to obtain the financial information in different databases at once.<\/p>\n\n\n\n<p id=\"f651\"><strong>Step 2.&nbsp;<\/strong>Data Preprocessing<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u6574\u7406\u80a1\u50f9<br>data_PB_price = data_PB_price.rename({'\u8b49\u5238\u4ee3\u78bc': '\u516c\u53f8'}, axis=1) # \u6539\u540d\u5b57<br>data_PB_price['\u958b\u76e4\u50f9(\u5143) t+1'] = data_PB_price.groupby('\u516c\u53f8')['\u958b\u76e4\u50f9(\u5143)'].shift(-1)# \u65b0\u589e\u5e74\u8207\u6708<br>data_PB_price['\u5e74'] = data_PB_price['\u5e74\u6708\u65e5'].dt.year<br>data_PB_price['\u6708'] = data_PB_price['\u5e74\u6708\u65e5'].dt.month<br>data_PB_price = data_PB_price.sort_values(by=['\u5e74\u6708\u65e5']).reset_index(drop=True) # \u6392\u5e8f\u5e74\u6708\u65e5<\/pre>\n\n\n\n<p id=\"90a0\"><strong>Step 3.&nbsp;<\/strong>Merge data in different frequencies and keep each month end data<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u5408\u4f75\u5b63\u983b\u7387 ROE\u8207\u8ca1\u5831\u767c\u5e03\u65e5<br>data_all = pd.merge(data_ROE ,data_annouce ,how = 'left' , on = ['\u516c\u53f8','\u5e74\/\u6708'])<br>data_all = data_all.rename({'\u5e74\/\u6708': '\u8ca1\u5831'}, axis=1) # \u6539\u540d\u5b57<br>data_all = data_all.sort_values(by=['\u8ca1\u5831\u767c\u5e03\u65e5']).reset_index(drop=True) # \u6392\u5e8f\u8ca1\u5831\u767c\u5e03\u65e5# \u5408\u4f75\u5b63\u983b\u7387\u8207\u65e5\u983b\u7387\u8cc7\u6599<br>data_all = pd.merge_asof(data_PB_price ,data_all ,left_on = '\u5e74\u6708\u65e5', right_on = '\u8ca1\u5831\u767c\u5e03\u65e5', by = ['\u516c\u53f8'] ,direction = \"backward\")# \u7559\u4e0b\u6bcf\u6708\u5e95\u8cc7\u6599<br>data_all = data_all.drop_duplicates(subset=['\u516c\u53f8','\u5e74','\u6708'], keep='last')<br>data_all = data_all.sort_values(by=['\u516c\u53f8','\u5e74\u6708\u65e5']).reset_index(drop=True)<br>data_all['\u6708\u6301\u6709\u5831\u916c\u7387'] = data_all.groupby('\u516c\u53f8')['\u6536\u76e4\u50f9(\u5143)'].shift(-1).reset_index(drop=True) \\<br>    \/ data_all['\u958b\u76e4\u50f9(\u5143) t+1'] -1<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1abNZ-QIbdmdeqju1fgLW-A.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"a425\"><code>pd.merge<\/code>&nbsp;and&nbsp;<code>pd.merge_asof<\/code>&nbsp;are very useful tools to merge dataframes. The former is used to merge data in the same frequency, the latter is used to merge data in the different frequencies. The parameter&nbsp;<code>direction = backward<\/code>&nbsp;can avoid the look-ahead bias;&nbsp;<code>pd.drop_duplicates<\/code>&nbsp;can filter the data for year and month, then keep month end data of each company. Finally, we can get the current accurate factor value, and sort and group factor by value.<\/p>\n\n\n\n<p id=\"5758\"><strong>Step 4.&nbsp;<\/strong>Delete missing data<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">data_all = data_all.dropna().reset_index(drop=True)<br>data_all = data_all.set_index(['\u5e74\u6708\u65e5','\u516c\u53f8'])<br>data_all = data_all[['\u80a1\u50f9\u6de8\u503c\u6bd4-TEJ','ROE(A)\uff0d\u7a05\u5f8c','\u6708\u6301\u6709\u5831\u916c\u7387']]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6c9d\"><span class=\"ez-toc-section\" id=\"Calculate_IC_value_and_establish_portfolio\"><\/span><strong>Calculate IC value and establish portfolio<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"af30\"><strong>Step 1.&nbsp;<\/strong>Sort a factor based on value<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def get_rank(data):<br>    factors_name=[i for i in data.columns.tolist() if i not in ['\u6708\u6301\u6709\u5831\u916c\u7387']] # \u5f97\u5230\u56e0\u5b50\u540d<br>    <br>    rank_df = []<br>    for factor in factors_name:<br>        if factor in ['\u80a1\u50f9\u6de8\u503c\u6bd4-TEJ']:<br>            rank_list = data[factor].groupby(level=0).rank(ascending = True) # rank\u7531\u5c0f\u5230\u5927\u6392\u5e8f\uff0c\u5373\u503c\u8d8a\u5c0f\uff0c\u6392\u540d\u8d8a\u9760\u524d<br>        else:<br>            rank_list = data[factor].groupby(level=0).rank(ascending = False) # rank\u7531\u5927\u5230\u5c0f\u6392\u5e8f\uff0c\u5373\u503c\u8d8a\u5927\uff0c\u6392\u540d\u8d8a\u9760\u524d<br>        <br>        rank_df.append(rank_list)<br>        <br>    rank_df = pd.concat(rank_df, axis=1)<br>    return rank_df<\/pre>\n\n\n\n<p id=\"1b0f\">ROE is a measure of a company\u2019s profitability, a company with a higher ROE has greater the expected rate of return, so it is arranged in descending order, that is, ROE is higher, the ranking is higher; PE ratio is a measure of a company\u2019s good value, a company with a lower PE ratio has greater the expected rate of return, so it is arranged in ascending order, that is, PE ratio is more small, the ranking is higher.<\/p>\n\n\n\n<p id=\"56f3\"><strong>Step 2.&nbsp;<\/strong>Get IC values<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def get_ic(data):<br>    factors_name=[i for i in data.columns.tolist() if i not in ['\u6708\u6301\u6709\u5831\u916c\u7387']] # \u5f97\u5230\u56e0\u5b50\u540d<br>    ic = data.groupby(level=0).\\<br>        apply(lambda data: [stats.spearmanr(data[factor],<br>                                            data['\u6708\u6301\u6709\u5831\u916c\u7387'])[1] for factor in factors_name])<br>        <br>    ic = pd.DataFrame(ic.tolist(), index=ic.index, columns=factors_name)<br>    return ic<\/pre>\n\n\n\n<p id=\"17b2\">IC is a correlation coefficient of the factor to the future holding rate of return at a certain cross-sectional time. The higher IC value, the higher the expected return of holding in the future. IC can be used to compare different effectiveness factors.<\/p>\n\n\n\n<p id=\"b693\"><strong>Step 3.&nbsp;<\/strong>Synthesize new factor<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u6839\u64daIC\u8a08\u7b97\u56e0\u5b50\u6b0a\u91cd<br>def ic_weight(data):<br>    data_= data.copy()<br>    ic = get_ic(data)  <br>    ic0 = ic.abs() # \u8a08\u7b97 IC\u7d55\u5c0d\u503c<br>    rolling_ic = ic0.rolling(12,min_periods=1).mean()  # \u6efe\u52d5 12\u4e2a\u6708<br>    weight = rolling_ic.div(rolling_ic.sum(axis=1),axis=0)  # \u8a08\u7b97 IC\u6b0a\u91cd,\u6309\u884c\u6c42\u548c,\u6309\u5217\u76f8\u9664<br>    ranks = get_rank(data)   # \u5f97\u5230\u5404\u56e0\u5b50\u7684\u6392\u5e8f\u6578\u64da<br>    <br>    score_ = OrderedDict()<br>    for date in weight.index.tolist():<br>        rank = ranks.loc[date]<br>        score = rank * weight.loc[date] <br>        score_[date] = score.sum(axis=1).to_frame().rename(columns={0: 'score'})<br>    <br>    score_df = pd.concat(score_.values(),keys=score_.keys())<br>    score_df = score_df.reset_index().rename({'level_0': '\u5e74\u6708\u65e5'}, axis=1)<br>    score_df = score_df.set_index(['\u5e74\u6708\u65e5','\u516c\u53f8'])<br>    data_ = data_.join(score_df)<br>    data_ = data_.reset_index()<br>    return data_data_ic = ic_weight(data_all)<br>data_ic['\u56e0\u5b50\u6bcf\u5e74\u5206\u7d44'] = data_ic.groupby('\u5e74\u6708\u65e5')['score'].rank().\\<br>    transform(lambda x: pd.qcut(x, 10, labels = range(1,11)))<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8009\"><span class=\"ez-toc-section\" id=\"Visualization\"><\/span><strong>Visualization<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"7332\"><strong>Step 1.&nbsp;<\/strong>Calculate portfolio\u2019s monthly return<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def arrange_group_return(tempt):<br>    tempt = tempt.groupby(['\u5e74\u6708\u65e5','\u56e0\u5b50\u6bcf\u5e74\u5206\u7d44'])[['\u6708\u6301\u6709\u5831\u916c\u7387']].mean().reset_index()<br>    tempt['\u6708\u6301\u6709\u5831\u916c\u7387'] = tempt['\u6708\u6301\u6709\u5831\u916c\u7387'] * 100<br>    tempt = pd.pivot_table(tempt, values='\u6708\u6301\u6709\u5831\u916c\u7387', index=['\u56e0\u5b50\u6bcf\u5e74\u5206\u7d44'] ,columns=['\u5e74\u6708\u65e5'])<br>    tempt.index = tempt.index.astype(str)<br>    tempt = tempt.T<br>    tempt = tempt.cumsum().dropna()<br>    tempt.index = tempt.index.astype(str).str[:7]<br>    <br>    return temptdata_ic = arrange_group_return(data_ic)data_ic.round(2)<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1_IQJwciwp2wVxEIS88H-iA.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"9005\"><strong>Step 2.&nbsp;<\/strong>Visualize the cumulative rate of return of the grouping<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def draw_group_return(tempt ,weight_method):<br>    fig = plt.figure(figsize = (14,7))<br>    ax = fig.add_subplot()<br>    <br>    ax.set_title(weight_method, <br>                 fontsize=16, <br>                 fontweight='bold')<br>    <br>    for i in tempt.columns:<br>        ax.plot(tempt[i], linewidth=2, alpha=0.8 , marker='o')<br>    <br>    ax.legend(tempt.columns,loc=2)<br>    <br>    plt.grid(axis='y')<br>    plt.xlabel('\u65e5\u671f', fontsize=18)<br>    plt.ylabel('\u5831\u916c\u7387 %',rotation=0, fontsize=18,labelpad=20)<br>    plt.xticks(fontsize=12)<br>    plt.yticks(fontsize=12)<br>    plt.show()draw_group_return(data_ic, 'IC\u52a0\u6b0a\u6cd5')<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1lBPTzGOsrd4mBK4WnNx5eQ.png\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1YCUB68hJ2Z4bKRwN43nalg.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u6bd4\u8f03 \u7b49\u6b0a\u91cd\u6cd5\u8207 IC\u52a0\u6b0a\u6cd5<br>data_equal_ir = pd.merge(<br>pd.DataFrame(data_equal['1']).rename({'1':'\u7b49\u6b0a\u91cd\u6cd5'}, axis=1),<br>pd.DataFrame(data_ic['1']).rename({'1':'IC\u52a0\u6b0a\u6cd5'}, axis=1),<br>how='inner',left_index=True, right_index=True)draw_group_return(data_equal_ir, '\u7b49\u6b0a\u91cd\u6cd5 vs IC\u52a0\u6b0a\u6cd5')<\/pre>\n\n\n\n<p id=\"19ea\">Compare the first group of the two weighting methods, that is, the group with the largest ROE and the smallest PE ratio.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1nPMeeu88A9aK7cXUHGPt0w.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"a92c\"><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=\"ef40\">The synthetic factor portfolio performance of PE ratio and ROE does not show a stable monotonicity and discrimination from the beginning of 2019 to the end of 2020. Monthly frequency transaction and quarterly ROE data are the reason why cumulative rate of return of the grouping is sometimes tangled. Meanwhile, The equal-weighted and the IC-weighted have no significant difference in different time periods.<\/p>\n\n\n\n<p id=\"8a91\">We can try to reduce the frequency of transactions in the future and backtest different factor combinations to find stable monotonicity and discriminative factor combinations, and then further optimize the factor weights. If readers are interested in other factor information, welcome to purchase the plan offered in TEJ E-Shop and find the factors with profitability, stability and interpretability!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"d8f9\"><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\/stocks-selection-by-esg-factors\/\" class=\"ek-link\">Stocks Selection by ESG Factors<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.tejwin.com\/en\/insight\/efficient-frontier\/\" class=\"ek-link\">Efficient Frontier<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5846\"><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:\/\/api.tej.com.tw\/index.html\" rel=\"noreferrer noopener\" target=\"_blank\">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>Does the weights setting affects the performance of the two-factor portfolio? Preface The common weights settings are equal-weighted and capitalization-weighted. The former treats all factors as the same, assigns equal weights to different factors, and synthesizes new factor values; the latter weights individual factors with capitalization-weighted to synthesize new factor values at first, assign different [&hellip;]<\/p>\n","protected":false},"featured_media":16582,"template":"","tags":[2574,2371,3008,2541],"insight-category":[690,50],"class_list":["post-16581","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-data-visualization","tag-python","tag-tejapi-quant","tag-2541","insight-category-data-analysis","insight-category-fintech"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/16581","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\/16581\/revisions"}],"predecessor-version":[{"id":16591,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/16581\/revisions\/16591"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/16582"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=16581"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=16581"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=16581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}