如何将 getReturns 与 Yahoo Finance API 结合使用 [英] How to use getReturns with the Yahoo finance API
问题描述
我在使用 R 包 getReturns
时遇到问题.自 5 月 17 日以来,我遇到了此错误:
I have problems with R package getReturns
. I have encountered this error since 17th May:
文件中的警告(文件,rt"):无法打开 URL 'http://ichart.finance.yahoo.com/table.csv?s=AAPL&a=4&b=28&c=2014&d=4&e=27&f=2017&g=w&ignore=.csv':HTTP 状态为'404 Not Found'
Warning in file(file, "rt") : cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=AAPL&a=4&b=28&c=2014&d=4&e=27&f=2017&g=w&ignore=.csv': HTTP status was '404 Not Found'
看起来 ichart
API 不再运行了.谁能帮我解决这个问题?有人知道如何解决吗?我在使用 quantmod
R 包时遇到了同样的问题.
It looks like that ichart
API did not run anymore. Can anyone help me with this issue? Does someone know how to fix it? I have encountered the same issue with the quantmod
R package.
推荐答案
你可以按照我之前的发表,可能对你有帮助.
You can follow my an earlier post, which might help you.
我试过了:
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
这篇关于如何将 getReturns 与 Yahoo Finance API 结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!