R(https) 中的 getSymbols 函数使用错误 [英] Error in getSymbols function usage in R(https)

查看:211
本文介绍了R(https) 中的 getSymbols 函数使用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行

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 连接.

This occurs due to the usage of https in the web page. The in-built functionality is not able to download the file necessary for the package since its using secured https connection.

现在需要找到使用 quantmod 包中的 https 站点(如 yahoo)的解决方案.

Now there is a need of finding solution for using the https sites in quantmod package like yahoo.

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

I am using R 3.4.0 latest version and quantmod 0.4-8 I am not able to retrieve data.

推荐答案

我试过了:

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

当我尝试其他来源时,它起作用了:

When I tried other source, it worked:

# "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 似乎存在问题.

It seems there are issues with google and yahoo while we use quantmod pkg.

我建议您改用Quandl".请到 Quandl 网站,免费注册并创建 API 密钥,然后将其复制到下面:

I will suggest you to use 'Quandl' instead. Plz goto Quandl website, register for free and create API key, and then copy it in below:

# 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,您可以使用:

For HDFC at BSE, you can use:

hdfc = Quandl("BSE/BOM500180")

了解更多详情:

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

这篇关于R(https) 中的 getSymbols 函数使用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