Downloading Yahoo stock prices in R

后端 未结 8 630
野趣味
野趣味 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:02

    This also a little late...If you want to grab data with just R's base functions without dealing with any add-on packages, just use the function read.csv(URL), where the URL is a string pointing to the right place at Yahoo. The data will be pulled in as a dataframe, and you will need to convert the 'Date' from a string to a Date type in order for any plots to look nice. Simple code snippet is below.

    URL <- "http://ichart.finance.yahoo.com/table.csv?s=SPY"
    dat <- read.csv(URL)
    dat$Date <- as.Date(dat$Date, "%Y-%m-%d")
    

    Using R's base functions may give you more control over the data manipulation.

提交回复
热议问题