예제 #1
0
def get_options_dict(ticker_list,warm_dict=None):

    if not warm_dict:
        tdict={}
    else:
        tdict=warm_dict

    for ticker in ticker_list:

        if not tdict.has_key(ticker):

            print '****\n****\n**** getting for %s\n****\n****' % ticker
            op   = Options(ticker, 'yahoo')

            try:

                data = op.get_all_data()
                up   = op.underlying_price
                time.sleep(1200)
                tdict[ticker]={'data':data,'up':up}

            except pd.io.data.RemoteDataError:

                print'Request Refused, Dumping and Exiting...'
                cPickle.dump(tdict,open('warm_dict.pkl','wb'))
                sys.exit(0)


        

    return tdict
예제 #2
0
 def __validate_source_connection__(self):
     """ Check internet connection """
     test_stock = 'AAPL'
     try:
         aapl = Options(test_stock, self.source)
         data = aapl.get_all_data()
         return True
     except Exception:
         return False
예제 #3
0
    def pull_data(self, ticket_list):
        """
        Pull online option data
        :param ticket_list: list contains tickets you want to download
        :return: option data dict, in the form of [ ticket : DataFrame, ... ]
        """
        if isinstance(ticket_list, str):
            ticket_list = (ticket_list, )

        option_dict = {}
        for ticket in ticket_list:
            print "Pull Option Data : %s ..." % ticket
            try:
                option_method = Options(ticket, self.source)
                option_dict[ticket] = option_method.get_all_data()
                if len(option_dict[ticket]) == 0:
                    print "Length of data is Zero during the time asked"
            except Exception as err_message:
                option_dict[ticket] = None
                print "Exception: %s" % err_message
                # raise RuntimeError("Can't not download Stock: %s" % stock)
        return option_dict
예제 #4
0
import pandas as pd, datetime
from pandas_datareader import data

# Stocks
start=datetime.datetime(2013, 1, 1)
end=datetime.datetime(2015, 9, 30)
s = data.DataReader("SSW", 'yahoo', start, end)
print s.head()

# Options

from pandas.io.data import Options

aapl = Options('AAPL',"yahoo")
df = aapl.get_options_data()
print df.head()
예제 #5
0
import time
import math

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
"""
  Name     : 4375OS_10_34_get_option_data_given_year_month.py
  Book     : Python for Finance
  Publisher: Packt Publishing Ltd. 
  Author   : Yuxing Yan
  Date     : 12/26/2013
  email    : [email protected]
             [email protected]
"""

from pandas.io.data import Options
ticker='IBM'
month=2
year=2014
x = Options(ticker,'yahoo')
puts,calls = x.get_options_data(month,year)

print puts.head()

예제 #7
0
def call_data(tickrr, exp_date):
    x = Options(ticker, 'yahoo')
    data = x.get_call_data(expiry=exp_date)
    return data
def get_straddle():
    options = Options("AAPL", "yahoo")
    call = get_price(options, True, False)
    put = get_price(options, False, True)
    return call + put
def get_option_data(tickrr, exp_date):
    x = Options(ticker, 'yahoo')
    puts, calls = x.get_options_data(expiry=exp_date)
    return puts, calls
예제 #10
0
start = dt.datetime(2015, 1, 1)
msi = web.DataReader('msi', 'yahoo', start)
msi['Close'].plot()

#%%
"""
Options data -- doesn't work
http://pandas.pydata.org/pandas-docs/stable/remote_data.html#yahoo-finance-options
"""
import pandas as pd
print('Pandas version:', pd.__version__)

from pandas.io.data import Options

aapl = Options('aapl', 'yahoo')
data = aapl.get_all_data()

#%%
"""
convert do file to pandas format and variable labels
CPS
http://www.nber.org/data/cps_progs.html
MEPS
http://meps.ahrq.gov/mepsweb/data_stats/download_data_files_detail.jsp?cboPufNumber=HC-155
"""
import pandas as pd
url = 'http://www.nber.org/data/progs/cps/cpsmar2014.dct'
pd.read_csv(url, sep='\s+')

#open(url).read()
"""
  Name     : 4375OS_10_33_option_data_Yahoo.py
  Book     : Python for Finance
  Publisher: Packt Publishing Ltd. 
  Author   : Yuxing Yan
  Date     : 12/26/2013
  email    : [email protected]
             [email protected]
"""

from pandas.io.data import Options
x = Options('IBM', 'yahoo')
puts, calls = x.get_options_data()

print calls.head()
예제 #12
0
 def get_option_data(self, symbol):
     aapl = Options(symbol, 'google')
     data = aapl.get_all_data()
     return data
예제 #13
0
        options.rror.iloc[i] = (p / -l)

    options = options.drop(['sv', 'lv'], axis=1)

    return options


###############################################################################
#           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:
예제 #14
0
from pandas.io.data import Options

aapl = Options('AAPL')
vals = aapl.get_options_data()
print(vals)
예제 #15
0
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 16 18:02:31 2015

@author: justin.malinchak
"""

#import pullprices_optionsonly as pp
#
#pp.options('VIX',
#        '2015-07-17',
#        'c:\\Batches\\$Work')

from pandas.io.data import Options
temp = Options('SPY', 'yahoo')
z = temp.get_options_data(7, 2014)
print z
예제 #16
0
from pandas.io.data import Options
spy = Options('spy', 'yahoo')
chain = spy.get_all_data()