雅虎在 Matlab 中获取货币?
有谁知道如何获取适用于从 Yahoo< 获取货币对的日期范围/a>?下面的代码可以很好地捕获所需的最新汇率吗?我正在寻找一系列日期的相同信息的完整时间序列或矩阵。我尝试使用 Mathworks.com 中的示例,但出现下面显示的错误。这段代码工作正常:
Connect = yahoo;
k = {'USDJPY=X' 'USDEUR=X' 'USDCAD=X' 'USDGBP=X'};
data = fetch(Connect, k)
如果
USDJPY=X = USD to JPY
USDEUR=X = USD to EUR
etc...
我执行一系列日期,我会收到此错误:
>> data = fetch(Connect, k, '24-Oct-2003',datestr(now))
Warning: Historical data fetch does not support multiple security input.
USDJPY=X data reurned.
> In yahoo.fetch at 310
??? Error using ==> yahoo.fetch at 363
Unable to return historical data for given security.
谢谢
Does anyone know how to get a range of dates that works for fetching currency pairs from Yahoo? The code below works fine for capturing the latest rates needed? I am looking for a complete time series or matrix of the same info for a range of dates. I tried using the examples from Mathworks.com but get errors displayed below. This code works fine:
Connect = yahoo;
k = {'USDJPY=X' 'USDEUR=X' 'USDCAD=X' 'USDGBP=X'};
data = fetch(Connect, k)
where
USDJPY=X = USD to JPY
USDEUR=X = USD to EUR
etc...
If I do a range of dates, I get this error:
>> data = fetch(Connect, k, '24-Oct-2003',datestr(now))
Warning: Historical data fetch does not support multiple security input.
USDJPY=X data reurned.
> In yahoo.fetch at 310
??? Error using ==> yahoo.fetch at 363
Unable to return historical data for given security.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,如果你仔细阅读文档:
所以你必须一次指定一个......
至于另一部分,这是我尝试过的一个例子:
我得到:
但是对于相反的转换
'USDEUR=X'
,你会得到错误:通过单步执行代码,用于获取数据的 URL 为:
将其粘贴到您最喜欢的浏览器中,您将获得一个包含预期数据的 CSV 文件。如果您将其从
EURUSD
更改为USDEUR
,您会收到 404 错误:抱歉,找不到您请求的页面。
。我不确定这些代码是否正确,但我尝试过:
JPY=X
、CAD=X
、EUR=X
、< code>GBP=X,并且它们都返回有效结果...附带说明:我做了一个快速研究,据我所知,MATLAB 函数正在使用旧的 Yahoo CSV API。有一个更新的基于 REST 的 API,用于使用返回 XML/JSON 的 YQL 访问数据,但是我没有这方面的经验。有一个 YQL 控制台...
HTH
更新(2017 年 4 月)
我刚刚在 MATLAB R2016b 中测试了上述内容,雅虎财经 API 中似乎发生了一些变化;如果基础不是美元,它不再返回历史货币汇率。换句话说,所使用的符号只能采用
???=X
形式(其中???
是 3 个字母的代码):请求
EURUSD =X
或USDEUR=X
仅在您未指定日期或日期范围时才有效:为了确认,我尝试直接使用 YQL 控制台和 查询像这样:
具有相似的结果。如果您将符号更改为
USDEUR=X
,结果中会出现“404 Not Found”错误(顺便说一句,YQL 查询使用下面相同的 CSV 端点。如果您有兴趣,请在此处是 一些 URL 中参数含义的线索)。
如果您正在查找支持的货币符号列表,请参阅此 API 称呼:
就其价值而言,雅虎财经 API 似乎从来就没有打算用作公共服务!引用这个答案:
所以不能保证它将来不会损坏......
First, if you carefully read the documentation:
So you have to specify one at a time...
As for the other part, here is an example I tried:
I get:
But for the opposite conversion
'USDEUR=X'
, you get the error:By stepping through the code, the URL used to fetch the data was:
Pasting that in your favorite browser, you will get a CSV file with the expected data. If you change it from
EURUSD
toUSDEUR
you get a 404 error:Sorry, the page you requested was not found.
.I'm not sure if these are the correct codes, but I tried:
JPY=X
,CAD=X
,EUR=X
,GBP=X
, and they all return valid results...As a side note: I've done a quick research, and from what I understood, the MATLAB function is using the older Yahoo CSV API. There is a newer REST-based API for accessing the data using YQL which returns XML/JSON, but I have no experience in that. There is a YQL console you can play around with though...
HTH
Update (April 2017)
I just tested the above in MATLAB R2016b, and it seems something changed in the Yahoo Finance API; It no longer returns historical currencies exchange rates if the base is not USD. In other words, the symbol used can only be of the form
???=X
(where???
is the 3-letter code):Requesting
EURUSD=X
orUSDEUR=X
only works if you don't specify a date or a date range:To confirm, I tried using the YQL console directly with a query like this:
with similar results. If you change the symbol to
USDEUR=X
you get "404 Not Found" errors in the results(BTW the YQL query uses the same CSV endpoint underneath. In case you're interested, here are some clues to the meaning of the parameters in the URL).
If you're looking for the list of supported currency symbols, see this API call:
For what it's worth, it appears that the Yahoo Finance API was never meant to be used as a public service! To quote this answer:
So no guarantees it won't break in the future...
YQL 只是在后台/作为基础使用“较旧的”CSV API,因为 YQL 是 CSV API 的容器。区别仅在于请求类型(REST 或 YQL)。结果是一样的。
YQL is just using the "older" CSV API in background/as base, because YQL is a container for the CSV API. The difference is only the request type (REST or YQL). The results are the same.