File Exchange

image thumbnail

STOCK QUOTE QUERY

version 1.0.0.0 (10.3 KB) by Michael Boldin
Pulls stock prices for a given ticker symbol from the YAHOO web server.

4 Downloads

Updated 20 Feb 2007

No License

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.

Comments and Ratings (30)

Tom Saam

I'm getting an error message, "??? Error using ==> StockQuoteQuery at 106
Could not connect to server. It may be unavailable. Try again later." After a few searches, I see that it's possible that Yahoo Finance has changed or eliminated the stock quote download API. Does anyone know if the URL format "http://table.finance.yahoo.com/table.csv?a=6&b=7&c=2016&d=6&e=7&f=2017&s=HRS&y=0&g=d" still works? I get a "server not found" when I try "http://table.finance.yahoo.com/" Any plan to update SQQ for a new API or perhaps Google Finance?

Devon Snell

Hello everyone,
does anyone know how to call this function more than once, to compare multiple stocks for instance. I get The server unavailable error on the second iteration.

Thank you

Panos

Hello everyone!I have been using this function to download data for stocks and it works pretty fine. However, i am trying to download currency data(exchange rates) from yahoo finance using this function and it is not possible.

Does anyone knows why is this and whether there is another function that could help me on this task?

giovanni

"??? Error using ==> StockQuoteQuery at 104
Could not connect to server. It may be unavailable. Try again later."

Solution:
in StockQuoteQuery.m go to the bottom of the code and change the yahooUrlString function as follow:

server = 'http://ichart.finance.yahoo.com/table.csv';

change also query:

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

it worked fine for me.

Amit K

Great m-file! However, lately I have been getting the following message:
"??? Error using ==> StockQuoteQuery at 104
Could not connect to server. It may be unavailable. Try again later."

Does anyone know what is the reason for this and how to fix it? I will appreciate the help.

AK

N/A

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.

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!?

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?

Henry Leung

Simple interface. A handy tool for stock data processing.

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.

Sarah P

One can use Matlab Datafeed toolbox in the latest version.

Satisfied User

Excellent script, works perfectly

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

James Cadzow

Greg:

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

Jim

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).

Fred Schlereth

Hi

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

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?

Larry Z

Wonderful tool!

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

Marcelo Scherer Perlin

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

Gert Van TOnder

MARVELOUS, THANKS MICHAEL BOLDIN!

wang bryne

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

LK Lee

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'];

Brian Edwards

Very useful. Saved me a lot of time!

Kam Moud

Fantastic function, very useful, good job

James Cadzow

A very useful program for obtaining stock market data.

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

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.

- -

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.

Updates

1.0.0.0

Fixed problem caused by YAHOO changing their date format.

Modified function to be R12 compatible

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

Inspired by: Display Stock Data

Inspired: GUI Technical Analysis Tool