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.
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.
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++).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With