suppressPackageStartupMessages({
  library(tidyverse)
  library(scales)
  library(glue)
  library(tidyquant)
  library(DT)
  library(lubridate)
  library(treemapify)
})

1 S&P 500 Index

In this project we will analyze stocks in S&P 500 index (symbol: ^GSPC) which measures the stock performance of 500 large companies listed on stock exchanges in the United States (Wikipedia).

We can get daily values of the index using tq_get() function of the tidyquant package

sp <- tq_get("^GSPC", from = "1950-01-01") 

sp %>% 
  select(-adjusted, -symbol) %>% 
  DT::datatable(
    caption = "S&P 500 Raw Data",
    options = list(
      dom = 'tip',
      pageLength = 10,
      autoWidth = TRUE
    ),
    rownames = FALSE) %>% 
  formatRound(columns = 2:5,digits = 2)