Module YahooQuote
YahooQuote - a set of classes for fetching stock quotes from
finance.yahoo.com
Created by David McNab ((david AT conscious DOT co DOT nz))
Originally this was a wrapper of the original 'pyq' utility by Rimon
Barr:
-
http://www.cs.cornell.edu/barr/repository/pyq/index.html
But now, the back-end has been completely re-written.
This new version of YahooQuote stores its cache of retrieved histories
in a fast MetaKit database file, ~/.yahooquote/stocks.db
Usage Examples:
>>> import YahooQuote
>>> market = YahooQuote.Market()
>>> redhat = market['rht']
>>> redhat
<Ticker:rht>
>>> redhat[20070601]
<Quote:rht/20070601:m=-0.31 o=24.88 c=24.57 l=24.40 h=25.25 a=24.57 v=8579200>
>>> redhat.now # magic attribute via __getattr__
<Quote:rht/20071506:m=-0.22 o=23.50 c=23.28 l=23.22 h=23.75 a=23.28 v=1185200>
>>> ms = market['msft']
>>> ms
<Ticker:msft> # note the 'dji/msft', meaning that MS is on DJI index
>>> ms[20070604:20070609] # get range of dates as slice - Jun4 - Jun8
[<Quote:msft/20070604:m=+0.30 o=30.42 c=30.72 l=30.40 h=30.76 a=30.72 v=41434500>,
<Quote:msft/20070605:m=-0.04 o=30.62 c=30.58 l=30.33 h=30.63 a=30.58 v=44265000>,
<Quote:msft/20070606:m=-0.08 o=30.37 c=30.29 l=30.25 h=30.53 a=30.29 v=38217500>,
<Quote:msft/20070607:m=-0.40 o=30.02 c=29.62 l=29.59 h=30.29 a=29.62 v=71971400>]
>>> lastThu = ms[20070614] # fetch a single trading day
>>> lastThu
<Quote:msft/20070614:m=+0.17 o=30.35 c=30.52 l=30.30 h=30.71 a=30.52 v=59065700>
>>> lastThu.__dict__ # see what is in a Quote object
{'volume': 59065700, 'open': 30.350000000000001, 'high': 30.710000000000001,
'adjclose': 30.52, 'low': 30.300000000000001, 'date': '20070614',
'close': 30.52, 'ticker': <Ticker:dji/msft>}
>>> ms[20070603] # sunday, markets closed, build dummy quote from Friday
<Quote:msft/20070603:m=0.00 o=30.59 c=30.59 l=30.59 h=30.59 a=30.59 v=0>
Read the API documentation for further features/methods
| Classes |
Index |
encapsulates a stock index, eg 'dji' for dow jones |
Market |
Main top-level class for YahooQuote. |
Quote |
dumb object which wraps quote data |
QuoteDate |
Simple int subclass that represents yyyymmdd quote dates |
Ticker |
Represents the prices of a single ticker symbol. |