Downloading Yahoo stock prices in R

后端 未结 8 626
野趣味
野趣味 2020-12-12 13:46

This is a newbie question in R. I am downloading yahoo finance monthly stock price data using R where the ticker names are read from a text file. I am using a loop to read

相关标签:
8条回答
  • 2020-12-12 14:27

    I'm a little late to the party, but I think this will be very helpful to other late comers.

    The stockSymbols function in TTR fetches instrument symbols from nasdaq.com, and adjusts the symbols to be compatible with Yahoo! Finance. It currently returns ~6,500 symbols for AMEX, NYSE, and NASDAQ. You could also take a look at the code in stockSymbols that adjusts tickers to be compatible with Yahoo! Finance to possibly adjust some of the tickers in your file.

    NOTE: stockSymbols in the version of TTR on CRAN is broken due to a change on nasdaq.com, but it is fixed in the R-forge version of TTR.

    0 讨论(0)
  • 2020-12-12 14:27

    Maybe give the BatchGetSymbols library a try. What I like about it over quantmod is that you can specify a time period for your data.

    library(BatchGetSymbols)
    
    # set dates
    first.date <- Sys.Date() - 60
    last.date <- Sys.Date()
    freq.data <- 'daily'
    # set tickers
    tickers <- c('FB','MMM','PETR4.SA','abcdef')
    
    l.out <- BatchGetSymbols(tickers = tickers, 
                             first.date = first.date,
                             last.date = last.date, 
                             freq.data = freq.data,
                             cache.folder = file.path(tempdir(), 
                                                      'BGS_Cache') ) # cache in tempdir()
    
    0 讨论(0)
提交回复
热议问题