如何在R市场关闭前使用quantmod包下载开盘价?

时间:2016-06-20 18:52:23

标签: r quantmod

我希望在市场仍然开放时从雅虎财经下载股票报价,以获得当天的开盘价。我正在尝试使用quantmod包中的getSymbols()在R中执行此操作:

#Acquire today's data as a string
today.char <- Sys.Date() %>% as.character

#Download stock quote during market hours
currentQuote <- getSymbols('QQQ',
                           from = today.char,
                           src = "yahoo",
                           env = NULL)

但是,这会导致以下错误:

Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  : 
  cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=QQQ&a=5&b=20&c=2016&d=5&e=20&f=2016&g=d&q=q&y=0&z=QQQ&x=.csv'
In addition: Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
  cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=QQQ&a=5&b=20&c=2016&d=5&e=20&f=2016&g=d&q=q&y=0&z=QQQ&x=.csv': HTTP status was '404 Not Found'

我做错了什么,如何才能在收市前获得至少开盘价?

1 个答案:

答案 0 :(得分:2)

getQuote()为你工作吗?例如getQuote('X')[5]将为您提供今日美国钢铁的开盘价,其余报价位于`getQuote()'返回的数据框中