Upload
rajat-agarwal
View
220
Download
0
Embed Size (px)
DESCRIPTION
Programming in R
Citation preview
Programming in R Performance measurement of Growth and Value Stocks
By Rajat Agarwal, Gabriel Benedickt, Jishuo Ma, Helene Schröcksnadel, David Stein
Folder structure: o The folder aHer unzipping has the following structure:
o ProgrammingR_Project o Data -‐> Data files used in the enOre program o Saves -‐> Directory for saving Outputs of the program o Scripts -‐> Directory for the main program files o PresentaOon -‐> ExplanaOon of the program as a presentaOon
Programming in R 2
How to run the program
Before running the scripts: o Make sure you update the staOc variables to your need
o E.g. !!! Update the file paths if run on a different computer
Programming in R 3
How to run the program
o Structure of the scripts: o To ensure userfriendlyness and prevent changing mulOple lines, staOc variables are defined at the top. You only need to change them once.
o To prevent searching through many lines of codes, ALL funcOons are defined following the staOc variables
o The sequenOal execuOon code is followed aHer the funcOons
o Structure:
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 sufficient
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. ClassificaOons: 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 reflect investor reacOon to company problems, which may raise
doubts about the company‘s longterm prospects The Primary measures to define 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 )
CharacterisOcs
High
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
Low
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
Risks
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 Buffet, 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, difference 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 firms, strong firm-‐size effect,
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 ClassificaOon using P/E RaOo ClassificaOon 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)
fyear
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
ID)
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
AllMarketData
CategorizaOon
CategorizaOon
CategorizaOon
SmallCap
MidCap
LargeCap
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 first observaOon for every company, the first quarter in the first 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 predefined (staOc variable) percenOle § Determine Value Stocks for the predefined 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 idenOfier 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)×individualMarketCaptotalMarketCap
returnPortfolio = 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
Programming in R 26
Results & Conclusion
Programming in R 27
Results & Conclusion
Programming in R 28
Results & Conclusion
Programming in R 29
Results & Conclusion
Programming in R 30
Results & Conclusion
Programming in R 31
In most of the Omes Value stocks clearly outperform growth stocks -‐> 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 difiniOons of Value and Growth stocks may differ from person
to person 2. Also the cleaning processes could have eliminated material data
for the analysis 3. The analysis is of historical data and thus is to be used cauOously
for predicOons. The analysis shows that value outperforms growth in a persiod of 1999 – 2014.
Sources
# htp://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html # WDRS selecOon # htp://stocks.about.com/od/invesOngphilisophies/a/Groval061405.htm # htp://stackoverflow.com/quesOons/3695677/how-‐to-‐find-‐common-‐elements-‐from-‐mulOple-‐vectors # htp://stackoverflow.com/quesOons/12389318/dollar-‐sign-‐before-‐a-‐variable # htp://stackoverflow.com/quesOons/14860078/plot-‐mulOple-‐lines-‐data-‐series-‐each-‐with-‐unique-‐color-‐in-‐r # htp://stackoverflow.com/quesOons/2564258/plot-‐2-‐graphs-‐in-‐same-‐plot-‐in-‐r # htp://stackoverflow.com/quesOons/14883238/adding-‐simple-‐legend-‐to-‐plot-‐in-‐r
Programming in R 32