Ejemplo n.º 1
0
def grab_options_prices(date_=datetime.datetime(2013,10,1)):
	mech = Browser()


	url = "http://finance.yahoo.com/q/op?s=SPY&m={0}-{1}".format(date_.year, date_.month)
	page = mech.open(url)

	html = page.read()
	soup = BeautifulSoup(html)

	tables = soup.findAll("table")
	#tables[4] ?
	#tables[8] ?
	#tables[9] ?
	#tables[12] ?
	#tables[13] ?
	#goes up to 17

	day = datetime.datetime.today()
	rows = [as_optionday(r, day, 0.0) for r in tables[4].findAll('tr') if is_optionday(r, day, 0.0)]
	rows = [r for r in rows if is_vanilla(r.option_name)]
	maturities = utility.sorted_groupby([r for r in rows], Options.Day.expiration_date)

	return [Options.make_quote(m[1]) for m in maturities]
Ejemplo n.º 2
0
def make_maturity_from_options(expiration_date, options):
	""" Builds a maturity data structure from a list of unsorted options with the same expiration date """
	assert(all([option.expiration_date() == expiration_date for option in options]))

	options = sorted(options, key=OptionsDay.quote_date)
	return Maturity(expiration_date, [make_quote_from_options(quote_date, options_) for quote_date, options_ in utility.sorted_groupby(options, OptionsDay.quote_date)])