R(https)中getSymbols函数用法出错

时间:2017-05-17 07:45:22

标签: r quantmod

运行

library(quantmod)
getSymbols("^BSESN",src="yahoo")

生成以下错误消息:

Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  : 
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=F&a=0&b=01&c=2007&d=4&e=17&f=2017&g=d&q=q&y=0&z=F&x=.csv'
In addition: Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=F&a=0&b=01&c=2007&d=4&e=17&f=2017&g=d&q=q&y=0&z=F&x=.csv': HTTP status was '502 Connection refused'

这是由于在网页中使用https而发生的。 由于内置功能使用安全的https连接,因此无法下载程序包所需的文件。

现在需要找到使用quantmod软件包中的https网站的解决方案,例如yahoo。

我使用的是R 3.4.0最新版本和quantmod 0.4-8 我无法检索数据。

1 个答案:

答案 0 :(得分:1)

我试过了:

library(quantmod)
# Create an object containing the Pfizer ticker symbol
symbol <- "PFE"    
# Use getSymbols to import the data
getSymbols(symbol, src="yahoo", auto.assign=T) 
# because src='google' throws error, yahoo was used, and even that is down

当我尝试其他来源时,它有效:

# "quantmod::oanda.currencies" contains a list of currencies provided by Oanda.com
currency_pair <- "GBP/CAD"    
# Load British Pound to Canadian Dollar exchange rate data
getSymbols(currency_pair, src="oanda")
str(GBPCAD)    

当我们使用quantmod pkg时,谷歌和雅虎似乎存在问题。

我建议你使用&#39; Quandl&#39;代替。 Plz转到Quandl网站,免费注册并创建API密钥,然后将其复制到下面:

# Install Quandl
install.packages("Quandl")
# or from github
install.packages("devtools")
library(devtools)
install_github("quandl/quandl-r")

# Load the Quandl package
library(Quandl)

# use API for full access
Quandl.api_key("xxxxxx")

# Download APPLE stock data
mydata = Quandl::Quandl.datatable("ZACKS/FC", ticker="AAPL")

对于BSE的HDFC,您可以使用:

hdfc = Quandl("BSE/BOM500180")

了解更多详情:

https://www.quandl.com/data/BSE-Bombay-Stock-Exchange?keyword=HDFC