Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit

Saint Louis University

Computer Science 144
Introduction to Computer Science: Multimedia

Michael Goldwasser

Spring 2015

Dept. of Math & Computer Science

Gathering Stock Data from Yahoo

Interestingly, Yahoo Finance seems to provides an (undocumented and unsupported) interface for requesting current or historical stock data in a CSV format. They do limit you to a maximum frequency of requests so that you don't overly tax their servers, and their Terms of Service only allow use of this interface for non-commercial purposes (such as education!).

Some informative explanations of the interface can be found at:

We provide only the briefest of summaries.

To get the most current quote for one or more stocks (although likely with 5-minute delay during market hours), you can use a URL such as:
http://finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG&f=snvb3gh
where the AAPL+GOOG can be any combination of one or more stock symbols, and the symbols after the f= parameter describes which fields you wish to be sent. (In our example s is symbol, n is name, v is volume, b3 is real-time bid, g  is daily low and h  is daily high.)

Historical data can be retrieved at either daily, weekly, or monthly intervals, using a url such as:
http://ichart.yahoo.com/table.csv?s=AAPL&a=3&b=3&c=2010&d=10&e=2&f=2012&ignore=.csv
For this syntax, the parameters a, b, and c define a start of the historical query range, respectively as month, date, and year. Note well that they use an unusual convention where months are zero-indexed (e.g., January is 0), yet dates and years use natural values. Similarly, parameters d, e, and f define the end of the query range. It is also worth nothing that these results include a first header line, and then all entries ordered in reverse chronological order (i.e., most recent first).


Michael Goldwasser
CSCI 144, Spring 2015
Last modified: Wednesday, 08 April 2015
Assignments | Course Home | Documentation | Lab Hours/Tutoring | Schedule | Submit