英文:
Exists() and getSymbols() can't find symbol listed in yahoo
问题
PRIO3F.SA在雅虎金融上列出,但在使用exists()函数时未找到任何内容。这是一个学校项目,使用这种方法找不到相当多的符号。quantmod(或者可能是雅虎金融)是否不是我最好的选择?
我尝试了多种不同的符号变体,仍然失败。
如果我尝试使用getSymbols()函数,会出现以下错误:
> getSymbols("PRIO3F.SA", src = "yahoo", auto.assign = FALSE)
Error in getSymbols.yahoo(Symbols = "PRIO3F.SA", env = <environment>, :
Unable to import “PRIO3F.SA”.
attempt to set an attribute on NULL
英文:
For some reason, even though PRIO3F.SA is listed on yahoo(and also other symbols aside from this one specifically), when I do exists() it simply doesn't find anything.
This is for a school project and quite a few symbols can't be found with this method. Is quantmod (or maybe yahoo finance) not my best place to go to?
I've tried multiple different symbol variations and still failing.
> exists("PRIO3F.SA")
[1] FALSE
> exists("PRIO3.SA")
[1] FALSE
> exists("PRIO3F")
[1] FALSE
> exists("PRIO3")
[1] FALSE
If by any chance I try to use getSymbols() instead, this is what greets me:
> getSymbols("PRIO3F.SA", src = "yahoo", auto.assign = FALSE)
Error in getSymbols.yahoo(Symbols = "PRIO3F.SA", env = <environment>, :
Unable to import “PRIO3F.SA”.
attempt to set an attribute on NULL
答案1
得分: 2
Yahoo不为每个股票符号提供历史每日数据。这就是这种情况下的问题。
英文:
Yahoo does not provide historical daily data for every ticker symbol. That's the problem in this case.
答案2
得分: 1
由于我可以成功调用 getSymbols("MSFT",src="yahoo",auto.assign = FALSE)
,而 getSymbols("PRIO3F.SA",src="yahoo",auto.assign = FALSE)
失败(对我也是如此),这表明 API 可能已经发生了变化。我在调试 getSymbols.yahoo
(内部函数)时发现自动生成的 URL 如下所示:
yahoo.URL
# [1] "https://query2.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?period1=1167609600&period2=1688688000&interval=1d"
而在 Yahoo! 自己的财务页面中显示的 URL 则不同。在调试过程中,如果我将其替换为以下内容(在深度调试时):
yahoo.URL <- "https://query1.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?region=US&lang=en-US&includePrePost=false&interval=2m&useYfid=true&range=1d&corsDomain=finance.yahoo.com&.tsrc=finance"
## 用于比较的其他 URL...
https://query2.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?period1=1167609600&period2=1688688000&interval=1d
https://query1.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?region=US&lang=en-US&includePrePost=false&interval=2m&useYfid=true&range=1d&corsDomain=finance.yahoo.com&.tsrc=finance
它可以正常工作。请注意,由 getSymbols.yahoo
生成的 URL 包括期间,而我在浏览器中嗅探到的 URL 则不包括。我确信这将是进一步调查的源头。
我建议您向作者提交一个 bug 报告,因为看起来 Yahoo! 可能已经更新了他们的 API 和/或收紧了他们的期望。可能是 CORS、我的请求来源国家或其他任何事情。
英文:
Since I can call getSymbols("MSFT",src="yahoo",auto.assign = FALSE)
successfully while getSymbols("PRIO3F.SA",src="yahoo",auto.assign = FALSE)
fails (for me as well), that suggests the API may have changed. I debug
ged the call to getSymbols.yahoo
(internal) and it appears that the URL being generated automatically
yahoo.URL
# [1] "https://query2.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?period1=1167609600&period2=1688688000&interval=1d"
and the URL shown within Yahoo!'s own finance page are different. While debugging, if I replace it with (while deep within debugging)
yahoo.URL <- "https://query1.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?region=US&lang=en-US&includePrePost=false&interval=2m&useYfid=true&range=1d&corsDomain=finance.yahoo.com&.tsrc=finance"
## for comparison ...
https://query2.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?period1=1167609600&period2=1688688000&interval=1d
https://query1.finance.yahoo.com/v8/finance/chart/PRIO3F.SA?region=US&lang=en-US&includePrePost=false&interval=2m&useYfid=true&range=1d&corsDomain=finance.yahoo.com&.tsrc=finance
it works. Note that the url generated by getSymbols.yahoo
includes the period whereas the url I sniffed in the browser does not. I'm sure this will be the source of some more investigation.
I suggest you submit a bug-report to the authors, since it appears Yahoo! may have updated their API and/or tightened their expectations. (Perhaps it's CORS or the source country of my request or any number of things.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论