Exemplo n.º 1
0
def get_symbol_frame(**kwargs):

    frame_type = kwargs['frame_type']
    settle_date = kwargs['settle_date']

    if frame_type == 'nasdaq':
        symbol_address = nasdaq_symbol_address
    elif frame_type == 'other':
        symbol_address = other_symbol_address

    output_dir = dn.get_directory_name(ext='stock_data')
    file_name = output_dir + '/' + frame_type + '_' + str(settle_date) + '.pkl'

    if os.path.isfile(file_name):
        return pd.read_pickle(file_name)
    else:

        datetime_now = dt.datetime.now()

        if datetime_now.weekday() in [5, 6]:
            last_settle_date = exp.doubledate_shift_bus_days()
        elif 100 * datetime_now.hour + datetime_now.minute > 930:
            last_settle_date = cu.get_doubledate()
        else:
            last_settle_date = exp.doubledate_shift_bus_days()

        if settle_date == last_settle_date:

            data_list = sd.download_txt_from_web(web_address=symbol_address)
            column_names = data_list[0].decode('iso-8859-1').split("|")
            parset_data_list = [
                data_list[x].decode('iso-8859-1').split("|")
                for x in range(1,
                               len(data_list) - 1)
            ]
            symbol_frame = pd.DataFrame(parset_data_list, columns=column_names)
            symbol_frame.to_pickle(file_name)
        else:
            symbol_frame = pd.DataFrame()

    return symbol_frame
Exemplo n.º 2
0
commodity_address = 'ftp://ftp.cmegroup.com/pub/settle/stlags'
equity_address = 'ftp://ftp.cmegroup.com/pub/settle/stleqt'
fx_address = 'ftp://ftp.cmegroup.com/pub/settle/stlcur'
interest_rate_address = 'ftp://ftp.cmegroup.com/pub/settle/stlint'
comex_futures_csv_address = 'ftp://ftp.cmegroup.com/pub/settle/comex_future.csv'
comex_options_csv_address = 'ftp://ftp.cmegroup.com/pub/settle/comex_option.csv'
nymex_futures_csv_address = 'ftp://ftp.cmegroup.com/pub/settle/nymex_future.csv'
nymex_options_csv_address = 'ftp://ftp.cmegroup.com/pub/settle/nymex_option.csv'

#folder_date = cu.get_doubledate()
folder_date = exp.doubledate_shift_bus_days()

options_data_dir = dn.get_dated_directory_extension(folder_date=folder_date,
                                                    ext='raw_options_data')

commodity_output = sd.download_txt_from_web(web_address=commodity_address)
equity_output = sd.download_txt_from_web(web_address=equity_address)
fx_output = sd.download_txt_from_web(web_address=fx_address)
interest_rate_output = sd.download_txt_from_web(
    web_address=interest_rate_address)

comex_futures_output = sd.download_csv_from_web(
    web_address=comex_futures_csv_address)
comex_options_output = sd.download_csv_from_web(
    web_address=comex_options_csv_address)

nymex_futures_output = sd.download_csv_from_web(
    web_address=nymex_futures_csv_address)
nymex_options_output = sd.download_csv_from_web(
    web_address=nymex_options_csv_address)
import ta.prepare_daily as prep

commodity_address = 'ftp://ftp.cmegroup.com/pub/settle/stlags'
equity_address = 'ftp://ftp.cmegroup.com/pub/settle/stleqt'
fx_address = 'ftp://ftp.cmegroup.com/pub/settle/stlcur'
interest_rate_address = 'ftp://ftp.cmegroup.com/pub/settle/stlint'
comex_futures_csv_address = 'ftp://ftp.cmegroup.com/pub/settle/comex_future.csv'
comex_options_csv_address = 'ftp://ftp.cmegroup.com/pub/settle/comex_option.csv'
nymex_futures_csv_address = 'ftp://ftp.cmegroup.com/pub/settle/nymex_future.csv'
nymex_options_csv_address = 'ftp://ftp.cmegroup.com/pub/settle/nymex_option.csv'

folder_date = cu.get_doubledate()

options_data_dir = dn.get_dated_directory_extension(folder_date=folder_date, ext='raw_options_data')

commodity_output = sd.download_txt_from_web(web_address=commodity_address)
equity_output = sd.download_txt_from_web(web_address=equity_address)
fx_output = sd.download_txt_from_web(web_address=fx_address)
interest_rate_output = sd.download_txt_from_web(web_address=interest_rate_address)

comex_futures_output = sd.download_csv_from_web(web_address=comex_futures_csv_address)
comex_options_output = sd.download_csv_from_web(web_address=comex_options_csv_address)

nymex_futures_output = sd.download_csv_from_web(web_address=nymex_futures_csv_address)
nymex_options_output = sd.download_csv_from_web(web_address=nymex_options_csv_address)

with open(options_data_dir + '/commodity.pkl', 'wb') as handle:
        pickle.dump(commodity_output, handle)

with open(options_data_dir + '/equity.pkl', 'wb') as handle:
        pickle.dump(equity_output, handle)