The project is to produce a figure with E/P ratio on the y-axis and average growth rate of earnings on the x-axis, with sizing the dots by log-firm-cap to see whether there is trend in the three variables.
The collected data of stock price, growth rate, E/P and market cap in the event period are listed in the following table: Data Summary
The graph of growth rate of earnings and E/P ratio is plotted in the following graph:
1.The EPS, market cap and earnings data are imported from Wrds UpdateCRSP/Compustat MergedCRSP/Compustat Merged - Fundamentals Annual
2.The stock price data are imported from "quantmod" packaget, data source is yahoo.finance.
1.Delete missing values in the original data.
2.Delete data whose release dates are before March of the next fiscal year.
3.Use "quantmod" package to extract price data from yahoo finnace to compute E/P ratio, in which earnings data are average value of last four years.
4.Compute average return of earnings in the last three years, and plot the graph.
library(data.table) library(quantmod) library(xts) library(lubridate) library(dplyr) library(ggplot2) data <- fread("C:/Users/bingj/Google Drive/2018 WINTER/Corporate Finance and Risk Management/Project6/oridata.csv") data <- na.omit(data) cmpyear <- data$fyear+1 cmpdate <- as.Date(paste(cmpyear,'-03-01',sep = "")) data$datadate <- as.Date(data$datadate) flag <- which(data$datadate<cmpdate) data <- data[-flag,] data <- data[!duplicated(data)] grate <- diff(data$ni)/data$ni[1:nrow(data)-1] sorted_data <- data %>% group_by(tic) %>% mutate(num = length(tic),meanmkt = mean(mkvalt)) flag <- which(sorted_data$num!=4) sorted_data <- sorted_data[-flag,] grate <- grate[-(flag-1)] flag <- seq(4,nrow(sorted_data),4) stockid <- sorted_data$tic[-flag] grate <- grate[-flag] grate <- as.data.frame(cbind(stockid,grate)) grate$grate <- as.numeric(as.character(grate$grate)) grate$stockid <- as.factor(grate$stockid) mrate <- tapply(grate$grate,grate$stockid,mean) tdate <- today() if (weekdays(tdate) == "Sunday"){ tdate <- tdate-1 }else if (weekdays(tdate) == "Monday"){ tdate <- tdate-2 } stocksum <- data.frame(mrate,price = 0,ep = 0,mkt = 0) for (i in 1:length(mrate)){ a <- try(getSymbols(names(mrate)[i],src = "yahoo",from = tdate-1,to = tdate,auto.assign = T)) if (class(a)!="try-error"){ stocksum[a,2] <- eval(parse(text = paste(a,"[1,6]",sep = ""))) stocksum[a,3] <- mean(unlist(sorted_data[sorted_data$tic==a,"epsfi"]))/stocksum[a,2] stocksum[a,4] <- as.numeric(unique(sorted_data[sorted_data$tic==a,"meanmkt"])) }else{ stocksum[i,2] <- NA stocksum[i,3] <- NA stocksum[i,4] <- NA } } stocksum <- na.omit(stocksum) flag1 <- which(stocksum$ep<quantile(stocksum$ep,0.1) | stocksum$ep>quantile(stocksum$ep,0.9)) flag2 <- which(stocksum$mrate<quantile(stocksum$mrate,0.1) | stocksum$mrate>quantile(stocksum$mrate,0.9)) stocksum <- stocksum[-unique(c(flag1,flag2)),] stocksum$mkt <- log(stocksum$mkt) p <- ggplot(data = stocksum,mapping = aes(x = mrate,y = ep,size = mkt))+geom_point(colour = "light pink")+xlab("Average Growth Rate of Earnings")+ylab("E/P Ratio") p
According to the definition of PEG, which is P/E ratio divided by average growth rate of earnings, we could discover that stocks which has a low value of PEG are usually undervalued, which means in the graph, points with high slope means the stocks are undervalued. As we can see, most points gather in the upper right area, and some points are in the upper left area, which are undervalued stocks. Some of these are large cap stocks and some are small. In addition, there are some overvalued stocks, most of them have small market size.