Python - Yahoo Stock Quote Module
Python - Yahoo Stock Quote Module
Submitted by Corey Goldberg on Mon, 17/09/2007 - 20:16.Last week I wrote a small Python module for retrieving stock prices.
It used screen scraping to get data from Google Finance. Yahoo offers stock data in a much more digestible form which allowed me to get values without screen scraping and regular expressions. So, I wrote a module based around this.
This new module is much more comprehensive and exposes a Python API for retrieving all sorts of stock data from Yahoo Finance.
My ystockquote module provides a Python API for retrieving stock data from Yahoo Finance. This module contains the following functions:
- get_all(symbol)
- get_price(symbol)
- get_change(symbol)
- get_volume(symbol)
- get_avg_daily_volume(symbol)
- get_stock_exchange(symbol)
- get_market_cap(symbol)
- get_book_value(symbol)
- get_ebitda(symbol)
- get_dividend_per_share(symbol)
- get_dividend_yield(symbol)
- get_earnings_per_share(symbol)
- get_52_week_high(symbol)
- get_52_week_low(symbol)
- get_50day_moving_avg(symbol)
- get_200day_moving_avg(symbol)
- get_price_earnings_ratio(symbol)
- get_price_earnings_growth_ratio(symbol)
- get_price_sales_ratio(symbol)
- get_price_book_ratio(symbol)
- get_short_ratio(symbol)
Sample Usage:
>>> import ystockquote >>> print ystockquote.get_price('GOOG')
529.46 >>> print ystockquote.get_all('MSFT') {'stock_exchange': '"NasdaqNM"',
'market_cap': '268.6B', '200day_moving_avg': '29.2879', '52_week_high': '31.84', 'price_earnings_growth_ratio':
'1.45', 'price_sales_ratio': '5.33', 'price': '28.65', 'earnings_per_share': '1.423',
'50day_moving_avg': '28.7981', 'avg_daily_volume': '55579700', 'volume': '25330856',
'52_week_low': '26.48', 'short_ratio': '1.60', 'price_earnings_ratio': '28.65', 'dividend_yield':
'1.38', 'dividend_per_share': '0.40', 'price_book_ratio': '8.76', 'ebitda': '20.441B',
'change': '-0.39', 'book_value': '3.315'}
The module is available here: http://www.goldb.org/ystockquote.html
