{"id":16620,"date":"2021-12-15T05:30:06","date_gmt":"2021-12-14T21:30:06","guid":{"rendered":"https:\/\/www.tejwin.com\/?post_type=insight&#038;p=16620"},"modified":"2024-06-17T11:49:36","modified_gmt":"2024-06-17T03:49:36","slug":"measure-the-companys-earnings-management","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/measure-the-companys-earnings-management\/","title":{"rendered":"Measure the company\u2019s earnings management"},"content":{"rendered":"\n<p id=\"b4e0\">Analyze the relationship between the company\u2019s earnings management and the earnings-price ratio group<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter is-resized caption-align-center\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1FKXin5Mu_Ey0npywq1At6Q.jpg\" alt=\"\" style=\"width:840px;height:559px\"\/><figcaption class=\"wp-element-caption\">Photo by&nbsp;<a href=\"https:\/\/unsplash.com\/@rupixen?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\" rel=\"noreferrer noopener\" target=\"_blank\">rupixen.com<\/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<ul class=\"wp-block-list\">\n<li>Difficulty\uff1a\u2605\u2605\u2605\u2606\u2606<\/li>\n\n\n\n<li>There is a higher earnings management in the specific earnings-price ratio groups.<\/li>\n\n\n\n<li>Advice: This article aims to compare the Discretionary Current Accrual (DCA) of companies in the same industry and individual company. If you want to understand more professional corporate credit risk model, you can further refer to\u00a0<a href=\"https:\/\/www.tejwin.com\/solution\/?cid=21\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">TEJ credit risk<\/a>.<\/li>\n\n\n\n<li>Linking to&nbsp;<a href=\"https:\/\/gist.github.com\/tej87681088\/698a7b6109567c073d70ae4b819e439c\" 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-69e55ea09db89\" 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-69e55ea09db89\"  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\/measure-the-companys-earnings-management\/#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\/measure-the-companys-earnings-management\/#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\/measure-the-companys-earnings-management\/#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\/measure-the-companys-earnings-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-5\" href=\"https:\/\/www.tejwin.com\/en\/insight\/measure-the-companys-earnings-management\/#Calculate_DCA_and_profit-to-cost_ratio_grouping\" >Calculate DCA and profit-to-cost ratio grouping<\/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\/measure-the-companys-earnings-management\/#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\/measure-the-companys-earnings-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\/measure-the-companys-earnings-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\/measure-the-companys-earnings-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\/measure-the-companys-earnings-management\/#Related_Link\" >Related Link<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"d43a\"><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=\"0cff\">Investors care about earnings which is one of the key indicators. future earnings trends will affect investors\u2019 willingness to hold stocks. If investors expect an increase in the company\u2019s earnings, they will improve their willingness to hold stocks. Earnings can be divided into cash and accruals, and accruals can be divided into discretionary and non-discretionary. Discretionary accruals is manipulated by the company\u2019s management. According to the past research, company management has incentives to achieve its proposed earnings target by accounting principles, Discretionary power, and so on.<\/p>\n\n\n\n<p id=\"1496\">In the case of information asymmetry between investors and company management, company management executes earnings management by discretionary accruals. Investors may overestimate the company\u2019s true earnings and the company\u2019s future stock price. Measuring the company\u2019s earnings management each year can help us avoid to hold companies with higher earnings management in the same industry.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"15e6\"><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=\"4615\">Windows OS and Jupyter Notebook<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u529f\u80fd\u6a21\u7d44<br>import pandas as pd<br>import numpy as np<br>import statsmodels.api as sm<br>import matplotlib.pyplot as plt<br>from scipy.stats import wilcoxon# TEJ API<br>import tejapi<br>tejapi<strong>.<\/strong>ApiConfig<strong>.<\/strong>api_key <strong>=<\/strong> 'Your key'<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"045c\"><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\/columns.html?idCode=TWN%2FANPRCSTD\" rel=\"noreferrer noopener\" target=\"_blank\">Security Characteristics Document<\/a>:the code of the database is(TWN\/EWNPRCSTD), which includes the codes of the current listed firms<\/li>\n\n\n\n<li><a href=\"https:\/\/api.tej.com.tw\/columns.html?idCode=TWN%2FAIM1A\" rel=\"noreferrer noopener\" target=\"_blank\">Consolidated Cumulative Financial Reports (All Industries)<\/a>:the code of the database is(TWN\/AIM1A), covering cumulative financial data of listed firms<\/li>\n\n\n\n<li><a href=\"https:\/\/api.tej.com.tw\/columns.html?idCode=TWN%2FAIFINA\" rel=\"noreferrer noopener\" target=\"_blank\">Consolidated Cumulative Financial Reports (All Industries \u2163)<\/a>:the code of the database is(TWN\/AIFINA)<\/li>\n\n\n\n<li><a href=\"https:\/\/api.tej.com.tw\/columns.html?idCode=TWN%2FAPRCD\" rel=\"noreferrer noopener\" target=\"_blank\">Daily Stock Price<\/a>:the code of the database is(TWN\/APRCD)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"8a48\"><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=\"cd49\"><strong>Step 1.&nbsp;<\/strong>Obtain industry code, financial data and stock price<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u532f\u5165 \u53f0\u7063\u4ea4\u6613\u6240\u6240\u6709\u4ee3\u78bc<br>code = tejapi.get(\"TWN\/EWNPRCSTD\",<br>                  paginate=True,<br>                  opts={'columns':['coid', 'mdate', 'stypenm','market','tseindnm']},<br>                  chinese_column_name=True)<br># \u532f\u5165 \u8ca1\u52d9\u8cc7\u6599<br>data = tejapi.get('TWN\/AIM1A',<br>                  coid = code['\u8b49\u5238\u78bc'].tolist(),<br>                  mdate= {'gte': '2012-01-01','lte':'2020-12-31'},<br>                  opts={'pivot':True,<br>                        'columns':['coid', 'mdate','0010','0130','R531',<br>                                   '7210','3100','0400','3990']},<br>                  chinese_column_name=True,<br>                          paginate=True)<br># \u532f\u5165 \u8ca1\u5831\u767c\u5e03\u65e5 <br>data_annouce = tejapi.get('TWN\/AIFINA',<br>                          coid = code['\u8b49\u5238\u78bc'].tolist(),<br>                          mdate= {'gte': '2012-01-01','lte':'2020-12-31'},<br>                          opts={'columns':['coid', 'mdate', 'a0003']},<br>                          chinese_column_name=True,<br>                          paginate=True)<\/pre>\n\n\n\n<p id=\"6cb3\">The stock price is the daily data. There are at least a thousand data for a stock. We can use the&nbsp;<code>paginate=True<\/code>&nbsp;parameter to obtain data, but the maximum total number of single transactions is 1,000,000. Therefore, we can group the companies into groups of 50 so that we can collect datas by&nbsp;<code>for loop<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">groups = []<br>while True:<br>    if len(security_list) &gt;= 50:<br>        groups.append(security_list[:50])<br>        security_list = security_list[50:]<br>    elif 0 &lt;= len(security_list) &lt; 50:<br>        groups.append(security_list)<br>        break# \u532f\u5165\u672a\u8abf\u6574\u80a1\u50f9<br>data_price = pd.DataFrame()    <br>for group in groups:<br>    data_price = data_price.append(tejapi.get('TWN\/APRCD',<br>                                              coid = group,<br>                                              mdate= {'gte': '2013-03-01','lte':'2021-3-31'},<br>                                              opts={'columns':['coid', 'mdate','close_d']},<br>                                              chinese_column_name = True,<br>                                              paginate = True)).reset_index(drop=True)<\/pre>\n\n\n\n<p id=\"7db6\"><strong>Step 2.&nbsp;<\/strong>Keep the closing price at the end of March and the end of the year data<\/p>\n\n\n\n<p id=\"9f75\">First, we rename column name in different dataframe so that we can avoid duplicate merge key column in merged output. Second, we only retain the stock data at the end of March each year in&nbsp;<code>data_price<\/code>&nbsp;because the denominator of the earnings-price ratio is limited to the closing price at the end of March each year. For the same reason, we only retain the year-end data in&nbsp;<code>data<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u8cc7\u6599\u524d\u8655\u7406<br>code = code.rename({'\u8b49\u5238\u78bc': '\u516c\u53f8'}, axis=1) # \u6539\u540d\u5b57<br>data = data.rename({'\u516c\u53f8\u4ee3\u78bc':'\u516c\u53f8'}, axis=1) # \u6539\u540d\u5b57<br>data_annouce = data_annouce.rename({'\u5e74\/\u6708':'\u8ca1\u5831\u5e74\u6708'}, axis=1) # \u6539\u540d\u5b57<br>data_price = data_price.rename({'\u8b49\u5238\u4ee3\u78bc':'\u516c\u53f8'}, axis=1) # \u6539\u540d\u5b57data_price['\u5e74'] = data_price['\u5e74\u6708\u65e5'].dt.year - 1 # \u6539\u6210\u8ca1\u5831\u5e74<br>data_price = data_price[data_price['\u5e74\u6708\u65e5'].dt.month == 3]<br>data_price = data_price.drop_duplicates(subset=['\u516c\u53f8','\u5e74'], keep='last') # \u53ea\u4fdd\u7559\u4e09\u6708\u5e95\u6536\u76e4\u50f9data['\u5e74'] = data['\u8ca1\u5831\u5e74\u6708'].dt.year<br>data = data.drop_duplicates(subset=['\u516c\u53f8','\u5e74'], keep='last') # \u53ea\u4fdd\u7559\u5e74\u5e95\u8cc7\u6599<\/pre>\n\n\n\n<p id=\"e75d\"><strong>Step 3.&nbsp;<\/strong>Combine data from different databases<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u5408\u4f75\u8cc7\u6599<br>data = data.merge(code[['TSE\u7522\u696d\u540d','\u516c\u53f8']] ,how = 'left' ,on=['\u516c\u53f8']) <br>data = data.merge(data_annouce,how = 'left' ,on=['\u516c\u53f8','\u8ca1\u5831\u5e74\u6708'])<br>data = data.merge(data_price[['\u516c\u53f8','\u5e74','\u6536\u76e4\u50f9(\u5143)']] ,how = 'left' ,on=['\u516c\u53f8','\u5e74'])<\/pre>\n\n\n\n<p id=\"1a7f\">We merge the financial report and the stock price data into one by company name and date.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1x28DMCSw1LU21i-w404A8w.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"b97f\"><span class=\"ez-toc-section\" id=\"Calculate_DCA_and_profit-to-cost_ratio_grouping\"><\/span><strong>Calculate DCA and profit-to-cost ratio grouping<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"11e7\"><strong>Step 1.&nbsp;<\/strong>Prepare financial information required for DCA<\/p>\n\n\n\n<p id=\"5bf4\">We use Jones (1991) model in this article. Jones researched the part of accruals affected by the economic environment is related to sales; the gross amount of depreciable assets is related to non-discretionary depreciation expenses in total accruals. Meanwhile, we have a sort-out in the different industry business models and scale companies.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u8a08\u7b97 DCA data['Total accrual'] = (data['\u5e38\u7e8c\u6027\u7a05\u5f8c\u6de8\u5229'] - data['\u4f86\u81ea\u71df\u904b\u4e4b\u73fe\u91d1\u6d41\u91cf']) * data['DCA \u524d\u671f\u8cc7\u7522\u7e3d\u984d\u5012\u6578'] # Ydata['DCA \u524d\u671f\u8cc7\u7522\u7e3d\u984d\u5012\u6578'] = 1 \/ data.groupby('\u516c\u53f8')['\u8cc7\u7522\u7e3d\u984d'].shift(1) # X0<br>data['DCA \u71df\u696d\u6536\u5165\u5dee'] = data.groupby('\u516c\u53f8')['\u71df\u696d\u6536\u5165\u6de8\u984d'].diff() * data['DCA \u524d\u671f\u8cc7\u7522\u7e3d\u984d\u5012\u6578'] # X1<br>data['DCA \u4e0d\u52d5\u7522\u5ee0\u623f\u53ca\u8a2d\u5099'] = data['\u4e0d\u52d5\u7522\u5ee0\u623f\u53ca\u8a2d\u5099'] * data['DCA \u524d\u671f\u8cc7\u7522\u7e3d\u984d\u5012\u6578'] # X2<br>data['DCA \u71df\u696d\u6536\u5165\u5dee - \u61c9\u6536\u5dee'] = (data.groupby('\u516c\u53f8')['\u71df\u696d\u6536\u5165\u6de8\u984d'].diff() - \\<br>                           data.groupby('\u516c\u53f8')['\u61c9\u6536\u5e33\u6b3e\u53ca\u7968\u64da'].diff()) * data['DCA \u524d\u671f\u8cc7\u7522\u7e3d\u984d\u5012\u6578'] # X1<\/pre>\n\n\n\n<p id=\"fd3f\">We sort firms into 14 groups based on similar industry so that we avoid too few firms in a single industry and unreliable statistics. Meanwhile, we run regression by group to reduce industry difference and use the previous period of total asset to deflate other financial factors to reduce size difference.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u5206\u7d44\u76f8\u4f3c\u7522\u696d<br>data['\u7522\u696d\u5206\u7d44'] = \\<br>    np.select([(data['TSE\u7522\u696d\u540d'].isin([\"\u98df\u54c1\u5de5\u696d\",\"\u7d21\u7e54\u7e96\u7dad\",\"\u9020\u7d19\u5de5\u696d\"])) ,<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u5851\u81a0\u5de5\u696d\",\"\u6a61\u81a0\u5de5\u696d\",\"\u5316\u5b78\u5de5\u696d\",\"\u6cb9\u96fb\u71c3\u6c23\u696d\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u6c7d\u8eca\u5de5\u696d\",\"\u92fc\u9435\u5de5\u696d\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u96fb\u6a5f\u6a5f\u68b0\",\"\u96fb\u5668\u96fb\u7e9c\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u6c34\u6ce5\u5de5\u696d\",\"\u5efa\u6750\u71df\u9020\",\"\u73bb\u7483\u9676\u74f7\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u8cc7\u8a0a\u670d\u52d9\u696d\",\"\u96fb\u5b50\u5546\u52d9\",\"\u8cbf\u6613\u767e\u8ca8\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u89c0\u5149\u4e8b\u696d\",\"\u822a\u904b\u696d\",\"\u6587\u5316\u5275\u610f\u696d\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u751f\u6280\u91ab\u7642\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u5149\u96fb\u696d\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u534a\u5c0e\u9ad4\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u96fb\u8166\u53ca\u9031\u908a\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u901a\u4fe1\u7db2\u8def\u696d\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u96fb\u5b50\u96f6\u7d44\u4ef6\"])),<br>               (data['TSE\u7522\u696d\u540d'].isin([\"\u5176\u4ed6\u96fb\u5b50\u696d\",\"\u96fb\u5b50\u901a\u8def\u696d\",\"\u8fb2\u696d\u79d1\u6280\",\"\u5176\u4ed6\"]))],<br>              list(range(14)), default = np.nan)<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1DDJszZ0RRFWCXRZkxB-RiA.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"5843\"><strong>Step 2.&nbsp;<\/strong>Calculate annual DCA in different industries and firms<\/p>\n\n\n\n<p id=\"8328\">Total assets, operating income, and real estate plant and equipment are explanatory variables, and accruals is response variable. We get the observed accruals and the actual accruals by regression analysis. DCA is actual accruals minus observed accruals. If DCA is greater than 0, it means the company\u2019s earnings management is greater than the company\u2019s industry.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u8a08\u7b97 DCA<br>def regress(data):<br>    '''<br>    \u6bcf\u5e74\u4e0d\u540c\u7522\u696d\u5206\u7d44\u8dd1\u8ff4\u6b78\uff0c\u4e3b\u8981\u7528\u4f86\u7372\u5f97\u8ff4\u6b78\u4fc2\u6578<br>    '''<br>    data = data[['Total accrual','DCA \u524d\u671f\u8cc7\u7522\u7e3d\u984d\u5012\u6578','DCA \u71df\u696d\u6536\u5165\u5dee','DCA \u4e0d\u52d5\u7522\u5ee0\u623f\u53ca\u8a2d\u5099']].dropna()<br>    Y = data['Total accrual']<br>    X = data[['DCA \u524d\u671f\u8cc7\u7522\u7e3d\u984d\u5012\u6578','DCA \u71df\u696d\u6536\u5165\u5dee','DCA \u4e0d\u52d5\u7522\u5ee0\u623f\u53ca\u8a2d\u5099']]<br>    X = X.rename(columns={\"DCA \u524d\u671f\u8cc7\u7522\u7e3d\u984d\u5012\u6578\": \"alpha \u524d\u671f\u8cc7\u7522\u7e3d\u984d\u5012\u6578\",<br>                          \"DCA \u71df\u696d\u6536\u5165\u5dee\": \"alpha \u71df\u696d\u6536\u5165\u5dee\",<br>                          \"DCA \u4e0d\u52d5\u7522\u5ee0\u623f\u53ca\u8a2d\u5099\": \"alpha \u4e0d\u52d5\u7522\u5ee0\u623f\u53ca\u8a2d\u5099\",})<br>    try:<br>        result = sm.OLS(Y, X).fit()<br>        return result.params<br>    except ValueError:  <br>        passdata = data.merge(data.groupby(['\u8ca1\u5831\u5e74\u6708','\u7522\u696d\u5206\u7d44']).apply(regress).reset_index(),<br>                        how = 'left' ,on = ['\u8ca1\u5831\u5e74\u6708','\u7522\u696d\u5206\u7d44'])data['Normal accrual'] = (data['alpha \u524d\u671f\u8cc7\u7522\u7e3d\u984d\u5012\u6578'] * data['DCA \u524d\u671f\u8cc7\u7522\u7e3d\u984d\u5012\u6578'] \\<br>                          + data['alpha \u71df\u696d\u6536\u5165\u5dee'] * data['DCA \u71df\u696d\u6536\u5165\u5dee - \u61c9\u6536\u5dee'] \\<br>                              + data['alpha \u4e0d\u52d5\u7522\u5ee0\u623f\u53ca\u8a2d\u5099'] * data['DCA \u4e0d\u52d5\u7522\u5ee0\u623f\u53ca\u8a2d\u5099'])data['DCA'] = data['Total accrual'] - data['Normal accrual']<\/pre>\n\n\n\n<p id=\"b5e3\"><strong>Step 3.&nbsp;<\/strong>Profit-to-cost ratio grouping<\/p>\n\n\n\n<p id=\"5431\">We sort firms into groups based on earnings-price ratio to analyze the specified group whether there are a significant abnormality DCA. That is, there are a significant abnormality earnings management in the specified group.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u8a08\u7b97\u76ca\u672c\u6bd4\uff0c\u4e26\u4ee50.0125\u5206\u7d44\u3002<br>def cal_EP_label():<br>    '''\u7372\u5f97 EP ratio\u5206\u7d44\u4e0b\u7684\u516c\u53f8\u6578\uff0cnum=33\uff0c\u52070.025'''<br>    label = np.linspace(-0.2, 0.2, num=33).tolist()<br>    label = [ '%.4f' % elem for elem in label ]<br>    label.insert(0,-np.inf)<br>    label.insert(len(label),np.inf)<br>    label = np.array(label, dtype=float)<br>    return labeldata['\u76ca\u672c\u6bd4'] = data['\u6bcf\u80a1\u76c8\u9918'] \/ data['\u6536\u76e4\u50f9(\u5143)']<br>data['\u76ca\u672c\u6bd4\u5206\u7d44'] = pd.cut(data['\u76ca\u672c\u6bd4'],bins = cal_EP_label() ,right=True)<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1dsHRxHM5PyI2rFRExFlkWg.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"cd00\"><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=\"b7f1\"><strong>Step 1.&nbsp;<\/strong>Create<strong>&nbsp;<\/strong>a graph to analyze the distribution of earnings-price ratio<\/p>\n\n\n\n<p id=\"11ca\">In the figure below, there is a significant difference between the number of companies whose earnings-price ratio distribution is in (-0.0125, 0.0) and (0.0, 0.0125]. Does this indicate that the company\u2019s management have loss aversion when they face with earnings losses? Therefore, the company\u2019s management is unwilling to explain the losses to the shareholders and they have an incentive to manipulate the EPS from negative to positive.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#%% \u505a\u5716 \u89c0\u5bdf\u76ca\u672c\u6bd4\u5206\u7d44\u72c0\u6cc1fig = plt.figure(figsize = (12,9))<br>ax = fig.add_subplot()factor = data.groupby(['\u76ca\u672c\u6bd4\u5206\u7d44'])['\u516c\u53f8'].count().reset_index()['\u76ca\u672c\u6bd4\u5206\u7d44'].astype(str)<br>value = data.groupby(['\u76ca\u672c\u6bd4\u5206\u7d44'])['\u516c\u53f8'].count().reset_index()['\u516c\u53f8']<br>ax.bar(factor,value,fill = '#eb3434',edgecolor = 'black')<br>ax.bar('(0.0, 0.0125]',value[17],fill = '#eb344f',edgecolor = 'black')<br>ax.set_title('Earnings-Price Distribution', <br>             fontsize=16, <br>             fontweight='bold')<br>ax.set_xticks(['(-0.15, -0.138]','(-0.112, -0.1]','(-0.075, -0.0625]','(-0.0375, -0.025]','(0.0, 0.0125]',<br>              '(0.0375, 0.05]','(0.075, 0.0875]','(0.112, 0.125]','(0.15, 0.162]'])<br>plt.grid(axis='y')<br>plt.xticks(rotation=30)<br>plt.xlabel('EP Interval',fontsize=12)<br>plt.ylabel('Frequency',fontsize=12, rotation=0)<br>plt.show()<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1_1Bwb6llAo99vohnKnP1jLKA.png\" alt=\"\"\/><\/figure>\n\n\n\n<p id=\"6aa7\"><strong>Step 2.&nbsp;<\/strong>Make a table to observe the relationship between the earnings-price ratio groups and the degree of earnings management<\/p>\n\n\n\n<p id=\"de51\">The median test of Wilcoxon signed-rank test is performed on the earnings-price ratio groups, and it was found that the median of DCA of all companies is -0.002 being significantly different from 0. However, the company\u2019s earnings-price ratio is in (-0.0125, 0.0) and (0.0, 0.0125), the median DCA is 0.004 being significantly different from 0. It can be seen that the compnay\u2019s earnings-price ratio is in (0.0, 0.0125). the companys with earnings management is widespread.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">def cal_wilcoxon(group):<br>    return pd.DataFrame({'DCA': group.median(),<br>                         'p-value': wilcoxon(group)[1]}, index = [0])def add_star(df,p_value):<br>    '''<br>    p-values of the Wilcoxon signed rank test &lt;= 0.01\uff0c\u5247\u4fc2\u6578\u65b0\u589e***<br>    0.01 &lt; p-values of the Wilcoxon signed rank test &lt;= 0.05\uff0c\u5247\u4fc2\u6578\u65b0\u589e**<br>    0.1 &lt; p-values of the Wilcoxon signed rank test &lt;= 0.01\uff0c\u5247\u4fc2\u6578\u65b0\u589e*<br>    '''<br>    df = np.select([(p_value &lt;= 0.01),<br>                      (p_value &gt; 0.01) &amp; (p_value &lt;= 0.05),<br>                      (p_value &gt; 0.05) &amp; (p_value &lt;= 0.1)],<br>                     [df.apply(lambda x: '%.3f'%x + '***'),<br>                      df.apply(lambda x: '%.3f'%x + '**'),<br>                      df.apply(lambda x: '%.3f'%x + '*')],<br>                     default = df.apply(lambda x: '%.3f'%x))<br>    return dfdef run_data_cal_wilcoxon(df):<br>    '''p-values of the Wilcoxon signed rank test for one sample median DCA equal to 0'''<br>    finaldf = pd.DataFrame()<br>    <br>    for data in df:<br>        <br>        temp = data.dropna(subset=['DCA']).groupby('\u5e74')['DCA'].\\<br>            apply(cal_wilcoxon).reset_index(level=1, drop=True)<br>        <br>        temp.loc['All','DCA'] = data.dropna(subset=['DCA'])['DCA'].median()<br>        temp.loc['All','p-value'] = wilcoxon(data.dropna(subset=['DCA'])['DCA'])[1]<br>        <br>        temp['DCA'] = add_star(temp['DCA'],temp['p-value'])<br>        temp['p-value'] = temp['p-value'].apply(lambda x: '(' + '%.3f'%x + ')')<br>    <br>        finaldf = pd.concat([finaldf, temp], axis=1)   <br>        <br>    return finaldfTable = run_data_cal_wilcoxon([data,<br>                               data[data['\u76ca\u672c\u6bd4\u5206\u7d44'].astype(str).isin(['(-0.025, 0.0]'])],<br>                               data[data['\u76ca\u672c\u6bd4\u5206\u7d44'].astype(str).isin(['(0.0, 0.025]'])]])<\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter\"><img decoding=\"async\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/1QzmNVvbNRqRHJjGqwGntUg.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1ec5\"><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=\"e244\">\u300cLosses loom larger than gains\u300d meaning that people by nature are aversive to losses. Therefore, when a company\u2019s management faces a small loss, there is a very high incentive to manipulate earnings management through Discretionary Accruals. they can change EPS from negative to positive to fit the expectations of shareholders and investors in the capital market.<\/p>\n\n\n\n<p id=\"7759\">In this paper, we can identify which companies\u2019 DCA being significantly higher than the industry average DCA and check whether the company\u2019s earnings-price ratio is in the range of (-0.0125, 0.0) and (0.0, 0.0125). If company\u2019s earnings-price ratio is in the range of (-0.0125, 0.0) and (0.0, 0.0125) and DCA is higher than 0, the company most likely have an earnings management.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"02e0\"><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\/698a7b6109567c073d70ae4b819e439c#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=\"ce4f\"><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=\"http:\/\/lawdata.com.tw\/tw\/detail.aspx?no=376403\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">Whether there is an<\/a> <a href=\"http:\/\/lawdata.com.tw\/tw\/detail.aspx?no=376403\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">\u300caccrual anomaly\u300d in Taiwan\u2019s stock market<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/journal_detail?journal_id=2021050504\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">Trial establishment of Window Dressing Indicators\u2014 Invalid revenue, bubble assets<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"ea92\"><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>Analyze the relationship between the company\u2019s earnings management and the earnings-price ratio group Preface Investors care about earnings which is one of the key indicators. future earnings trends will affect investors\u2019 willingness to hold stocks. If investors expect an increase in the company\u2019s earnings, they will improve their willingness to hold stocks. Earnings can be [&hellip;]<\/p>\n","protected":false},"featured_media":16621,"template":"","tags":[2574,2371,3008,2541],"insight-category":[690,50],"class_list":["post-16620","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\/16620","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\/16620\/revisions"}],"predecessor-version":[{"id":24253,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/16620\/revisions\/24253"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/16621"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=16620"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=16620"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=16620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}