View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Historical Stock Data Download (alternate Method)

5.0 | 1 rating Rate this file 11 Downloads (last 30 days) File Size: 6.83 KB File ID: #37502 Version: 1.0

Historical Stock Data Download (alternate Method)



Retrieves historical stock data from Yahoo Finance by parsing html pages instead of .csv download.

| Watch this File

File Information

This function is used to retrieve historical stock data from Yahoo Finance. I was using the the 'hist_stock_data.m' by Josiah Renfree (January 25, 2008)and it worked great but I noticed that it stopped working for the Dow Jones Industrial Average Index (^DJI). It turns out that due to some licensing issues, Yahoo is no longer permitted to give ^DJI data out in the .csv form that 'hist_stock_data.m' relied on. As I still wanted access to ^DJI, I hacked together this function to read the data not from .csv, but by parsing the html from displayed tables. Yahoo was still showing ^DJI data in this format.

This function will work with any valid Yahoo listed stock symbol, but will be
slower than 'hist_stock_data.m' because it has to do more work to extract the
data, including potentially reading dozens of pages to get it all. It goes to the first page, extracts the table data and reads the link for the next page of data and continues on till it gets it all. It then cleans it up and returns it in a tidy data structure.


Historical Stock Data Downloader inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.9 (R2009b)
Other requirements Requires internet access.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
13 Nov 2014 Josiah Renfree

Josiah Renfree (view profile)

Thanks for the info regarding the Dow Jones data. That's very odd and annoying, but it is what it is.

Comment only
01 Apr 2013 Guillaume

I use 7.6.0 version ( R2008a) and i have a problem with this function:

??? Input argument "ticker" is undefined.

Error in ==> get_yahoo_stockdata2 at 98

Do you have an idea to resolve this bug?
Thank you!

Comment only
24 Jan 2013 yan Chen


07 Nov 2012 Jia

Jia (view profile)

I'll try on R2012b then,see if it works.

Comment only
06 Nov 2012 SuperDude

I'm tried this in R2012b and did not get any errors.

Comment only
30 Oct 2012 Jia

Jia (view profile)

Hi there, I'm absolutely new to Matlab, when I run this function, it tell me

>> get_yahoo_stockdata2
Error: File: get_yahoo_stockdata2.m Line: 1 Column: 39
Unexpected MATLAB expression.

I'm running the R0212a version, is it the problem?

Comment only

Contact us