Using R to make historical data matrix

Discussion in 'Data Sets and Feeds' started by jk90029, Dec 21, 2014.

  1. We know that we can use R to download historical data (Daily OHLC), for EACH stock.

    In R, the commands to receive MSFT via free and open yahoo source are

    install.packages("quantmod")
    library(quantmod)
    getSymbols("MSFT", src="yahoo",from ="2013-01-01",to="2014-08-28")

    The three lines will provide the dataset with name "MSFT" in you R system.
    Obviously MSFT[,4] is the daily closes.

    ************************************************

    Now my question is how to make daily close historical data for 500 stocks in SnP500.
    The matrix in R will have 500 rows and 300(?) columns.
     
  2. i don't quite remember the R syntax but the basic idea in pseudo code:
    Code:
    big_frame = DataFrame
    for ticker in list_of_sp500_stocks:
          big_frame[ticker] = getSymbols(ticker, src='yahoo', from=start_date, to=end_date)
    it'll basically create a 3 dimensional frame where each page is a ticker. each row 1 day and each column one piece of data
    from there you can slice it to get column 4 (close price) or whatever you need.
     
  3. 2rosy

    2rosy

    get the data from quandl. it returns in a dataframe