Introduction

The PE Ratio is the ratio of the market price of a company’s stock to its earnings per share. It is one of the best known investment valuation indicators and one of the most widely used in the investment community. The following analysis will explore the PE Ratio for the US stock market since 1881.

Data Downloading and Processing

First, the necessary packages are uploaded. Quandl API provides economic and financial data, quantmod provides quantitative finance modelling tools, dygraphs is an R interface to the dygraphs JavaScript charting library useful to plot time series, PerformanceAnalytics provides tools for performance and risk analysis, ggplot for much nicer plotting.

library(Quandl)
library(PerformanceAnalytics)
library(dygraphs)
library(quantmod)
library(ggplot2)

The data analysed are the following time series (monthly):

  • S&P 500 Index, the index representing the US top 500 companies for market capitalization. The price from 1881 to 1949 is downloaded from http://www.econ.yale.edu/~shiller/data.htm, the online data collection that Robert Shiller used in his book Irrational Exuberance. The prices from 1950 until today are downloaded from Yahoo Finance.
  • PE Ratio, the Price Earnings Ratio based on trailing twelve months as reported earnings. Current PE is estimated from latest reported earnings and current market price. The series is downloaded through the Quandl API and the source database is multpl.com.
  • Shiller PE Ratio, the Price Earnings Ratio based on average earnings from the previous 10 years, also known as Cyclically Adjusted PE Ratio (CAPE Ratio). This methodology was introduced by Robert Shiller. The series is downloaded through the Quandl API and the source database is multpl.com.
# PE ratio
pe <- Quandl("MULTPL/SP500_PE_RATIO_MONTH")
pe <- xts(pe[,2],order.by = pe[,1])
colnames(pe) <- c('pe')
# PE ratio, Shiller method
peshiller <- Quandl("MULTPL/SHILLER_PE_RATIO_MONTH")
peshiller <- xts(peshiller[,2],order.by = peshiller[,1])
colnames(peshiller) <- c('peShiller')
# S&P500 index
spy1 <- read.csv('C:/Users/Flavio Angeli/Desktop/R files/spyShiller.csv')
spy1 <- xts(spy1[,2],order.by = as.Date(spy1[,1]))
colnames(spy1) <- c('spy')
getSymbols('^GSPC',from='1950-01-03')
## [1] "GSPC"
spy2 <- to.monthly(GSPC)
spy2 <- spy2[,'GSPC.Adjusted']
colnames(spy2) <- c('spy')
spy <- rbind(spy1['::1949'],spy2)
# merge series into the same table
data <- merge.xts(pe,peshiller,join = 'inner')
data <- merge.xts(data,spy,join = 'inner')

In the following chart, S&P 500 (logarithmic scale) and Shiller PE Ratio are plotted to analyse the two series. We can notice that S&P500 has an evident uptrend, whereas the PE Ratio tends to move in a range due to how the ratio is calculated.

# plot S&P500 and PE ratio
dygraph(data[,c('peShiller','spy')]) %>% dyRangeSelector() %>% 
                                        dySeries('spy',axis='y2') %>% 
                                        dyAxis('y2',logscale=T)

Moving on, six new columns are added to the data to calculate the S&P500 price return after different periods (1,2,3,5,10 and 20 years). The goal is to verify the presence of relationships between PE Ratio level and future returns.

# calculate returns after 1, 2, 3, 5, 10 and 20 years
data$r1 <- lag(round(ROC(data$spy,n=12),4),-12)
data$r2 <- lag(round(ROC(data$spy,n=24),4),-24)
data$r3 <- lag(round(ROC(data$spy,n=36),4),-36)
data$r4 <- lag(round(ROC(data$spy,n=60),4),-60)
data$r5 <- lag(round(ROC(data$spy,n=120),4),-120)
data$r6 <- lag(round(ROC(data$spy,n=240),4),-240)
head(data)
##               pe peShiller  spy      r1      r2      r3      r4      r5
## 1881-01-01 12.63     18.45 6.19 -0.0446 -0.0634 -0.1781 -0.1743 -0.2460
## 1881-02-01 12.85     18.13 6.17 -0.0636 -0.0827 -0.1482 -0.1520 -0.2305
## 1881-03-01 13.00     18.25 6.24 -0.0766 -0.0818 -0.1633 -0.1842 -0.2603
## 1881-04-01 13.23     17.92 6.22 -0.0734 -0.0579 -0.2064 -0.1946 -0.2244
## 1881-05-01 13.83     18.85 6.50 -0.1296 -0.1191 -0.3349 -0.2584 -0.2724
## 1881-06-01 14.00     19.01 6.58 -0.1471 -0.1227 -0.3889 -0.2258 -0.3051
##                r6
## 1881-01-01 0.1329
## 1881-02-01 0.1613
## 1881-03-01 0.1853
## 1881-04-01 0.2690
## 1881-05-01 0.1733
## 1881-06-01 0.2560

