Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fetch Historical Data at Yahoo still not working

497 views
Skip to first unread message

Marco Pereira

unread,
Apr 17, 2017, 6:59:07 PM4/17/17
to
Below is the code for fetching data from yahoo. I read that yahoo changed the url associated with the buildurl. It seems that whatever correction was done in the past, it is not there anymore.


c = yahoo;
sec = 'IBM';
field = 'Close'; % retrieve closing price data
fromdate = '01/01/2012'; % beginning of date range for historical data
todate = '06/30/2012'; % ending of date range for historical data
d = fetch(c,sec,field,fromdate,todate);
print(d)
close(c)

%Build url
% fetchurl = buildurl(s,sd,ed,p)
% fetchurl = ['http://ichart.yahoo.com/table.csv?s=IBM&a=00&b=1&c=2012&d=5&e=30&f=2012&g=d&ignore=.csv']
%
% The buildurl is still pointing to the wrong url. It should be pointing to
% ['http://ichart.finance.yahoo.com/table.csv?s=IBM&a=00&b=1&c=2012&d=5&e=30&f=2012&g=d&ignore=.csv']

% Error Message
% Error using yahoo/fetch (line 387)
% Unable to return historical data for given security.
%
% Error in getData (line 7)
% d = fetch(c,sec,field,fromdate,todate);

Jeremy Shaw

unread,
Apr 18, 2017, 3:08:07 PM4/18/17
to
For me it fails at the line

c = yahoo;

"Unable to connect or retrieve data from given URL."

It worked just fine last week.
Can someone at Matlab call Yahoo and find out what is going on?

yan bing

unread,
Apr 18, 2017, 11:22:08 PM4/18/17
to
"Jeremy Shaw" wrote in message <od5o6j$son$1...@newscl01ah.mathworks.com>...
In my case, it can connect. But has error on "fetch at 359, unable to return historical data for given security". Same code run smoothly for years. Issue starts since yesterday.

I guess Yahoo server has something different.

Last night, I spent some time find issue is due to urlread return empty array. Same url address copied to IE, it is able to get the historical data out. Not an expert to trouble shoot urlread file.

yan bing

Octavio Garcia

unread,
Apr 19, 2017, 4:35:08 AM4/19/17
to
The same happen to several people like me that that use urlread and urlread2 to get data from yahoo finance. In the request the status of the connection is ok but in both cases retreive an empty string. Therefore something had been changed in yahoo finance. Last sunday was working ok!!

Octavio Garcia

unread,
Apr 19, 2017, 5:39:07 AM4/19/17
to

Christopher Pedersen

unread,
Apr 19, 2017, 2:47:07 PM4/19/17
to
Try changing the http to https - worked for me.
h/t to Octavio Garcia for suggesting this in another thread.

Roberto

unread,
Apr 20, 2017, 4:25:08 AM4/20/17
to
"Christopher Pedersen" wrote in message <od8bb6$4i2$1...@newscl01ah.mathworks.com>...
> Try changing the http to https - worked for me.
> h/t to Octavio Garcia for suggesting this in another thread.


Please can you be more specific? I think I'm experiencing the same issue.
The code

c = yahoo

returns the error

Error using yahoo
Unable to connect or retrieve data from given URL.

But I did not understand where to fix the http to https.

dpb

unread,
Apr 20, 2017, 8:51:45 AM4/20/17
to
The URL must be buried in yahoo.m file; edit it.

--

Jeremy Shaw

unread,
Apr 20, 2017, 2:42:08 PM4/20/17
to
>
> The URL must be buried in yahoo.m file; edit it.
>

yahoo.m, for me, is just a series of comment lines so i can't make any meaningful changes to it.

Is there a URL that would work that i could pass to it, now that would help....?

Christopher Jones

unread,
Apr 20, 2017, 3:20:14 PM4/20/17
to
I am having a particular difficulty with certain ticker symbols, namely ^VIX and ^IRX. For the last 2-3 days, Yahoo is returning garbage data when I pull it via Matlab. Has anyone else noticed this?

Odemir Bruno

unread,
Apr 20, 2017, 6:26:13 PM4/20/17
to
"Christopher Pedersen" wrote in message <od8bb6$4i2$1...@newscl01ah.mathworks.com>...
> Try changing the http to https - worked for me.
> h/t to Octavio Garcia for suggesting this in another thread.

I tried https but did not work. Are you using urlread or openStream (Java inside Matlab) ?

Octavio Garcia

unread,
Apr 21, 2017, 3:06:07 AM4/21/17
to
"Marco Pereira" wrote in message <od3hbn$ksa$1...@newscl01ah.mathworks.com>...

Octavio Garcia

unread,
Apr 21, 2017, 3:10:08 AM4/21/17
to
Changing http by https, when you use urlread works for me, at least by now, as showed in the example bellow. For people that use fetch or another function of Matlab via Java, need to find the url and changed it I supose.

'https://ichart.finance.yahoo.com/table.csvs=IBM&a=.........

Hristo Raykov

unread,
Apr 21, 2017, 1:35:18 PM4/21/17
to
"Octavio Garcia" wrote in message <odcb8b$7m4$1...@newscl01ah.mathworks.com>...
> Changing http by https, when you use urlread works for me, at least by now, as showed in the example bellow. For people that use fetch or another function of Matlab via Java, need to find the url and changed it I supose.
>
> 'https://ichart.finance.yahoo.com/table.csvs=IBM&a=.........

i have the same problem last days nothing helps that works for me:

