#do some quick exploration with R #to see how many years #the S&P 500 has gone all year #without going below the first day of the year require(quantmod) require(plyr) require(rCharts) getSymbols("^GSPC",from = "1950-01-01") #get closing price on day one of the year dayone <- GSPC[endpoints(GSPC[-NROW(GSPC),],"years")+1,] #make xts a data frame without first day of year GSPC.df <- data.frame( index(GSPC), as.numeric(format(index(GSPC),"%Y")), GSPC[,4] )[-(endpoints(GSPC[-NROW(GSPC),],"years")+1),] colnames(GSPC.df) <- c("date","year","price") minprice <- ddply(GSPC.df,.(year),summarize,yearmin=min(price)) minprice$dayone = dayone[-NROW(dayone),1] minprice$pctlower = minprice$yearmin / minprice$dayone - 1 minprice$higherorlower = minprice$yearmin < minprice$dayone #draw a quick chart with rCharts dimple d1 <- dPlot( pctlower ~ year, groups = "higherorlower", data = minprice, type = "bar" ) d1$xAxis( orderRule = "year" ) d1$yAxis( outputFormat = "#.1%" ) d1 d1$templates$script = "http://timelyportfolio.github.io/rCharts_dimple_systematic/libraries/widgets/dimple/layouts/chart.html" d1$defaultColors( RColorBrewer::brewer.pal(11,"RdYlGn")[c(9,2)], replace = T ) d1