File Exchange

image thumbnail

Yahoo Finance and Quandl data downloader

version 1.03 (546 KB) by Artem Lenskiy
Yahoo Finance and Quandl data downloader


Updated 07 Jan 2021

From GitHub

View Version History

View license on GitHub

The toolbox contains two functions:

(a) getMarketDataViaYahoo()
% symbol - is a ticker symbol i.e. 'AMD', 'BTC-USD'
% startdate - the market data will be requested from this data
% enddate - the market data will be requested till this date
% interval - the market data will be returned in this intervals
% supported intervals are '1d', '5d', '1wk', '1mo', '3mo'
% data - is a retrieved dataset returned as a table

data = getMarketDataViaYahoo('AMD', '1-Jan-2018', datetime('today'), '5d'); % Downloads AMD share historic price

(b) getMarketDataViaQuandl()
% set_name - is a dataset name e.g. 'WIKI/AAPL'
% startdate - the market data will be requested from this data
% enddate - the market data will be requested till this date
% collapse - the market data will be returned in this intervals
% supported intervals are 'daily', 'weekly', 'monthly', 'quarterly', 'annual'
% key - user's api key
% data - is a retrieved dataset returned as a table

opec_orb_raw = getMarketDataViaQuandl('OPEC/ORB', '1-Jan-2018', date(), 'weekly'); % Downloads historic OPEC basket price from Quandl

For a complete list of free datasets provided by Quandl check


(a) Yahoo Finance
disp('Request historical YTD Bitcoin price and plot Close, High and Low');
initDate = '1-Jan-2018';
symbol = 'BTC-USD';
btcusd = getMarketDataViaYahoo(symbol, initDate);
btcusdts = timeseries([btcusd.Close, btcusd.High, btcusd.Low], datestr(btcusd(:,1).Date));
btcusdts.DataInfo.Units = 'USD';
btcusdts.Name = symbol;
btcusdts.TimeInfo.Format = "dd-mm-yyyy";
legend({'Close', 'High', 'Low'});

(b) Quandl
dataset = 'LBMA/GOLD';
initDate = '1-Jan-2018';
lbma_gold_raw = getMarketDataViaQuandl(dataset, initDate, date(), 'daily');
lbma_gold_ts = timeseries(lbma_gold_raw.("EURO(AM)"), datestr(lbma_gold_raw.Date));
lbma_gold_ts.DataInfo.Units = 'USD';
lbma_gold_ts.Name = dataset;
lbma_gold_ts.TimeInfo.Format = "dd-mm-yyyy";
figure, plot(lbma_gold_ts);

Cite As

