我从R的yahoo财务网站下载一些股票数据时出现错误。我正在使用tseries包中的get.hist.quote函数。
上周,没有问题。
可能代码如下:
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'
为什么会出现此错误?一种可能性是更改相关网址的名称。
如何解决此问题?我会很高兴得到任何帮助。非常感谢。
答案 0 :(得分:2)
雅虎做了一些更改,因此如果没有相应的“碎屑”,您将无法访问下载,请参阅Question few days ago。
除非您想手动复制粘贴每个股票的下载URL,否则我强烈建议您使用quantmod
包。它应用了一个简短的修复程序(可能很快就会包含在新的软件包版本中 - 直到那时你必须手动完成)。
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"