def fetch_historical_yahoo(ticker, date1, date2, cachename=None):
ticker = ticker.upper()<EOL>d1 = (date1.month-<NUM_LIT:1>, date1.day, date1.year)<EOL>d2 = (date2.month-<NUM_LIT:1>, date2.day, date2.year)<EOL>urlFmt = '<STR_LIT>'<EOL>url =  urlFmt % (d1[<NUM_LIT:0>], d1[<NUM_LIT:1>], d1[<NUM_LIT:2>],<EOL>d2[<NUM_LIT:0>], d2[<NUM_LIT:1>], d2[<NUM_LIT:2>], ticker)<EOL>if cachename is None:<EOL><INDENT>cachename = os.path.join(cachedir, md5(url).hexdigest())<EOL><DEDENT>if os.path.exists(cachename):<EOL><INDENT>fh = file(cachename)<EOL>verbose.report('<STR_LIT>'%(cachename, ticker))<EOL><DEDENT>else:<EOL><INDENT>if not os.path.isdir(cachedir): os.mkdir(cachedir)<EOL>fh = file(cachename, '<STR_LIT:w>')<EOL>fh.write(urlopen(url).read())<EOL>fh.close()<EOL>verbose.report('<STR_LIT>'%(ticker, cachename))<EOL>fh = file(cachename, '<STR_LIT:r>')<EOL><DEDENT>return fh<EOL>
Fetch historical data for ticker between date1 and date2.  date1 and
date2 are datetime instances

Ex:
fh = fetch_historical_yahoo('^GSPC', d1, d2)

cachename is the name of the local file cache.  If None, will
default to the md5 hash or the url (which incorporates the ticker
and date range)

a file handle is returned