Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Where are RUT fat tails
#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
#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],[,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 <-,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"])
main="Russell 2000 Rolling Skewness")),"last.qp")
#combine into data frame so we can melt as plot with lattice
kurtosis <-,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"])
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