Code covered by the BSD License  

Highlights from
Download Daily Data from Google and Yahoo! Finance


5.0 | 10 ratings Rate this file 328 Downloads (last 30 days) File Size: 84.4 KB File ID: #43627
image thumbnail

Download Daily Data from Google and Yahoo! Finance



25 Sep 2013 (Updated )

Provides functions for getting data from both data sources as well as helper utility functions

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

This archive contains functions for downloading daily stock price information from both Google and Yahoo! Finance as well as helpful utility functions. It furthermore contains a (basic but decent) example of a unit test harness created using MATLAB's functional unit test framework.

The utility functions allow you to convert the Google-formatted ticker symbols to the Yahoo! format and vice versa. Since Google does not provide adjusted closing prices, a helper function that uses dividend information to calculate them is automatically called.

Both Google and Yahoo! seem to allow the use of financial data for PERSONAL, INFORMATIONAL use ONLY and do not warrant against inaccuracies. These discrepancies are fairly common and are the main reason that this suite uses both Yahoo! AND Google data -- only if both sources agree on a piece of data should you begin to trust it.

For questions and discussion, go to


Google Finance Historical Stock Data Downloader and Download Google Finance Stock Prices inspired this file.

Required Products MATLAB
MATLAB release MATLAB 8.2 (R2013b)
Other requirements Requires internet connection. If using a pre-R2013b MATLAB, then Statistics Toolbox is also required and the unit testing will not work.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (17)
06 Dec 2014 Jan

works very well.

31 Jul 2014 Frédéric  
27 Jul 2014 Michael Weidman

Steven: The error message indicates that calculateAdjustedClose.m is not on the MATLAB path.

It is certainly included in the above ZIP-archive, so please ensure that you have extracted ALL of the files in the archive and added them to the path.

24 Jul 2014 Steven Shimizu

I'm running 2013a MATLAB with the Statistics Toolbox. I get an error when I run the example:
>> [data, dividends] = getGoogleDailyData({'NASDAQ:MSFT', 'EPA:ML'}, ...
'01/01/2010', '01/01/2013', 'dd/mm/yyyy');

Undefined function 'calculateAdjustedClose' for input
arguments of type 'double'.

Error in getGoogleDailyData (line 128)
ds.AdjClose = ...

What is the issue?

08 Jun 2014 Nikolaos Zikas  
27 May 2014 francesco  
26 May 2014 alexandre iolov  
19 Mar 2014 David

Nevermind! Got it working. Just had to replace "today" with a lowercase "now"

19 Mar 2014 David

Any advice??
I try and execute
[stock_data] = get_gf_histdata('NYSE:GE');

and i get :
Undefined function or variable 'today'.

Error in get_gf_histdata (line 23)
enddate=[datestr(today,3) '+' datestr(today,7) '%2C+' datestr(today,10)];

06 Mar 2014 Benjamin  
06 Mar 2014 Benjamin

Excellent Submission, I was using excel for this using Hoadley Option Add in... Scrap that now.

Amazingly simple to use file.

Thanks Michael!

10 Jan 2014 Michael Weidman

Thanks for catching that, Hugh. I had forgotten that the TODAY function is a part of Financial Toolbox (for some strange reason). You can always replace TODAY with FLOOR(NOW), or (in the context that this function applies it) you can just use NOW.

I've posted an update to this File Exchange submission accordingly, and it should publicly appear soon. Thanks!

09 Jan 2014 Hugh

The yahoo code worked for me, but the google code has an error: "today" is a valid matlab function.

I changed "today" to "date", but this leads to other errors.


16 Dec 2013 francesco  
01 Dec 2013 mohammed

In your first point, I'm not certain what you mean. When DATEVEC is used in this code, it's always passed dates in a numeric format (which is a valid syntax). Date formatting conventions don't enter the picture as far as DATEVEC is concerned.

06 Nov 2013 Michael Weidman

Hi, engineer!

In your first point, I'm not certain what you mean. When DATEVEC is used in this code, it's always passed dates in a numeric format (which is a valid syntax). Date formatting conventions don't enter the picture as far as DATEVEC is concerned.

For your second point, you're correct that the code does not make any adjustments for splits. In fact, only Google even reports when the splits occurred. My investigations concluded that both Yahoo! and Google already adjust for splits in both their raw closing prices and their volume data, so I just took that as a given. I'm happy to hear if you find that further adjustments need to be made.

Resampling the data to weekly or monthly intervals is beyond the scope of this submission. Perhaps you can create such an enhancement and submit it to the file exchange!

Finally, I'm unsure what you mean by your comment involving plotting: there is no data plotting in this submission. That said, I've found the dynamic date tick submission at to be incredibly useful when I try to plot time series like these.

04 Nov 2013 engineer

Pretty good Michael. There are two errors in your code, however:

datevec() uses mm/dd/yyyy format (which is well established in the U.S.), not dd/mm/yyyy. This makes a difference in the data that is returned.

Also, for splits, I believe that the volume must also be adjusted. I havn't looked into this yet, so I'm not sure how that will end up looking.

This code could be modified to also return weekly and monthly data (not just daily). This may require a separate query which you would then need to edit your existing daily structure (or Table) to add the OHLC weekly/monthly data. An alternative is to calculate these directly from the daily OHLC, however, non-trading days would make this rather cumbersome.

After returning the data from Yahoo!, datenum() is used so that the data can be easily plotted. Within the plot function, it is possible to get the handle for x-axis and plot the actual date corresponding to the matlab generated number.

10 Jan 2014

Small change to getGoogleDailyData to remove dependence on Financial Toolbox.

Contact us