(return to David's Python Resources)

YahooQuote

Python Stockmarket Price/History Fetcher Classes

YahooQuote is a module with convenient, pythonic classes for fetching stockmarket prices and histories from finance.yahoo.com.

Features

Doco and Download

Example Usage

  >>> import YahooQuote

  >>> market = YahooQuote.Market()

  >>> market['rht']
  <Ticker for rht>

  >>> market['rht'][20040203]
  <Quote:rhat:20040203:O=18.05,H=18.21,L=17.68,C=17.85,V=5828400,A=17.85>

  >>> market['rht'].now  # magic attribute via __getattr__

  <Quote:rhat:20040415:O=24.74,H=25.34,L=24.50,C=25.00,V=2840059,A=-1.00>

  >>> msft = market['msft']

  >>> msft[20040407:20040414]  # get range of dates as slice
  [<Quote:msft:20040407:O=25.74,H=25.78,L=25.35,C=25.59,V=63268900,A=25.59>,
   <Quote:msft:20040408:O=25.82,H=25.85,L=25.36,C=25.48,V=45294600,A=25.48>,
   <Quote:msft:20040412:O=25.48,H=25.74,L=25.43,C=25.61,V=38786800,A=25.61>,
   <Quote:msft:20040413:O=25.68,H=25.77,L=25.41,C=25.45,V=56971500,A=25.45>]

  >>> msft[20040410]  # easter saturday, no trading, interpolate (!!)

  <Quote:msft:20040410:O=25.65,H=25.80,L=25.39,C=25.55,V=0,A=25.55>

  >>> lastThu = msft[20040408]
  >>> lastThu.__dict__
  {'_fetcher': <YahooQuote.Fetcher instance at 0x403ba42c>,
   'adjclose': 25.48,
   'close': 25.48,
   'date': 20040408,
   'high': 25.850000000000001,
   'low': 25.359999999999999,
   'open': 25.82,
   'symbol': 'msft',
   'volume': 45294600}