使用R从雅虎财经下载数据时开始出错 [英] Started to get error while downloading data from yahoo finance using R

查看:43
本文介绍了使用R从雅虎财经下载数据时开始出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 R 中从雅虎财经网站下载一些股票数据时开始出错.我正在使用 tseries 包中的 get.hist.quote 函数.

I started to get an error while downloading some stock's data from yahoo finance web site in R. I am using get.hist.quote function from tseries package .

上周,没有问题.

五月代码如下:

library(tseries)

data<-get.hist.quote(instrument = "EREGL.IS,
                     provider="yahoo",
                     quote=c("Open","High","Low","Close","AdjClose","Volume"),
                     start="2010-01-01",
                     end="2017-02-03",
                     compression="d",
                     retclass="zoo")

`

我收到以下错误:

trying URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
download error, retrying ...
trying URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
download error, retrying ...
trying URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
download error, retrying ...
trying URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
download error, retrying ...
trying URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
Error in get.hist.quote(instrument = "EREGL.IS", provider = "yahoo", quote = c("Open",  : 
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
In addition: Warning messages:
1: In download.file(url, destfile, method = method, quiet = quiet) :
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv': HTTP status was '504 Maximum Transaction Time Exceeded'
2: In download.file(url, destfile, method = method, quiet = quiet) :
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv': HTTP status was '504 Maximum Transaction Time Exceeded'
3: In download.file(url, destfile, method = method, quiet = quiet) :
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv': HTTP status was '504 Maximum Transaction Time Exceeded'
4: In download.file(url, destfile, method = method, quiet = quiet) :
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv': HTTP status was '504 Maximum Transaction Time Exceeded'
5: In download.file(url, destfile, method = method, quiet = quiet) :
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv': HTTP status was '504 Maximum Transaction Time Exceeded'

为什么会出现这个错误?一种可能性是更改相关网址的名称.

Why do I get this error? One possibility is changing name of the related url.

我该如何解决这个问题?我会很高兴得到任何帮助.非常感谢.

How can I fix this problem? I will be very glad for any help. Thanks a lot.

推荐答案

Yahoo 进行了一些更改,因此您无法在没有相应crumb"的情况下访问下载,请参阅 几天前的问题.
除非您想为每只股票手动复制粘贴此下载 URL,否则我强烈建议您使用 quantmod 包.在应用了一个简短的修复之后(可能很快会包含在新的软件包版本中 - 在此之前您必须手动进行修复),它可以工作.

Yahoo made some changes, so you can't access the download without the respective "crumb", see Question few days ago.
Unless you want to manually copy-paste this Download-URL for each stock, I'd highly suggest you to use the quantmod package. It works, after applying a short fix (which will probably soon be included in a new package version - until then you have to do it manually).

library(quantmod)   #probably will need to install the package first
devtools::install_github("joshuaulrich/quantmod", ref="157_yahoo_502")    #installing the fix (devtools necessary)

str(getSymbols("EREGL.IS",auto.assign=F,from="2010-01-01",to="2017-02-03"))    #Example
#An ‘xts’ object on 2010-01-01/2017-02-03 containing:
#  Data: num [1:1851, 1:6] 4.39 4.43 4.42 4.49 4.49 ...
# - attr(*, "dimnames")=List of 2
#  ..$ : NULL
#  ..$ : chr [1:6] "EREGL.IS.Open" "EREGL.IS.High" "EREGL.IS.Low"     #"EREGL.IS.Close" ...
#  Indexed by objects of class: [Date] TZ: UTC
#  xts Attributes:  
#List of 2
# $ src    : chr "yahoo"
# $ updated: POSIXct[1:1], format: "2017-05-20 12:11:08"

这篇关于使用R从雅虎财经下载数据时开始出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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