function [date, open, high, low, close, volume, adjclose ] = get_yahoo_hist_data(ticker)

[start_year, start_month, start_day] = datevec(now-1200);
[this_year, this_month, this_day] = datevec(now);

url_string = 'http://chart.finance.yahoo.com/table.csv?';
url_string = strcat(url_string, 's=', upper(ticker));
url_string = strcat(url_string, '&a=', num2str(start_month-1));
url_string = strcat(url_string, '&b=', num2str(start_day));
url_string = strcat(url_string, '&c=', num2str(start_year));
url_string = strcat(url_string, '&d=', num2str(this_month-1));
url_string = strcat(url_string, '&e=', num2str(this_day));
url_string = strcat(url_string, '&f=', num2str(this_year));
url_string = strcat(url_string, '&g=d&ignore=.csv');

data=webread(url_string);
data=table2cell(data);

open=cell2mat(data(:,2));
high=cell2mat(data(:,3));
low=cell2mat(data(:,4));
close=cell2mat(data(:,5));
volume=cell2mat(data(:,6));
adjclose=cell2mat(data(:,7));

date=zeros(length(close),1);
for i=1:length(close)
date(i,1)=datenum(data{i,1});
end

end

Alexandre Amorim

unread,
Apr 30, 2017, 12:21:07 PM4/30/17
to
"Marco Pereira" wrote in message <od3hbn$ksa$1...@newscl01ah.mathworks.com>...
I was facing same problem. Check the answer below:
https://www.mathworks.com/matlabcentral/answers/335949-datafeed-returns-an-error-using-fetch-function#answer_263844

If you follow the procedures as explained your Yahoo function will return from death.

Octavio Garcia

unread,
May 17, 2017, 3:33:10 AM5/17/17
to
"Marco Pereira" wrote in message <od3hbn$ksa$1...@newscl01ah.mathworks.com>...

Octavio Garcia

unread,
May 17, 2017, 3:52:10 AM5/17/17
to
Problems araising again downloading historical data like last month.......Same problem hdownloading historical data using urlread, 12h ago was ok......Yahoo has changed something again.

People begin reporting that:

https://es.mathworks.com/matlabcentral/answers/337271-datafeed-toolbox-does-not-work-with-yahoo

Adriano

unread,
May 18, 2017, 4:33:10 AM5/18/17
to
"Octavio Garcia" wrote in message <ofgvf3$r7o$1...@newscl01ah.mathworks.com>...
> Problems araising again downloading historical data like last month.......Same problem hdownloading historical data using urlread, 12h ago was ok......Yahoo has changed something again.
>
> People begin reporting that:
>
> https://es.mathworks.com/matlabcentral/answers/337271-datafeed-toolbox-does-not-work-with-yahoo

The problem is that the url below doesn't work:

https://ichart.yahoo.com/

I conctact Matlab support to fix the problem but they are waiting to understand if this is a temporary error or if yahoo is changing something in its web. I will write the solution when Matlab support give me it.

Jeffrey Kern

unread,
May 18, 2017, 7:41:08 AM5/18/17
to
Thanks for following this!

PeterV

unread,
May 19, 2017, 8:10:09 AM5/19/17
to

PeterV

unread,
May 19, 2017, 8:21:07 AM5/19/17
to

Alexandre Amorim

unread,
May 21, 2017, 12:05:08 AM5/21/17
to
As PeterV said the Yahoo API was discontinued

https://forums.yahoo.net/t5/Yahoo-Finance-help/Is-Yahoo-Finance-API-broken/td-p/250503/page/3

*Look for Nixon's 2nd post.

There are a different address to download historic data, but there are some differences (and challenges) to make it work properly.

This is an example of the new link:

https://query1.finance.yahoo.com/v7/finance/download/PETR4.SA?period1=1487559600&period2=1495249200&interval=1wk&events=history&crumb=XXXXXXXX

1 - the dates are now in unix format, but it is easy converted using posixtime
2 - the crumb parameter is relative to a cookie registered by your browser, and without this parameter yahoo do not return nothing:

{
"finance": {
"error": {
"code": "Unauthorized",
"description": "Invalid cookie"
}
}
}

I think it is possible to create a new parameter for fetch function where you pass this crumb code. As per discussed in stack overflow, link below, some guys are getting good results using php. Since this code is related to the cookies it will change when you clear the cookies or when it expires (after one year).

http://stackoverflow.com/questions/44030983/yahoo-finance-url-not-working

Christopher Reeves

unread,
May 24, 2017, 12:28:08 AM5/24/17
to
Seems that the yahoo API is no longer valid.

Here is the code to fetch data from google finance instead

<https://github.com/creeveshft/matlabfunctions/blob/master/GetHistoricGoogle.m>

Cheers!

Denis Alaev

unread,
Jun 18, 2017, 6:17:07 AM6/18/17
to
It seems that after several changes Yahoo Finance closed their API forever. The API was closed on May 15, one month ago already.

I've tested several alternatives and found that https://eodhistoricaldata.com the best one for those who used Yahoo Finance. They provide raw data, adjusted closes and splits/dividends.

They also have CSV output, with very similar format for Yahoo Finance users.

Also there is a https://intrinio.com/ data provider, looks good, but they much more expensive, have no data for Mutual Funds and API is very different in compare to Yahoo Finance. Then you need to significantly change your code.


"Christopher Reeves" <creev...@gmail.com> wrote in message <og324j$6pe$1...@newscl01ah.mathworks.com>...
0 new messages