public
Last active

exceptional case of the Russell 2000

  • Download Gist
fat tails to the upside.r
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 51 52 53 54 55
#explore exceptional case of the Russell 2000
 
require(quantmod)
require(PerformanceAnalytics)
require(xtsExtra)
 
getSymbols("^RUT", from = "1900-01-01")
getSymbols("^GSPC", from = "1900-01-01")
 
#do initial exploration of distribution
chart.QQPlot(na.omit(ROC(RUT[,4],type="discrete",n=250))["1987::"])
chart.QQPlot(na.omit(ROC(GSPC[,4],type="discrete",n=250))["1987::"])
 
#explore barplot.xts to do a chart of annual returns for both indexes
#merge prices
prices <- merge(GSPC[,4],RUT[,4])
#use endpoints to get annual returns
returns.annual <- as.xts(apply(
ROC(prices[endpoints(prices,"years")],type="discrete",n=1),
MARGIN = 2,
FUN = na.fill, fill = 0),
order.by = index(prices[endpoints(prices,"years")]))
#name columns something a little more clear
colnames(returns.annual) <- c("S&P 500","Russell 2000")
#using barplot.xts create the plot
#I made some subtle changes to barplot.xts to experiment so plot will be cosmetically different
barplot.xts(returns.annual,
stacked=FALSE,
box="transparent", #get rid of box surrounding the plot
ylim=c(-0.5,0.5),
ylab=NA,
border=c(brewer.pal(n=11,"BrBG")[c(4,9)]),
col=c(brewer.pal(n=11,"BrBG")[c(4,9)])) #deliberately trying some new colors
title(main="Annual Returns of S&P 500 and Russell 2000",
outer = TRUE,
adj=0.05, font.main = 1, cex.main = 1.25, line = -2)
require(latticeExtra)
require(reshape2)
 
roc <- na.omit(merge(ROC(GSPC[,4],type="discrete",n=250),ROC(RUT[,4],type="discrete",n=250)))
#name columns something a little more clear
colnames(roc) <- c("S&P 500","Russell 2000")
roc.melt <- melt(coredata(roc))
asTheEconomist(
densityplot(~value,data=roc.melt,groups=Var2,
#par.settings=theEconomist.theme(box="transparent"),
#lattice.options=theEconomist.opts(),
auto.key=list(space="right",col=(brewer.pal(n=11,"BrBG")[c(9,4)]),lines=FALSE),
col=(brewer.pal(n=11,"BrBG")[c(9,4)]),
ylab=NA,
main="Annual Returns (Rolling 250 Day) of S&P 500 and Russell 2000")
)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.