No BSD License  

Highlights from
STOCK QUOTE QUERY

4.75

4.8 | 17 ratings Rate this file 37 Downloads (last 30 days) File Size: 10.29 KB File ID: #4069

STOCK QUOTE QUERY

by Michael Boldin

 

19 Oct 2003 (Updated 20 Feb 2007)

Pulls stock prices for a given ticker symbol from the YAHOO web server.

| Watch this File

File Information
Description

SQQ & STOCKQUOTEQUERY pull stock prices for a given ticker symbol
from the YAHOO web server using the MATLAB Java URL interface.

STOCKQUOTEQUERY has the main code. SQQ calls STOCKQUOTEQUERY and allows for either interactive (keyboard) inputs or as a function call with numerous options for setting dates.

Outputs
   DATE: Date for the quote
   CLOSE: Closing market price
   OPEN: Opening price
   HIGH: High price (during trading day or frequency period)
   LOW: Low price (during trading day or frequency period)
   VOLUME: Volume (during trading day or frequency period)
   CLOSEADJ: Close adjusted for splits

Use HELP SQQ for the full set of input and output options.

STOCKQUOTEQUERY is based on GETSTOCKDATA by Peter Webb of Mathworks, as explained in the October 2002 MATLAB News and Notes article "Internet Enabled Data Analysis and Visualization with MATLAB"

How to use SQQ & STOCKQUOTEQUERY
   --Enter 'sqq' at the comand line for an interactive run.
   --For a simple example that pulls recent data (over the past 7 days) for IBM,
       try sqq('ibm',today,today-7).
   --SQQEXAMPLE.M has more examples, including a demonstration of two different types
       of stock quote queries and also produces three charts.
      
How SQQ differs from GETSTOCKDATA
   --verifies YAHOO server tables have 7 elements on a line before parsing the line.
       The server tables sometimes show extra lines for dividend payments and splits.
   --close(breader); close(ireader); close(stream); commented out-- caused problems.
   --adjusts query parameters to refer to January as month '0', not '1', and February
       as '1', and so on. (This is a feature of the YAHOO system. STOCKQUOTEQUERY uses
       1 to 12 numbering for months in the input-output parameter translation.)
   --flips data vectors to normal date order (increasing, oldest to most recent).
   --does not require month(), day() or year() functions, uses datevec.
   --keeps VOLUME and CLOSEADJ data.
   --SQQ has flexible input options, especially for dates.
   --R12 compatible.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Display Stock Data
This submission has inspired the following:
GUI Technical Analysis Tool, Get Trading Data, from Yahoo, in your Matlab Workpace (or Excel)

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (25)
22 Oct 2003 - -

Why a 0 for January and not 1? Where are zero based months used? That doesn't seem very common. Looks like some nice improvements otherwise.

23 Oct 2003 Jim Cadzow

I am using MATLAB R12 and it does not have the command "strfind". I tried to replace this command with "findstr" which is in MATLA R12. Unfortunately, this does not seem to work. Could someone give me help in this matter. Thank You.

23 Oct 2003 Jim Cadzow

Does someone have a version of this program that works under MATLAB R12? If so, would you please send me a copy. Thanks

25 Nov 2003 James Cadzow

A very useful program for obtaining stock market data.

18 Dec 2003 Kam Moud

Fantastic function, very useful, good job

27 Mar 2004 Brian Edwards

Very useful. Saved me a lot of time!

14 Apr 2004 Brian Edwards

Yahoo seemed to have changed its query request syntax. I added/changed this code in StockQuoteQuery.m.

comments/suggestions-bmedward@syr.edu

%changed query string to work with new yahoo format. The month,variable a,
%is now represented by a 2 digit value, e.g. january=00, march=02,december=11 instead
%of older 0=jan, 2=march,december=11 format.
if((startMonth-1) < 10)
    a = ['0' num2str(startMonth-1)];
else a = num2str(startMonth-1);
end

query = ['?s=' num2str(symbol) '&a=' a '&b=' num2str(startDay) '&c=' num2str(startYear) ...
         '&d=' num2str(endMonth-1) '&e=' num2str(endDay) '&f=' num2str(endYear) ...
         '&g=d&ignore=.csv'];

23 Apr 2004 LK Lee  
04 May 2004 wang bryne

Not good performance for other symbols, such as 0325.hk etc. It can only extract at most 200 observations for such symbols.

17 Jan 2006 Gert Van TOnder

MARVELOUS, THANKS MICHAEL BOLDIN!

17 May 2006 Marcelo Scherer Perlin

Excellent. Too bad that yahoo server doesnt help much for commom stocks.

28 Nov 2006 james subbu

Good work!!

Do have one problem, does not work on the new Intetl Macs,
keeps crashing on java.net.url(UrlString),

is my Java messed up or does the pragoram need modification for the new macs??

thanks

02 Dec 2006 Larry Z

Wonderful tool!

08 Feb 2007 James Cadzow

I have had problems with StockQuoteQuery over the last 2 or 3 days. I am unable to download historical stock data and get the message "2007 is too large a number for month". Is there a fix for this problem?

10 Feb 2007 Fred Schlereth

Hi

get the same error message as mentioed by Mr Cadzow, above. Is there a fix?

11 Feb 2007 Greg Wdowiak

Change line 188 if StockQuoteQuery.m from

       date = datenum(dates);

to:

    date = datenum( dates, 'yyyy-mm-dd' );

(or use whatever date format /i.e. the 'yyyy-mm-dd' string/ may look like in your locale - I doubt that yahoo data would be locale-specific but who knows).

15 Feb 2007 James Cadzow

Greg:

I tried your recommendation of line 188 change and still unable to to download data.

Jim

17 Feb 2007 Michael Boldin

It see Yahoo changed their date format and the fix date=datenum(dates,'yyyy-mm-dd') worked for me, but I will post new code with a more robust solution
  

21 Apr 2007 Satisfied User

Excellent script, works perfectly

24 Jun 2007 Sarah P

One can use Matlab Datafeed toolbox in the latest version.

24 Jul 2008 Stefan Roth

Works nicely!
There's a little error popping up in the sqqexample.m line 17 though. It requires the year behind the dates or otherwise returns an error within StockQuoteQuery.m.

04 Sep 2008 Henry Leung

Simple interface. A handy tool for stock data processing.

08 Dec 2009 Gary

Michael, good code. Works great.
Say, Is there any way to access, download or otherwise account for stock spits? Using 'LMT' as an example, dates 01/01/1979 to present, for example: Code dutifully downloads historical data but is radically different from that displayed on Yahoo. This is due, largely, to the stock splits. Any way to include these details?

11 Mar 2010 smithjake01@gmail.com Jake

Hi, how to pass parameters through URL in matlab?

I am trying to pass the parameters (g = ) to the following link "http://tinygeocoder.com/create-api.php?g=33.790348,-117.226085" but wasn't successful. Could any one guide me please!?

19 Oct 2011 Amira Roula

Works great. BUT. It does not permit you to start at the IPO date of each stock, and end at today's date.

if you visit Yahoo Finance, the default values given to start date and end date are the IPO and today's date respectively.

I would rate this program a clear five star that function would be added.

Please login to add a comment or rating.
Updates
05 Dec 2003

Modified function to be R12 compatible

20 Feb 2007

Fixed problem caused by YAHOO changing their date format.

Tag Activity for this File
Tag Applied By Date/Time
finance Michael Boldin 22 Oct 2008 07:08:50
modeling Michael Boldin 22 Oct 2008 07:08:50
stock prices Michael Boldin 22 Oct 2008 07:08:51
analysis Michael Boldin 22 Oct 2008 07:08:51
internet data query Michael Boldin 22 Oct 2008 07:08:51
java inputstreamreader Michael Boldin 22 Oct 2008 07:08:51

Contact us at files@mathworks.com