PDF Presentation

  • Published on

  • View

  • Download

Embed Size (px)


Programming in R


<ul><li><p>Programming in R Performance measurement of Growth and Value Stocks </p><p>By Rajat Agarwal, Gabriel Benedickt, Jishuo Ma, Helene Schrcksnadel, David Stein </p></li><li><p>Folder structure: oThe folder aHer unzipping has the following structure: </p><p>oProgrammingR_Project oData -&gt; Data les used in the enOre program oSaves -&gt; Directory for saving Outputs of the program oScripts -&gt; Directory for the main program les oPresentaOon -&gt; ExplanaOon of the program as a presentaOon </p><p>Programming in R 2 </p><p>How to run the program </p></li><li><p>Before running the scripts: oMake sure you update the staOc variables to your need </p><p>o E.g. !!! Update the le paths if run on a dierent computer </p><p>Programming in R 3 </p><p>How to run the program </p></li><li><p>oStructure of the scripts: oTo ensure userfriendlyness and prevent changing mulOple lines, staOc variables are dened at the top. You only need to change them once. </p><p>oTo prevent searching through many lines of codes, ALL funcOons are dened following the staOc variables </p><p>oThe sequenOal execuOon code is followed aHer the funcOons </p><p>oStructure: </p><p>Programming in R 4 </p><p>How to run the program </p></li><li><p>Running the scripts: o cleaningData.R o processingData.R o Running processingData.R ist NOT necessary as all it does is: Take the </p><p>COMPUSTAT data (/data/NA_Quart_1999-2014_Raw2.csv) and clean it for companies which have INCOMPLETE Ome series data. It then outputs a list of companies (saved in: /saves/cleanedNames.txt) </p><p>o This .txt can be used to do a query again in COMPUSTAT. But instead of downloading data for the enOre database, one can put in this list and download the data for thepreselected stocks, which have complete Ome series data. </p><p>o The cleaned data (/data/NA_Clean_Quart_1999-2014_AJEXQ-ATQ-CEQQ-CSHOQ-EPSPXQ-NIQ-DVPSPQ-PRCCQ.csv) is used in processingData.R </p><p>o All the data handling and computaOons take place in processingData.R o For recreaOng the results, running processingData.R ist sucient </p><p>Programming in R 5 </p><p>How to run the program </p></li><li><p>Overview </p><p>I. The TheoreOcal Concept 1. Growth versus Value Stocks 2. Data 3. Method </p><p>II. The Programm 1. Data PreparaOon 2. ClassicaOons: Growth Value &amp; Company Size 3. EvaluaOng Performance and Plolng </p><p>III. Conclusion, Outlook </p><p>Programming in R 6 </p></li><li><p>Growth vs. Value Stocks Which Investment Strategy is opOmal? Growth Stock o High-quality, successful company, seeks to achieve high earnings growth o Company may have the potenOal to achieve high earnings growth o Tends to invest earnings back into the company -&gt; zero or low dividend yield Value Stock o Company fallen out of favor in the marketplace o Bargain-priced compared with bookvalue, liquidaOon value o Much lower priced than similar companies in the same industry o Lower price may reect investor reacOon to company problems, which may raise </p><p>doubts about the companys longterm prospects The Primary measures to dene growth and value stocks are: Price-to-Earnings RaOo (in per share values) Price-to-Book RaOo (in per share values) </p><p>Programming in R 7 </p></li><li><p>Growth vs. Value Stocks </p><p>Programming in R 8 </p><p>Growth Stock (Growth Inves=ng) </p><p>Value Stock (Value Inves=ng ) </p><p>CharacterisOcs </p><p>High </p><p>P/E Ra=o (Price-to-Earning) P/B Ra=o (Price-to-Bookvalue) Companies with rapidly growing sales and earnings, higher-than-average valuaOon </p><p>Low </p><p>P/E Ra=o (Price-to-Earning) P/B Ra=o (Price-to-Bookvalue) Companies with lower-than-average sales, earnings and growth, tend to have higher dividend yields </p><p> Risks </p><p>Growth may not always be realized, unforseen events </p><p>Intrinsic Value may never be realized, Market may have correctly priced </p></li><li><p>Growth vs. Value Inves=ng The ra=onale behind Growth Inves=ng Thomas Rowe Price Jr. o Strong past performance indicates conOnued performance o Stocks will sell at higher price as companies conOnues to grow o No assurance forecast will be atained o Growth Stocks tend to lead bull markets </p><p>The ra=onale behind Value Inves=ng Warren Buet, Michael Larson o Out-of-favor company with sOll good fundamentals o Investors probably overreacted to negaOve events o Buy in the lower-priced stocks and sell later when companies bounce back, value recognized by </p><p>other investors. o Limited transparency, Market may have priced correctly o Value Stocks oHen cyclical industries, tend to do well early in an economic recovery </p><p>Mixed evidence in Research o Fama &amp; French Value Stocks have higher returns than Growth Stocks, dierence on average </p><p>returns, global poruolios, 1975-1995 is 7.6% per year, internaOonal CAPM cannot explain the value premium </p><p>o Bauman, Conover &amp; Miller 1990-2000, internaOonal stock markets, Value Stocks outperform Growth Stocks, except for the smallest rms, strong rm-size eect, </p><p>Programming in R 9 </p></li><li><p>Data </p><p>Source, Warton Research Data Services (WRDS) Range, All listed Northamerican companies, US$ Timeframe, 1999 2014, Quarterly Data Variables </p><p>Programming in R 10 </p><p>AJEXQ Adjustment Factor (for price of shares) </p><p>ATQ Total Assets (Bookvalue) </p><p>CSHOQ Common Shares Outstanding </p><p>NIQ Net Income (Earning) </p><p>PRCCQ Share Price </p></li><li><p>Method </p><p>1. Cleaning Data, accounOng for missing values 2. Reading Data, Ome series 3. Three subsets based on company capitalisaOon (in billion $) </p><p> small &lt; 2 | medium 2-10 | large &gt; 10 </p><p>4. IdenOfying Growth and Value ClassicaOon using P/E RaOo ClassicaOon using P/B RaOo </p><p>5. EvaluaOng Performance The getReturns() funcOon </p><p>6. Plolng and comparing Programming in R 11 </p></li><li><p>Cleaning Data </p><p>Programming in R 12 </p><p>gvkey (Company ID) </p><p>fyear </p><p>1234 1999 </p><p>1234 2000 </p><p>1234 2001 </p><p>1234 2002 </p><p>1234 2003 </p><p>1234 2004 </p><p>5678 2001 </p><p>5678 2002 </p><p>5678 2003 </p><p>rawCompNames: Aggregate( ... , by=list( ... $gvkey), FUN=sum): </p><p>gvkey (Company </p><p>ID) </p><p>Sum(gvkey) Sum(fyear) </p><p>1234 4936 12009 </p><p>5678 10712 6006 </p><p>-&gt; All Companies having a sum(fyear) == 12009 Have complete data. All others have incomplete data </p><p>Time series not matching </p></li><li><p>Cleaning Data </p><p>Programming in R 13 </p><p> Keep selected Companies in the Dataset Companies with complete quarterly observaOons for the years 1999-2014 Calculate the maximal quarterly number in the case of complete observaOons Calculate the quarterly number for each company Compare and Select </p></li><li><p>Processing Data </p><p>Programming in R 14 </p><p>AllMarketData </p><p>CategorizaOon </p><p>CategorizaOon </p><p>CategorizaOon </p><p>SmallCap </p><p>MidCap </p><p>LargeCap </p><p>Small Growth </p><p>Small Value </p><p>Mid Growth </p><p>Mid Value Large Growth </p><p>Large Value </p></li><li><p>Processing Data </p><p> Read the cleaned Data Use the cleaned Data to calculate the P/E RaOo Use the cleaned Data to calculate the P/B RaOo (for later CategorisaOon into Growth and Value Stocks) </p><p>Programming in R 15 </p></li><li><p>Classify based on capitaliza=on </p><p> Use the rst observaOon for every company, the rst quarter in the rst year and </p><p>check for NAs (Just to be sure) </p><p> Create subset SmallCap: companies with capitalisaOon &lt; 2 billion The same procedure is repeated for medium sized companies (midCap 2-10 billion) </p><p>and large companies (largeCap &gt; 10billion) </p><p>Programming in R 16 </p></li><li><p>Iden=fy Growth and Value </p><p> Using the subset smallCap order the company entries in this dataset according to the value of the P/E RaOo Determine Growth Stocks for the predened (staOc variable) percenOle Determine Value Stocks for the predened percenOle Same procedure for the subsets midCap and largeCap Same procedure using P/B for all subsets smallCap, midCap and largeCap </p><p>Programming in R 17 </p></li><li><p>Evaluate Performance </p><p> Evaluate the performance of each of the six category of </p><p>Stocks using the funcOon getReturns() </p><p>Programming in R 18 </p></li><li><p>The getReturns() func=on </p><p>Clean the data one last Ome -&gt; cleanDataFinally() Calculate the market weighted returns of individual stocks </p><p> Calculate the total return of the enOre collecOon of stocks </p><p>returnStock =P(t)</p><p>P(t = 0) individualMarketCaptotalMarketCap</p><p>returnPortfolio = returnStockAllCompanies</p><p>Programming in R 19 </p></li><li><p>The getReturns() func=on </p><p>Company idenOer Price Market Cap </p><p>InputData IndividualCompanyData </p><p>Company 1 (1050) </p><p>Company 2 (1257) </p><p>Programming in R 20 </p></li><li><p>The getReturns() func=on </p><p>returnStock =P(t)</p><p>P(t = 0) individualMarketCaptotalMarketCap = individualMarketCap</p><p>+ + Company 1 Loop 1 </p><p>Company 2 Loop 2 </p><p>Company 3 Loop 3 </p><p> Programming in R 21 </p></li><li><p>The getReturns() func=on </p><p>returnStock =P(t)</p><p>P(t = 0) individualMarketCaptotalMarketCap</p><p>Loop 1 Loop 2 Loop 3 Loop 4 Loop 5 returnIndexBasePrice </p><p>Programming in R 22 </p></li><li><p>The getReturns() func=on </p><p>returnStock =P(t)</p><p>P(t = 0) individualMarketCaptotalMarketCapreturnPortfolio = returnStockAllCompanies</p><p>Programming in R 23 </p></li><li><p>CleanDataFinally() </p><p>Programming in R 24 </p><p> Use the result from previous cleaning and account for missing values NAs Replace NAs with the next following value in the row if possible -&gt; EsOmateion of the </p><p>NA with the next closest data point in Ome </p></li><li><p>Results &amp; Conclusion </p><p>Programming in R 25 </p></li><li><p>Results &amp; Conclusion </p><p>Programming in R 26 </p></li><li><p>Results &amp; Conclusion </p><p>Programming in R 27 </p></li><li><p>Results &amp; Conclusion </p><p>Programming in R 28 </p></li><li><p>Results &amp; Conclusion </p><p>Programming in R 29 </p></li><li><p>Results &amp; Conclusion </p><p>Programming in R 30 </p></li><li><p>Results &amp; Conclusion </p><p>Programming in R 31 </p><p>In most of the Omes Value stocks clearly outperform growth stocks -&gt; An investor in the past (1999) should have persued an investment strategy in Value stocks in order to gain the highest returns. However: 1. The diniOons of Value and Growth stocks may dier from person </p><p>to person 2. Also the cleaning processes could have eliminated material data </p><p>for the analysis 3. The analysis is of historical data and thus is to be used cauOously </p><p>for predicOons. The analysis shows that value outperforms growth in a persiod of 1999 2014. </p></li><li><p>Sources </p><p># htp://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html # WDRS selecOon # htp://stocks.about.com/od/invesOngphilisophies/a/Groval061405.htm # htp://stackoverow.com/quesOons/3695677/how-to-nd-common-elements-from-mulOple-vectors # htp://stackoverow.com/quesOons/12389318/dollar-sign-before-a-variable # htp://stackoverow.com/quesOons/14860078/plot-mulOple-lines-data-series-each-with-unique-color-in-r # htp://stackoverow.com/quesOons/2564258/plot-2-graphs-in-same-plot-in-r # htp://stackoverow.com/quesOons/14883238/adding-simple-legend-to-plot-in-r </p><p>Programming in R 32 </p></li></ul>