Code covered by the BSD License  

Highlights from
Download Google Finance Stock Prices

4.0

4.0 | 1 rating Rate this file 36 Downloads (last 30 days) File Size: 2.05 KB File ID: #27907
image thumbnail

Download Google Finance Stock Prices

by Fayssal El Moufatich

 

15 Jun 2010

Download historical stock prices from Google Finance in a dataset MATLAB format.

| Watch this File

File Information
Description

PURPOSE: Download the historical prices for a given stock from Google Finance and converts it into a MATLAB dataset format.

USAGE: ds = googleprices(stockTicker, startDate, endDate)
where:

stockTicker = Google stock ticker ExchangeSymbol:SecuritySymbol), ex. NASDAQ:CSCO for Cisco Stocks.

startDate: start date of the prices series. It could be either in
serial MATLAB form or in Google Date form (mmm+dd,yyyy).
       
endDate: end date of the prices series. It could be either in
serial matlab form or in Google Date form (mmm+dd,yyyy).

Example:

ds = googleprices('NASDAQ:CSCO', 'Oct+1,2000', 'Jun+15,2010');

MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
17 Jun 2010 mklcst mklcst

Good Idea, I think you should implement all index components download for a given one!

17 Jun 2010 Fayssal El Moufatich

I will be including some more features soon :).

21 Jun 2010 mklcst mklcst

:-) very good!

21 Aug 2010 Michael

Code isn't working. I think google, yahoo, and such do not want mass and automated downloading of their information.

01 Sep 2010 Fayssal El Moufatich

Interesting! I did not try it a very on a long loop, but It actually works for me still!

24 Jun 2011 Paulo Fonte

Unfortunately, at this time is seems to work only for US and UK stocks.

25 Jun 2011 Paulo Fonte

This snippet will scan the google finance page and generate a csv-like page. Some obvious variables must be predefined. It is limited to 200 days (max in a single google finance page).

url=['http://finance.google.co.uk/finance/historical?q=' codes{n} '&startdate=' MONTHst '+' num2str(Dst) ',+' num2str(Yst) '&enddate=' MONTHend '+' num2str(Dend) ',+' num2str(Yend) '&num=200'];
page=urlread(url);
[tokenDate]=regexp(page,'<td class="lm">(\w{3} \d*, \d*)','tokens');
[tokenOHLC]=regexp(page,'<td class="rgt">(\d*.\d*)','tokens');
[tokenV]=regexp(page,'<td class="rgt rm">([\d,]*)','tokens');
tokenOHLC=reshape(tokenOHLC,4,[]);

newpage=['Date,Open,High,Low,Close,Volume,Adj Close'];
for n=1:length(tokenDate)
    newpage=[newpage char(10), ...
        datestr(datenum(tokenDate{n},'mmm dd, yyyy'),29), ',' ...
        char(regexprep(tokenOHLC{1,n},',','')) ',', ...
        char(regexprep(tokenOHLC{2,n},',','')) ',', ...
        char(regexprep(tokenOHLC{3,n},',','')) ',', ...
        char(regexprep(tokenOHLC{4,n},',','')) ',', ...
        char(regexprep(tokenV{n},',','')) ',0'];
end

15 Nov 2011 Debi  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
google finance Fayssal El Moufatich 15 Jun 2010 13:45:13
urlwrite Fayssal El Moufatich 15 Jun 2010 13:45:13
dataset Fayssal El Moufatich 15 Jun 2010 13:45:13
url Fayssal El Moufatich 15 Jun 2010 13:45:13
stock prices Fayssal El Moufatich 15 Jun 2010 13:45:13

Contact us at files@mathworks.com