Skip to content

Instantly share code, notes, and snippets.

@Lauler
Created June 29, 2016 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lauler/58e76c9af5f67ada88d3c75a494cfebf to your computer and use it in GitHub Desktop.
Save Lauler/58e76c9af5f67ada88d3c75a494cfebf to your computer and use it in GitHub Desktop.
stocks <- read.table("returns.csv")
head(stocks,200)
stocks_quantiles <- data.frame(NA, NA, NA, NA, NA, NA)
names(stocks_quantiles) <- c("year", "five", "twofive", "median", "sevenfive", "ninefive")
stocks_quantiles$year <- 1:40
for(i in 1:40){
for(j in 2:6){
stocks_quantiles[i, j] <- quantile(stocks$multip[stocks$year == i],
c(0.05, 0.25, 0.5, 0.75, 0.95),
na.rm = TRUE)[[j-1]]
}
}
ggplot(data = stocks_quantiles, aes(x = year)) +
geom_ribbon(aes(ymin = five, ymax = ninefive), fill = "grey72") +
geom_ribbon(aes(ymin = twofive, ymax = sevenfive), fill = "grey82") +
geom_line(aes(y = median)) +
z_theme()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment