PDF Presentation

Embed Size (px)


Programming in R

Text of PDF Presentation

  • Programming in R Performance measurement of Growth and Value Stocks

    By Rajat Agarwal, Gabriel Benedickt, Jishuo Ma, Helene Schrcksnadel, David Stein

  • Folder structure: oThe folder aHer unzipping has the following structure:

    oProgrammingR_Project oData -> Data les used in the enOre program oSaves -> Directory for saving Outputs of the program oScripts -> Directory for the main program les oPresentaOon -> ExplanaOon of the program as a presentaOon

    Programming in R 2

    How to run the program

  • Before running the scripts: oMake sure you update the staOc variables to your need

    o E.g. !!! Update the le paths if run on a dierent computer

    Programming in R 3

    How to run the program

  • 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.

    oTo prevent searching through many lines of codes, ALL funcOons are dened following the staOc variables

    oThe sequenOal execuOon code is followed aHer the funcOons


    Programming in R 4

    How to run the program

  • Running the scripts: o cleaningData.R o processingData.R o Running processingData.R ist NOT necessary as all it does is: Take the

    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)

    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.

    o The cleaned data (/data/NA_Clean_Quart_1999-2014_AJEXQ-ATQ-CEQQ-CSHOQ-EPSPXQ-NIQ-DVPSPQ-PRCCQ.csv) is used in processingData.R

    o All the data handling and computaOons take place in processingData.R o For recreaOng the results, running processingData.R ist sucient

    Programming in R 5

    How to run the program

  • Overview

    I. The TheoreOcal Concept 1. Growth versus Value Stocks 2. Data 3. Method

    II. The Programm 1. Data PreparaOon 2. ClassicaOons: Growth Value & Company Size 3. EvaluaOng Performance and Plolng

    III. Conclusion, Outlook

    Programming in R 6

  • 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 -> 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

    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)

    Programming in R 7

  • Growth vs. Value Stocks

    Programming in R 8

    Growth Stock (Growth Inves=ng)

    Value Stock (Value Inves=ng )



    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/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


    Growth may not always be realized, unforseen events

    Intrinsic Value may never be realized, Market may have correctly priced

  • 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

    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

    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

    Mixed evidence in Research o Fama & French Value Stocks have higher returns than Growth Stocks, dierence on average

    returns, global poruolios, 1975-1995 is 7.6% per year, internaOonal CAPM cannot explain the value premium

    o Bauman, Conover & Miller 1990-2000, internaOonal stock markets, Value Stocks outperform Growth Stocks, except for the smallest rms, strong rm-size eect,

    Programming in R 9

  • Data

    Source, Warton Research Data Services (WRDS) Range, All listed Northamerican companies, US$ Timeframe, 1999 2014, Quarterly Data Variables

    Programming in R 10

    AJEXQ Adjustment Factor (for price of shares)

    ATQ Total Assets (Bookvalue)

    CSHOQ Common Shares Outstanding

    NIQ Net Income (Earning)

    PRCCQ Share Price

  • Method

    1. Cleaning Data, accounOng for missing values 2. Reading Data, Ome series 3. Three subsets based on company capitalisaOon (in billion $)

    small < 2 | medium 2-10 | large > 10

    4. IdenOfying Growth and Value ClassicaOon using P/E RaOo ClassicaOon using P/B RaOo

    5. EvaluaOng Performance The getReturns() funcOon

    6. Plolng and comparing Programming in R 11

  • Cleaning Data

    Programming in R 12

    gvkey (Company ID)


    1234 1999

    1234 2000

    1234 2001

    1234 2002

    1234 2003

    1234 2004

    5678 2001

    5678 2002

    5678 2003

    rawCompNames: Aggregate( ... , by=list( ... $gvkey), FUN=sum):

    gvkey (Company


    Sum(gvkey) Sum(fyear)

    1234 4936 12009

    5678 10712 6006

    -> All Companies having a sum(fyear) == 12009 Have complete data. All others have incomplete data

    Time series not matching

  • Cleaning Data

    Programming in R 13

    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

  • Processing Data

    Programming in R 14








    Small Growth

    Small Value

    Mid Growth

    Mid Value Large Growth

    Large Value

  • Processing Data

    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)

    Programming in R 15

  • Classify based on capitaliza=on

    Use the rst observaOon for every company, the rst quarter in the rst year and

    check for NAs (Just to be sure)

    Create subset SmallCap: companies with capitalisaOon < 2 billion The same procedure is repeated for medium sized companies (midCap 2-10 billion)

    and large companies (largeCap > 10billion)

    Programming in R 16

  • Iden=fy Growth and Value

    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

    Programming in R 17

  • Evaluate Performance

    Evaluate the performance of each of the six category of

    Stocks using the funcOon getReturns()

    Programming in R 18

  • The getReturns() func=on

    Clean the data one last Ome -> cleanDataFinally() Calculate the market weighted returns of individual stocks

    Calculate the total return of the enOre collecOon of stocks

    returnStock =P(t)

    P(t = 0) individualMarketCaptotalMarketCap

    returnPortfolio = returnStockAllCompanies

    Programming in R 19

  • The getReturns() func=on

    Company idenOer Price Market Cap

    InputData IndividualCompanyData

    Company 1 (1050)

    Company 2 (1257)

    Programming in R 20

  • The getReturns() func=on

    returnStock =P(t)

    P(t = 0) individualMarketCaptotalMarketCap = individualMarketCap

    + + Company 1 Loop 1

    Company 2 Loop 2

    Company 3 Loop 3

    Programming in R 21

  • The getReturns() func=on

    returnStock =P(t)

    P(t = 0) individualMarketCaptotalMarketCap

    Loop 1 Loop 2 Loop 3 Loop 4 Loop 5 returnIndexBasePrice

    Programming in R 22

  • The getReturns() func=on

    returnStock =P(t)

    P(t = 0) individualMarketCaptotalMarketCapreturnPortfolio = returnStockAllCompanies

    Programming in R 23

  • CleanDataFinally()

    Programming in R 24

    Use the result from previous cleaning and account for missing values NAs Replace NAs with the next following value in the row if possible -> EsOmateion of the

    NA with the next closest data point in Ome

  • Results & Conclusion

    Programming in R 25

  • Results & Conclusion