SP500NasdaqDAX

  1. require(rCharts)
  2. rChart <- rCharts$new()
  3. rChart$setLib('//timelyportfolio.github.io/rCharts_d3_horizon/libraries/widgets/d3_horizon')
  4. rChart$setTemplate(script = '//timelyportfolio.github.io/rCharts_d3_horizon/libraries/widgets/d3_horizon/layouts/d3_horizon_smallmultiple.html')
  5. rChart$set(
  6. bands = 3,
  7. mode = "mirror",
  8. interpolate = "basis",
  9. width = 700,
  10. height = 300
  11. )
  12. require(quantmod)
  13. #get sp500 prices and convert them to monthly
  14. SP500 <- to.monthly(
  15. getSymbols("^GSPC", from = "1990-01-01", auto.assign = FALSE)
  16. )[,4]
  17. Nasdaq <- to.monthly(
  18. getSymbols("^IXIC", from = "1990-01-01", auto.assign = FALSE)
  19. )[,4]
  20. Dax <- to.monthly(
  21. getSymbols("^GDAXI", from = "1990-01-01", auto.assign = FALSE)
  22. )[,4]
  23. #get 12 month rolling return
  24. prices <- merge(SP500,Nasdaq,Dax)
  25. returns <- na.omit(ROC(prices, type = "discrete", n = 12))
  26. returns.df <- cbind(
  27. as.numeric(as.POSIXct(as.Date(index(returns)))),
  28. coredata(returns)
  29. )
  30. colnames(returns.df) <- c("date","SP500","Nasdaq","DAX")
  31. #supply the data to our dataless but no longer naked rChart
  32. rChart$set(data = returns.df)
  33. rChart$set(x = "date")
  34. rChart