开发者

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

开发者 https://www.devze.com 2022-12-13 04:02 出处:网络
Closed. This question does not meet Stack开发者_如何学Python Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack开发者_如何学Python Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 4 years ago.

Improve this question

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消