示例#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 __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
def retrieve_option_chain(ticker="SPY"):
    spy_data = pandas.DataFrame()
    print(" --> Today's option chain not on system:         downloading it now... ")
    try:
        spy_options = Options(ticker, "yahoo")
        spy_data = spy_options.get_all_data()
        spy_data = spy_data.reset_index()
        if "Symbol" in spy_data.keys():
            spy_data = spy_data.set_index("Symbol")
        spy_data.to_csv(filename, date_format="%Y-%m-%d")
        # Load the data from the CSV you just wrote
        # (this ensures that re-shaping is always done
        #    by retrieve_option_chain_from_file() )
        spy_data = retrieve_option_chain_from_file(filename)
    except:
        print("Error with retrieving data. Please double-check the ticker symbol")
        return spy_data

    return spy_data
示例#5
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
示例#6
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
示例#7
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()
示例#8
0
 def get_option_data(self, symbol):
     aapl = Options(symbol, 'google')
     data = aapl.get_all_data()
     return data
"""
the usual checks
"""
import sys
import pandas as pd

print('\nPython version: ', sys.version)
print('\nPandas version: ', pd.__version__, '\n')

#%%
"""
Remote data access
"""
from pandas.io.data import Options
aapl = Options('aapl', 'yahoo')
data = aapl.get_all_data()



#%%
"""
Set up simple dataframes to play with
"""
# create arbitrary dataframe
gdp = [2, 5, 7, 9]
pop = [9, 6, 3, 10]
cty = ['USA', 'USA', 'FRA', 'FRA']
year = ['2010', '2011', '2012', '2013']

data = {'gdp': gdp, 'pop': pop, 'cty': cty}
df = pd.DataFrame(data=data, index=year)
示例#10
0
from pandas.io.data import Options
spy = Options('spy', 'yahoo')
chain = spy.get_all_data()