Artem Lenskiy (2021). Yahoo Finance and Quandl data downloader (, GitHub. Retrieved .

Comments and Ratings (74)

Holger Hoffmann

@Artem - Sorry, that was version 2016. Just updated and it works perfectly fine! Excellent - thx for providing this

Artem Lenskiy

@Holger, what version of Matlab are you using?

Holger Hoffmann

not working for me. Trying to reproduce the example I get:
Undefined variable "matlab" or class "".

Error in getMarketDataViaYahoo (line 55)
uri =['', upper(symbol), '/history'],...

Any hint?

Howard Labido

Please check here
if your data are provided by Yahoo! finance.

Paul Safier

Pavel Smith

Artem Lenskiy

@Jun thanks for the solution, I updated the repository.
@JRP, I've tried PYPL, FIT, NVAX and AdjClose is equal to Close prices, not sure what could be done at this point, since this is what Yahoo returns.
@Evgeny Gerasimov, Yahoo does not store dividends in a returned CSV file unfortunately.

Miguel Lopez


The function works well but cannot retrieve data before Jan 1st, 1970. The problem I believe is the "uint64" conversion of the start and end dates and the use of posix time. Change "uint64" to "int64" solves the problem.

Evgeny Gerasimov

Artem, hi! Thanks for your excellent work.
How to get the dividends data in the same table with OHLC prices?


On some it reports the AdjClose and on some it doesn't. It may work for CONE and it may work for AAPL but you can verify that the AdjClose price is incorrect using others -- PYPL, FIT, NVAX, SNAP. For those stocks I just listed the Close = AdjClose, which is incorrect.

marc de vernon

Checked it on CONE, a Nasdaq stock. Seems to be working fine. Thanks very much.


Something is wrong with the AdjClose price value that it pulls. I'm not sure what value that is there, but it isn't the AdjClose price at end of day. It looks like it's the Close price but still confused about that since it doesn't march Close price either.


Works fine after your last update, thank you!

Allen Zhang

Artem Lenskiy

DavyJonesLocker, indeed seems Yahoo has changed the interface a bit. I have modified the code, it should work now.


anyone know why the getMarketDataViaYahoo() doesn't return data for a whole host of Tickers such as CSCO, GOOGL, CVS etc. About 50 or so out of the S&P500. There were returning data until about 5 days ago and the respective URL seems fine when pasted into a web browsers

@Artem Thanks for the function though!

Paul Bower

David Fuhrman

Rafael Rebouças

Thanks, Works fine!

Igor Kuruc

Artem Lenskiy

@Christian, @Thomas Heuser, @Xiang Chen, @Ryan Hendry, the bug has been fixed. It was caused by slightly different forms of Quandl and Yahoo data.

Artem Lenskiy

@Denys Volkov, I just tested for EURUSD=X and it did return data:
initDate = '1-Jan-2014';
symbol = 'EURUSD=X';
eurusd_yahoo_raw = getMarketDataViaYahoo(symbol, initDate);
eurusd_yahoo= timeseries([eurusd_yahoo_raw.Close, eurusd_yahoo_raw.High, eurusd_yahoo_raw.Low], datestr(eurusd_yahoo_raw(:,1).Date));
eurusd_yahoo.DataInfo.Units = 'USD';
eurusd_yahoo.Name = symbol;
eurusd_yahoo.TimeInfo.Format = "dd-mm-yyyy";

figure, plot(eurusd_yahoo);
legend({'Close', 'High', 'Low'},'Location', 'northwest');


Hi all,
I just had a look through the tool (getMarketDataViaYahoo), as I had the same problem that the last data was not available (in my case 06 May 2020). Actually the the data is available in the downloaded data. I assume there is an issue in line 130. When replacing the -2 by -1 then you get the last data line, which is the one of the current day in your table also

Thomas Heuser


I really like the script! Very nice work.

Unfortunately I experience the same issue. In my case most recent data for ETF SPY or SXR8.DE is missing. I looked at Yahoo directly and for SPY all recent data is available (but not for SXR8.DE).

So far I add the missing data manually, but automatically by the script would be really great.


Xiang Chen

Hi Artem, thank you for the amazing tool. It's damn helpful. I want to report the same problem mentioned below, it seems the data for the most recent trading day is always missing. It's Mar 29 today and the last trading day is Mar 27 but it excludes Mar 27 when I set the enddate to be 'today'. It would be appreciated if you could help fix it. Thanks!


Thank you so much for this. Finally got the yahoo data.

Weidong Lin

Many thanks for the codes!

Ryan Hendry

Hi Artem, thanks for making this excellent program. I have a question, does yahoo not allow extraction of data from less than 24 hours ago? I tried to get all data from Nov 1st 2019 to today, and it did not include this friday, March 6, it stopped at March 5th.

Is there any way to fix this?

Michael Muhle

Artem, I am using Matlab ver 1209.b and am getting several error messages. Would appreciate you help on how to fix.
>> aaplusd_yahoo_raw = getMarketDataViaYahoo(symbol, initDate);
Dot indexing is not supported for variables of this type.
Error in (line 104)
if ~value.EncodedPath.startsWith('/')
Error in (line 197)
obj.RequestTarget = target;
Error in (line 754)
obj.RequestLine = obj.RequestLine.finish(uri,~isempty(proxyURI),obj.Method);

Error in (line 453)
[completedURI, obj] = obj.completeInternal(uri, options);
Error in getMarketDataViaYahoo (line 73)
[response, ~, ~] = requestObj.send(uri, options);

Denys Volkov

Hello Artem! Thank you very much for such useful function.
But it doesn't work for currency pairs for me. For example, i try: symbol = 'EURUSD=X'; and i have this error: Check ticker symbol and that Yahoo provides data for it

Daniel Dalla Palma

Artem, i have a problem, sometimes the code extract for the same time period, data with different length and this in a for cycle block the process of adding the last extraction in a table to the previous one. I need an advice on how to fix it in order to keep develop my portfolio optimization for the university. Tks man

Artem Lenskiy

Martin, thanks for spotting the bug. I just fixed it.

Martin Stolle

or sth. like this: if(strcmp(string(response.StatusCode), '404'))

Martin Stolle

Artem, nice job on the function (getMarketDataViaYahoo). Check Line 111, it seems the stringcompare shoud rather be strcmp(response.Statuscode, 'NotFound').

Valeri Disko

It just works. Thank you.

hossein kazemi


Artem Lenskiy

Afonso Moreira, hmm not sure then, I tested it once again and it worked.
Sometimes, when you copy and paste code from online or powerpoint presentations, unprintable characters are added. Please, check that the file does not have those hidden characters (e.g. \x0d). Matlab should highlight those with a red tilde symbol.

Afonso Moreira

Artem Lenskiy i am using MacOS 10.14.5 with Matlab 2019a. Tried to retrieve Apple with symbol 'AAPL'. Thanks

Artem Lenskiy

Afonso Moreira, what is your Matlab version ? What symbols did try to retrieve ?

Afonso Moreira

Has anybody got this error "Invalid character code sequence detected." when using this function?


Finally, I can find one package working. But my problem is whether I could get different stock market indexes from this funciton?


Dominic Nocon

Brook Dawit

Jesseca Nivens

Excellent! Thanks for sharing.

Artem Lenskiy

Martin, unfortunately Yahoo Finance does not provide historical data for "GC=F" gold futures. You can check it here as you can see there is no "historical data" tab.
I will try to spare some time in July and extend the toolbox to other data sources as well.


I tried to get gold futures: 'GC=F' symbol. I got: Dot indexing is not supported for variables of this type.
Anyway around it?

Lautaro Parada

works like a charm, thanks man!

Artem Lenskiy

b, I just tried and it worked for me, please double check that you have a stable internet connection.


Trying to use this example, but gives the error:
Error using
(line 1269)
The error "Connection refused" occurred while communicating
with URL

Error in (line 484)
obj.sendOneRequest(connector, options, [],

Error in getMarketDataViaYahoo (line 66)
[response, ~, ~] = requestObj.send(uri, options);

Error in getYahooFinanceData (line 4)
data = getMarketDataViaYahoo('AMD', '1-Jan-2018',
datetime('today'), '5d');

Caused by:
The error "Connection refused" occurred while
communicating with URL
The error "Connection refused" occurred while
communicating with URL

Error in
(line 324)
obj.ContentType = connection.ContentType; % may be
empty if no Content-Type

Error in (line
[~, history] = connector.sendRequest(credInfo,

Error in (line 484)
obj.sendOneRequest(connector, options, [],

Error in getMarketDataViaYahoo (line 66)
[response, ~, ~] = requestObj.send(uri, options);

Error in getYahooFinanceData (line 4)
data = getMarketDataViaYahoo('AMD', '1-Jan-2018',
datetime('today'), '5d');


Brandon Schleter

Easy to use. just set the function in the path, and in the command window, just simply remove the 'function' word. This seems elementary but for people like me, just make sure you are doing this. Super easy formula thank you.

Artem Lenskiy

Hi Konstantin, sorry for a late reply. I did check the code now and it still works. It might take some time to download a list of symbols though. So, please try downloading a single symbol first.

Konstantin K

I have one code stopped working?

Artem Lenskiy

Hi Jose, I've just checked the example and it work for me.
Can you please tell me what version of Matlab you are using? I am pretty sure the problem is in Matlab version. Yours, most probably does not support strings. Strings were added in 2016b. Please see

jose saballos

when I run the example to get the data from Yahoo I got the following error:
Error: File: getMarketDataViaYahoo.m Line: 63 Column: 13
Creating a string using double quotes is not supported. Use the string

how can I solve this issue? Thanks

Alberto Burchi


Artem Lenskiy

@Avishek Dusoye, sorry pal but this question should be directed to Yahoo!. Please check here if your symbols are provided by Yahoo! finance.

Avishek Dusoye

Looks good! I don't undertand the use of the format for the ticker e.g USD-ZAR does not work and for UK-100. Could you specfic on this please, where can i get the list of ticker?

Artem Lenskiy

@ Gian Maria Aprigliano make sure the function getMarketDataViaYahoo() is in your Matlab path i.e. either you should have it in your local folder or you should use function call addpath to add the path to getMarketDataViaYahoo() to your Matlab path, see for details.
@ Ravosh Samari, glad you figured it out. I did no test this function on versions below 2018.
@ Stephen Forczyk, it is possible by parsing the webpage, however this is a different mechanism from what getMarketDataViaYahoo() implements. As far as I know Yahoo does not provide companies info (P/E values etc) packaged into a single file, so it will not be possible to modify getMarketDataViaYahoo().

Gian Maria Aprigliano

I still can not make it work, could you show me the script or function you use?
every time I try it tells me that I have not declared the variable:

Ravosh Samari

Ignore the last comment, working on r2014a and r2014b introduced datetime

Ravosh Samari

datetime doesn't seem to work for me. It throws an error Undefined function 'datetime' for
input arguments of type 'char'." where ever it is used. Also the following line crumb = "\"; is no valid.

Stephen Forczyk

Is it possible to get earning per shape and P/E values from YAHOO Finance? Could your tool be modified to get this?

dan berkowitz

Brice Dupoyet

This is amazing, thank you so much for sharing your hard work, brilliant!!! :-)

Noah van Hartesveldt

Great! Thanks so much, could not figure out how to format output data on my code. Hoping to add functionality for finer granularity (<1day)

Széplaki István

Kevin Chng

It is really great. It has been headache quite long for me....Salute!

Juan Ignacio Peña

Széplaki István

MATLAB Release Compatibility
Created with R2018a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Yahoo! Finance Data Loader

Community Treasure Hunt

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

Start Hunting!