Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the closing price of a stock for a particular date [closed]

Tags:

api

stocks

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.

like image 810
Prescott Avatar asked Dec 06 '09 00:12

Prescott


2 Answers

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.

like image 199
Nosredna Avatar answered Sep 27 '22 23:09

Nosredna


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

like image 22
LeMiz Avatar answered Sep 27 '22 22:09

LeMiz