My Shiller Model

I had a quick look at my trusted Shiller Model which actually went to cash mid October this year. It continues to suggest holding onto cash. I attach the r code I used to build it, and I can apologize in advance for my sloppy coding, but it does most of the job. I plan on cleaning the code up in the near future.

Rplot05 Rplot04

library(quantmod)
library(PerformanceAnalytics)
library(gridExtra)
 
# I am pulling the data from Quandl and the MULTPL dataset. 
multpl<- read.csv('https://www.quandl.com/api/v1/datasets/MULTPL/SHILLER_PE_RATIO_MONTH.csv?trim_start=1881-01-01&trim_end=2014-12-17&auth_token=CqKCTyL4anWz5Zv', colClasses=c('Date'='Date'))
snp<- read.csv('https://www.quandl.com/api/v1/datasets/MULTPL/SP500_REAL_PRICE_MONTH.csv?trim_start=1871-01-01&trim_end=2014-12-17&auth_token=CqKCTyL4anWz5Zv', colClasses=c('Date'='Date'))
 
date<- snp$Date
values<- snp[,2]
snp.obj<- as.xts(values, order.by = as.Date(date, "%d/%m/%Y"))
snprets<- ROC(snp.obj, type = "discrete", n = 1)
 
date<- multpl$Date
values<- multpl[,2]
PE.obj<- as.xts(values, order.by = as.Date(date, "%d/%m/%Y"))
 
Shiller<- merge(snp.obj,PE.obj, snprets)
Shiller.sub = Shiller['1900-01-01::']
colnames(Shiller.sub) = c('S&P500','Shiller PE','S&P500 returns')
 
mean<- rollapply(PE.obj,48,mean)
sdsig<- rollapply(PE.obj,48,sd) + mean
over<- Lag(ifelse(PE.obj> sdsig,1,0))
 
pe_ret <- snprets * over
PEtimer<- cbind(pe_ret,snprets) 
colnames(PEtimer) = c('PE-Timer','Buy&Hold')
 
maxDrawdown(PEtimer)
grid.newpage(recording = FALSE)
grid.table(tail(over))
tail(over)
grid.newpage(recording = FALSE)
grid.table(table.AnnualizedReturns(PEtimer, Rf=0))
table.AnnualizedReturns(PEtimer, Rf= 0)
charts.PerformanceSummary(PEtimer, Rf = 0, main="Shiller PE Timer",geometric=FALSE)

Created by Pretty R at inside-R.org

One thought on “My Shiller Model

  1. Pingback: Operating Earnings Extrapolation & The Butterfly Effect | Sefirot Capital

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s