tags:

views:

450

answers:

4

I'd like to be able to pass in a stock symbol and a date to pull in the closing price. Does anyone know of any good free api's? This is for non-commercial use if that matters.

+1  A: 

Last I looked, you could grab historical data for a range of dates from yahoo, though I don't know the limitations in their TOS. You could specify a pretty decent range and get the data in a spreadsheet or csv. You'd want to cache it heavily, I'd expect.

retracile
+1, I used that Yahoo service for a personal worksheet too, but I preferred to took current (= -15 min) price to calculate options greek variables.
Rubens Farias
I took a look at http://www.gummy-stuff.org/Yahoo-data.htm, which gives a fantastic breakdown of the yahoo api - but that page (and anything else i've found) doesn't seem to tell me about a date reference. There is lots regarding moving averages, % changes, but nothing to pick a closing price on a particular date.
Prescott
@Rubens - Unfortunately I'm trying to do some analysis on older stuff, so I need to pull in a ton of old closing prices
Prescott
@Prescott, see my answer.
Nosredna
A: 

Yahoo Finance lets you export their data. For a ticker, on the left sidebar there is a link to Historical Prices. On the bottom of that page there is a link "Download To Spreadsheet".

You could pass that to fgetcsv to parse it.

Alex L
+2  A: 

The easiest way I know of is with the Yahoo Finance API. Here is a handy chart that shows all the options you can pass in (READ THE WHOLE POST, as it has been updated at the bottom):

http://ilmusaham.wordpress.com/tag/stock-yahoo-data/

Be aware of a few things:

1) Know the difference between unadjusted and adjusted prices. Splits will make your comparisons meaningless if you aren't careful.

2) Don't forget the effect of mergers and spin-offs. Go back far enough and you're almost sure to have nonsense. For example, think about the case of AT&T, which was bought, disappeared for awhile, and then the name was resurrected. Decades of AT&T's actual price history is now unavailable.

Nosredna
A: 

yahoo finance can help: For example, for Apple stock: http://ichart.yahoo.com/table.csv?s=AAPL&d=11&e=6&f=2009&g=d&a=8&b=7&c=1984&ignore=.csv

The parameters of the request are pretty straightforward (s is for the stock symbol, f and c are for the range, in years. You can retrieve the data in python with the urllib module, and parse them with the csv module. It should be quite easy, but I can give you a piece of code. If you put it in a hastable, with keys set to dates in iso format (yyyy-mm-dd), it should be quite easy one closing price.

Besides, the best quality of (commercial and very expensive) data, can be found with the bloomberg API (Java, C, and C++).

LeMiz
Is Bloomberg as good as CRSP?
Nosredna
I don't know what you mean by "cool", hey it's financial data ? And I don't know CRSP. But bloomberg is very reliable, comprehensive and termsheets often refers directly to them for fixings. Their server API is quite good, and performance is there. Support is correct. But licensing terms are very restrictive. On niche data (long history intraday's, intraday options prices, financial analysis,...) they are other vendors that are better, as for rates, fx, cds spreads, and so on.
LeMiz