R(https) 中的 getSymbols 函数使用错误

Error in getSymbols function usage in R(https)

运行

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 我无法检索数据。

我试过了:

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 时,google 和 yahoo 似乎有问题。

我建议您改用 'Quandl'。请到 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