MATLAB Answers

Datafeed returns an error using fetch function

5 views (last 30 days)
Hi everybody,
I'm trying to use "fetch" function with this code:
but I recive this error:
Error using yahoo Unable to connect or retrieve data from given URL.
I used the same code 3 days ago and it worked. What's going on? Thanks!

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 2 May 2017
The MathWorks Support Team recently posted an update on this issue. Here is the answer to save you the click:
“In April 2017, Yahoo introduced some changes in the protocol of their API. These changes prevented the Datafeed Toolbox from connecting to the service. The following webpage contains the workaround for this issue and instructions on how to apply the fix.

More Answers (6)

Shashank on 21 Apr 2017
Hi Adraino,
MATLAB uses Yahoo's API under the hood. Around April 18 Yahoo introduced some changes in the protocol of their API. These changes prevented the Datafeed Toolbox from connecting to the service.
The development team implemented a fix that takes into account those changes, but the fix needs to be applied manually. To apply the fix, follow these steps:
1) Download the attached files: 'yahoo.m' and 'fetch.m'
2) Remove the following file
where %MATLAB_ROOT% can be found with the following MATLAB command:
>> matlabroot
3) Place the downloaded files in the following locations:
4) Run the following MATLAB command
>> rehash toolboxcache
>> clear classes
Now you should be able to retrieve historic and current data as usual:
>> % Historic data
>> d = fetch(yahoo,'IBM','Close','01/01/2012','06/30/2012');
>> d(1:3,:)
>> % Current data
>> fetch(yahoo,'IBM')
Walter Roberson
Walter Roberson on 14 Jun 2017
The attachments were withdrawn. Yahoo changed their system, disabling the interface that MATLAB used, and has not replaced it with anything useful as yet. You will not be able to get historical data from yahoo until Yahoo implements some new arrangment, and Mathworks writes a new routine to access it.

Sign in to comment.

Philippe Loustaunau
Philippe Loustaunau on 21 Apr 2017
I tried this and it is not working. First there is inconsistency in the answer: The file you provided is yahoo.m, but you suggest we delete yahoo.p. The yahoo.m file is in the datafeed directory, the yahoo.p file is in the @yahoo directory, inside the datafeed directory. Since you attached the yahoo.m file, I assume you wanted to replace the one in the datafeed directory. I followed the steps, but it is not working, same error.

Sign in to comment.

avia gubbuy alon
avia gubbuy alon on 19 May 2017
again not working. please help.
  1 Comment
Denis Alaev
Denis Alaev on 18 Jun 2017
It seems that after several changes Yahoo Finance closed their API forever, I think that's just Verizon costs cutting strategy and I'm pretty sure this API will not be working again. The API was closed on May 15, one month ago already.
I've tested several alternatives and found that 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, API Documentation and even VBA Examples (
Also there is a 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.

Sign in to comment.

Munir Ruffo
Munir Ruffo on 29 May 2017
Where can i download the two mentioned files yahoo.m and fetch.m ? Can't find it anywhere!!

Adriano on 29 May 2017
This is the Mathworks answer on my Technical Support on yahoo fetch function:
I sincerely apologize for the recent issues you may have encountered while connecting to the Yahoo service using the Datafeed Toolbox.
Yahoo has reportedly changed its API and site structure, which has resulted in the above error. According to Yahoo's forum, "" will undergo structural changes that will not cover existing functionality. Since "fetch" accesses "" to fetch historical and intraday data, connecting to Yahoo using the Datafeed Toolbox is no longer supported.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!