Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Where are RUT fat tails

View rut where are fat tails.r
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
require(lattice)
require(latticeExtra)
require(directlabels)
require(reshape2)
require(quantmod)
require(PerformanceAnalytics)
 
#I will use a csv file of weekly returns to get more history
#but if you do not have access to that then use getSymbols for data to 1987
#getSymbols("^RUT",from="1900-01-01")
#then get weekly ROC
#rut.return <- ROC(to.weekly(RUT)[,4],type="discrete",n=1)
 
RUT <- read.csv("rut.csv",stringsAsFactors=FALSE)
RUT <- as.xts(RUT[,2],order.by=as.Date(RUT[,1]))
rut.return <- ROC(RUT,type="discrete",n=1)
 
#get skewness for short and long rolling periods
skew.short <- apply.rolling(rut.return,FUN=skewness,width=20,trim=FALSE)
colnames(skew.short) <- "roll20w"
skew.long <- apply.rolling(rut.return,FUN=skewness,width=250,trim=FALSE)
colnames(skew.long) <- "roll250w"
 
#do the same for kurtosis
kurtosis.short <- apply.rolling(rut.return,FUN=kurtosis,width=20,trim=FALSE)
colnames(kurtosis.short) <- "roll20w"
kurtosis.long <- apply.rolling(rut.return,FUN=kurtosis,width=250,trim=FALSE)
colnames(kurtosis.long) <- "roll250w"
 
#combine into data frame so we can melt as plot with lattice
skew <- as.data.frame(cbind(index(skew.short),coredata(merge(skew.short,skew.long))))
#melt to please lattice
skew.melt <- melt(skew,id.vars=1)
#clean up with good column names as properly formatted dates
colnames(skew.melt) <- c("date","measure","skew")
skew.melt[,"date"] <- as.Date(skew.melt[,"date"])
 
direct.label(asTheEconomist(xyplot(skew~date,groups=measure,data=skew.melt,type="l",lwd=c(1,3),
main="Russell 2000 Rolling Skewness")),"last.qp")
 
#combine into data frame so we can melt as plot with lattice
kurtosis <- as.data.frame(cbind(index(kurtosis.short),coredata(merge(kurtosis.short,kurtosis.long))))
#melt to please lattice
kurtosis.melt <- melt(kurtosis,id.vars=1)
#clean up with good column names as properly formatted dates
colnames(kurtosis.melt) <- c("date","measure","kurtosis")
kurtosis.melt[,"date"] <- as.Date(kurtosis.melt[,"date"])
 
direct.label(asTheEconomist(xyplot(kurtosis~date,groups=measure,data=kurtosis.melt,type="l",lwd=c(1,3),
main="Russell 2000 Rolling Kurtosis")),"last.qp")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.