Data Analysis

In this analysis the PE Ratio considered is the one following Shiller’s method. As summarized in the following table, the ratio has a mean of 16.76 and moved in the range 4.78-44.19 since 1881.

# peShiller analysis
summary(data$peShiller)
##      Index              peShiller    
##  Min.   :1881-01-01   Min.   : 4.78  
##  1st Qu.:1915-02-22   1st Qu.:11.78  
##  Median :1949-04-16   Median :16.12  
##  Mean   :1949-04-16   Mean   :16.77  
##  3rd Qu.:1983-06-08   3rd Qu.:20.39  
##  Max.   :2017-08-01   Max.   :44.19

The following histogram shows the frequency of the PE Ratio observations. The black vertical line repsesents the mean, the red line represents the 3rd quantile and the green line represents the 1st quantile.

# peShiller analysis
hist(data$peShiller,breaks = 30,col='blue',main='Shiller PE Ratio (1881-2017)',
     xlab = 'Ratio')
abline(v=mean(data$peShiller,na.rm=T),col='black',lwd=2)
abline(v=quantile(data$peShiller,0.25,na.rm=T),col='green',lwd=2)
abline(v=quantile(data$peShiller,0.75,na.rm=T),col='red',lwd=2)

Using the quantile function it is also possible to find intervals that contain 80 or 90 per cent of the PE Ratio observations. For example, only 10 per cent of the observations are lower than 9.138, or only 5 per cent of the observations are higher than 27.587. This way we know where the PE Ratio can be considered extremely low or extremely high.

# peShiller quantiles
quantile(data$peShiller,na.rm=T,probs=c(0,0.05,0.1,0.25,0.5,0.75,0.9,0.95,1))
##      0%      5%     10%     25%     50%     75%     90%     95%    100% 
##  4.7800  7.8295  9.1390 11.7775 16.1200 20.3925 25.4110 27.6505 44.1900

PE Ratio and S&P500 Returns

Using the PE Ratio confidence intervals corresponding to 25 and 75 per cent, the dataset can be divided into three subsets:

  • low, observations when PE Ratio was lower than the 25 per cent quantile
  • middle, observations when PE Ratio was higher than the 25 per cent quantile and lower than the 75 per cent quantile
  • high, observations when the PE Ratio was higher than the 75 per cent quantile.

Having these subsets, their S&P500 returns after different periods can be compared to see if there is a relationships between level of PE Ratio and stock market return.

# subset based on high/low pe and compare returns after n months
low_pe <- quantile(data$peShiller,probs=0.25,na.rm=T)
high_pe <- quantile(data$peShiller,probs=0.75,na.rm=T)
low <- subset(data,peShiller<low_pe)
high <- subset(data,peShiller>high_pe)
middle <- subset(data,(peShiller>low_pe & peShiller<high_pe))
low_returns <- apply(low[,-c(1,3)],2,function(x)round(mean(x,na.rm=T),digits=2))
high_returns <- apply(high[,-c(1,3)],2,function(x)round(mean(x,na.rm=T),digits=2))
middle_returns <- apply(middle[,-c(1,3)],2,function(x)round(mean(x,na.rm=T),digits=2))
years <- c(NA,1,2,3,5,10,20)
pe_returns <- data.frame(years=years,lowPE=low_returns,
                        middlePE=middle_returns,highPE=high_returns)
pe_returns
##           years lowPE middlePE highPE
## peShiller    NA  9.38    16.04  25.61
## r1            1  0.11     0.03   0.02
## r2            2  0.21     0.06   0.02
## r3            3  0.28     0.10   0.04
## r4            5  0.46     0.17   0.08
## r5           10  0.75     0.39   0.19
## r6           20  1.34     0.83   0.62

The table shows that the returns are higher when the PE Ratio is low. For example, the average return after 3 years is 28 per cent when the PE Ratio is low, higher than average 4 per cent returned when the Ratio is high.

The significance of the difference between returns of the two subsets lowPE and highPE can be verified using a t.test. The following results confirm that there is a statistically significant difference between returns (after 10 years) when PE is low and returns when PE is high.

