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
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.
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...