t1 = time.time() options = pd.read_csv("options.csv") tickers = options['Symbol'] #tickers=['GNW','MBI','VLO','BP'] yahoo_cap_url = 'http://finance.yahoo.com/d/quotes.csv?s=' bank_roll = 14000 offers = [] for e in tickers: expiry_2 = (2018, 1) expiry_1 = (2017, 1) tick = Options(e, 'yahoo') try: frame = tick.get_call_data(month=expiry_2[1], year=expiry_2[0]) a = list(frame.index) except: try: frame = tick.get_call_data(month=expiry_1[1], year=expiry_1[0]) a = list(frame.index) except: print e pass strike = [] for e in a: strike.append(e[0]) frame['Strike'] = strike frame['Mark'] = frame["Bid"] + ((frame["Ask"] - frame["Bid"]) / 2) frame['Ratio'] = frame['Strike'] / frame['Mark']
today = dt.date.today() one_week = dt.timedelta(days=7) start = today - one_week stock = web.DataReader(ticker, 'yahoo', start) print(stock.tail()) # just to see what we have # take the last close (that's what the -1 does) atm = stock.ix[-1,'Close'] # the -1 takes the last observation #%% # get option prices for same ticker # http://pandas.pydata.org/pandas-docs/stable/remote_data.html#yahoo-finance-options option = Options(ticker, 'yahoo') expiry = dt.date(2014, 12, 20) data_calls = option.get_call_data(expiry=expiry) data_puts = option.get_put_data(expiry=expiry) print(data_calls.tail()) print(data_puts.tail()) #%% # plot puts v strike, call v strike calls_bid = data_calls['Bid'] calls_ask = data_calls['Ask'] calls_strikes = data_calls['Strike'] calls_mid = (data_calls['Bid'] + data_calls['Ask'])/2 puts_strikes = data_puts['Strike'] puts_mid = (data_puts['Bid'] + data_puts['Ask'])/2
def call_data(tickrr, exp_date): x = Options(ticker, 'yahoo') data = x.get_call_data(expiry=exp_date) return data
############################################################################### securities = ['spy', 'iwm', 'qqq', 'aapl', 'nflx', 'kmx'] for s in securities: try: opt = Options(s, 'yahoo') today = datetime.datetime.today() today = datetime.date(today.year, today.month, today.day) for e in opt.expiry_dates: if (e - today).days > 4 and (e - today).days < 15: expiry = e call = opt.get_call_data(expiry=expiry) price = call.Underlying_Price[0] prices, p = cdf(s, expiry, price) bull = bull_call_spread() if bull.empty: print('%s is Empty' %s) else: print(filter_options('bull', prices, p, bull[bull.rror > 0.1], 0.3)) bear = bear_call_spread()
# Calculate Best Options for multiple indexes and secruities ############################################################################### securities = ['spy', 'iwm', 'qqq', 'aapl', 'nflx', 'kmx'] for s in securities: try: opt = Options(s, 'yahoo') today = datetime.datetime.today() today = datetime.date(today.year, today.month, today.day) for e in opt.expiry_dates: if (e - today).days > 4 and (e - today).days < 15: expiry = e call = opt.get_call_data(expiry=expiry) price = call.Underlying_Price[0] prices, p = cdf(s, expiry, price) bull = bull_call_spread() if bull.empty: print('%s is Empty' % s) else: print(filter_options('bull', prices, p, bull[bull.rror > 0.1], 0.3)) bear = bear_call_spread() if bear.empty: print('%s is Empty' % s)
today = dt.date.today() one_week = dt.timedelta(days=7) start = today - one_week stock = web.DataReader(ticker, 'yahoo', start) print(stock.tail()) # just to see what we have # take the last close (that's what the -1 does) atm = stock.ix[-1, 'Close'] # the -1 takes the last observation #%% # get option prices for same ticker # http://pandas.pydata.org/pandas-docs/stable/remote_data.html#yahoo-finance-options option = Options(ticker, 'yahoo') expiry = dt.date(2014, 12, 20) data_calls = option.get_call_data(expiry=expiry) data_puts = option.get_put_data(expiry=expiry) print(data_calls.tail()) print(data_puts.tail()) #%% # plot puts v strike, call v strike calls_bid = data_calls['Bid'] calls_ask = data_calls['Ask'] calls_strikes = data_calls['Strike'] calls_mid = (data_calls['Bid'] + data_calls['Ask']) / 2 puts_strikes = data_puts['Strike'] puts_mid = (data_puts['Bid'] + data_puts['Ask']) / 2
def call_data(tickrr,exp_date): x = Options(ticker,'yahoo') data= x.get_call_data(expiry=exp_date) return data
from pandas.io.data import Options import datetime aapl = Options('AAPL', 'yahoo') expiry = datetime.date(2014, 5, 1) aapl.get_call_data(expiry=expiry)