# significance test of the difference between lowPE and highPE returns (10 years)
t.test(low$r5,high$r5)
## 
##  Welch Two Sample t-test
## 
## data:  low$r5 and high$r5
## t = 17.414, df = 692.69, p-value < 2.2e-16
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.5009406 0.6282564
## sample estimates:
## mean of x mean of y 
## 0.7513449 0.1867463

The comparison can also be done considering the annualized return. Obviously the result si the same, low PE Ratio has higher returns. For example, investing in the S&P500 when the PE Ratio was low and holding it for ten years produced a 5.7 per cent annual return. Investing when the PE Ratio was high would have produced a 1.7 per cent annual return.

# compare annualizeed returns after n months
yearly_return <- function(r,n){
    y <- (1+r)^(1/n)-1
    return(round(y,digits = 4))
}
pe_returns_annualized <- pe_returns
for (j in c(2:4)){
    for (i in c(2:7)){
        pe_returns_annualized[i,j] <- yearly_return(pe_returns[i,j],pe_returns[i,1])
    }
}
pe_returns_annualized
##           years  lowPE middlePE  highPE
## peShiller    NA 9.3800  16.0400 25.6100
## r1            1 0.1100   0.0300  0.0200
## r2            2 0.1000   0.0296  0.0100
## r3            3 0.0858   0.0323  0.0132
## r4            5 0.0786   0.0319  0.0155
## r5           10 0.0576   0.0335  0.0175
## r6           20 0.0434   0.0307  0.0244

There seems to be an inverse relationships between PE Ratio and return. This is confirmed by the following chart, where PE Ratio and return after 10 years are plotted. It is clear that high PE Ratios correspond to lower returns, whereas low Ratios correspond to higher returns.

# plot PE Ratio and 10y return
ggplot(data=data,aes(peShiller,r5,color=peShiller))+
    geom_point()+
    ggtitle('PE Ratio and 10 years return')+
    ylab('10 years return')+xlab('Shiller PE Ratio')    

The inverse relationship is confirmed by the negative correlation between PE Ratio and return after 10 years, which is -0.39.

correlation <- with(na.omit(data),cor(peShiller,r5))
correlation
##                   r5
## peShiller -0.3920513

PE Ratio as Investment Strategy

Given the findings of the first part, the next step is to backtest an investment strategy based on the PE Ratio. In particular the strategy tested has the following rules:

  • buy when PE Ratio is lower than 11.7775, quantile corresponding to 20 per cent
  • hold the position until PE Ratio rises higher than 20.3925, quantile corresponding to 80 per cent, and than crosses below it.
# analyse investment strategy based on PE quantile levels
# buy when PE is low
# hold until PE is high or until PE goes high and back to medium
data2 <- data[,c('peShiller','spy')]
data2$r <- ROC(data2$spy)
low_pe <- quantile(data2$peShiller,probs=0.2)
high_pe <- quantile(data2$peShiller,probs=0.8)
data2$peLevel <- ifelse(data2$peShiller<low_pe,1,
                        ifelse(data2$peShiller>high_pe,3,2))
data2$signal <- 0
for (i in c(2:nrow(data2))){
    if (data2$peLevel[i]==1){data2$signal[i] <- 1}
    else if (data2$peLevel[i]==2){
            if (data2$peLevel[i-1]==3){data2$signal[i] <- 0}
            else {data2$signal[i] <- data2$signal[i-1]}
            }
    else if (data2$peLevel[i]==3){data2$signal[i] <- data2$signal[i-1]}
}
ptf_r <- lag(data2$signal)*data2$r

The following chart represent the performance of the PE Ratio investment strategy (black line) and the performance of the S&P500 Buy & Hold strategy (red line). The strategy based on buying when PE is low and sell when it is high seems to perform better than just buying and holding the S&P500. The strategy spends less time on the market and the drawdown seems lower.

# chart of ptf and market
merged_returns <- merge.xts(ptf_r,data2$r)
colnames(merged_returns) <- c('PE Strategy','Market')
charts.PerformanceSummary(merged_returns)

The following table shows that the investment strategy has higher annualized return, lower standard deviation and higher sharpe ratio. It seems it is performing better than the market.

# PE Ratio strategy and Market Performance Table
table.AnnualizedReturns(merged_returns)
##                           PE Strategy Market
## Annualized Return              0.0387 0.0325
## Annualized Std Dev             0.1160 0.1527
## Annualized Sharpe (Rf=0%)      0.3336 0.2127

Conclusion

The analysis conducted shows that there seems to be an inverse relation between PE Ratio and return after a few years. The strategy tested does not produce huge returns, but the lower standard deviation and higher Sharpe Ratio show that PE Ratio is a valuable indicator to reduce risk and improve investment strategies.