data-raw/nyse_o.R

library(rvest)
# Get the data file and unzip it if not already present
if (!file.exists("data-raw/nyse_o")) {
  tmp <- tempfile(fileext = ".zip")
  download.file("http://www.cs.technion.ac.il/~rani/portfolios/NYSE.zip", tmp)
  unzip(tmp, exdir = "data-raw/nyse_o")
  # Get the metadata
  download.file("http://www.cs.technion.ac.il/~rani/portfolios/NYSE_Dataset.htm",
                "data-raw/nyse_o/NYSE_dataset.htm")
}

html <- read_html("data-raw/nyse_o/NYSE_dataset.htm")
stock_names <- html %>%
  html_nodes("li") %>%
  html_text()

nyse_o <- "data-raw/nyse_o/NYSE.txt" %>%
  read.csv(header = FALSE, sep = "") %>%
  as.tbl
colnames(nyse_o) <- stock_names

save(nyse_o, file="data/nyse_o.RData")
benSepanski/PortfolioSelection documentation built on March 20, 2020, 9:46 p.m.