Пример #1
0
f = open(args.in_dir+'/datelist_'+args.dataset[:-3]+'.txt')
training_set_str = [line[:-1] for line in f]
training_set = [datetime.strptime(x, '%Y%m%d').replace(hour=9, minute=30) for x in training_set_str]

# file to backup console prints
log_file = open(args.out_dir+'/log_'+args.dataset[:-3]+'.txt', 'w')

today_data_all = {}
lkbk_days_data_all = {}
multiplier = {}

for i in range(len(training_set)):
    today = training_set[i]
    lkbk_days = utils.gen_lkbk_days(today=today)
    lkbk_days = [datetime.strptime(x,'%Y%m%d') for x in lkbk_days]
    utils._print(log_file,  'processing %s' % today)
    try:
        today_time_range = utils.day_time_range(today)
            
        vols = input_comp.ix[:, today, 'Volume']
        closes = input_comp.ix[:, today, 'Close']
        liqs = vols * closes
        liqs = liqs / liqs.sum()
        liqs = liqs.fillna(0)
        
        # get top input components by liquidity
        liqs = liqs[np.argsort(liqs)[::-1]]
        topn_input = liqs.index[:]
        
        multiplier[today] = liqs[topn_input]
        
Пример #2
0
    datetime.strptime(x, '%Y%m%d').replace(hour=9, minute=30)
    for x in training_set_str
]

# file to backup console prints
log_file = open(args.out_dir + '/log_' + args.dataset[:-3] + '.txt', 'w')

today_data_all = {}
lkbk_days_data_all = {}
multiplier = {}

for i in range(len(training_set)):
    today = training_set[i]
    lkbk_days = utils.gen_lkbk_days(today=today)
    lkbk_days = [datetime.strptime(x, '%Y%m%d') for x in lkbk_days]
    utils._print(log_file, 'processing %s' % today)
    try:
        today_time_range = utils.day_time_range(today)

        vols = input_comp.ix[:, today, 'Volume']
        closes = input_comp.ix[:, today, 'Close']
        liqs = vols * closes
        liqs = liqs / liqs.sum()
        liqs = liqs.fillna(0)

        # get top input components by liquidity
        liqs = liqs[np.argsort(liqs)[::-1]]
        topn_input = liqs.index[:]

        multiplier[today] = liqs[topn_input]
Пример #3
0
        print "no record found, maybe a holiday"

# backup file of console prints, just in case
f = open(dir_name+'/oost_'+start_day_str+'.txt', 'w')

sum_err = {}
ct = 0
for k in range(11): sum_err[k] = 0

for i in range(lkbk, 60, lkbk+1):
    try:
        today = training_set[i]
        today_data = today_data_all[today].ix[:10,:,:]
        lkbk_days_data = lkbk_days_data_all[today].ix[today_data.items,:,:]
        
        utils._print(f, '\n\n>>>>>>>>>>> set %d' % (i+1) )
        utils._print(f, 'today = %s' % today )
        utils._print(f, 'top10 '+ inputComponentIndexName +' components : %s' % today_data.items )

        close_name = '% Change(close)'
        liq_name = '% Change(liquidity)'

        today_close = today_data.ix[:,close_name,:]
        today_liq = today_data.ix[:,liq_name,:]
        today_close.columns = [(x + '_close') for x in today_close.columns]
        today_liq.columns = [(x + '_liq') for x in today_liq.columns]

        lkbk_close = lkbk_days_data.ix[:,close_name,:]
        lkbk_liq = lkbk_days_data.ix[:,liq_name,:]
        lkbk_close.columns = [(x + '_close') for x in lkbk_close.columns]
        lkbk_liq.columns = [(x + '_liq') for x in lkbk_liq.columns]
Пример #4
0
        stock_primary.columns = cols
        stock.columns = [ args.secondary[ index ]+' '+x for x in stock.columns]
        index = index + 1
    stock_primary = concat([stock_primary.ix[:,:-2],stock.ix[:,:-2],stock_primary.ix[:,-2:]], axis=1)
    
# file to backup console prints
log_file = open(args.out_dir+'/log_'+args.dataset[:-3]+'.txt', 'w')

today_data_all = {}
lkbk_days_data_all = {}

for i in range(len(training_set)):
    today = training_set[i]
    lkbk_days = utils.gen_lkbk_days(today=today)
    lkbk_days = [datetime.strptime(x,'%Y%m%d') for x in lkbk_days]
    utils._print(log_file,  'processing %s' % today)
    try:
        # generate date/time ranges for 'today'
        today_time_range = utils.day_time_range(today)
        lkbk_days_range = None
        for lkbk_day in lkbk_days:
            mins = utils.day_time_range(lkbk_day)
            if lkbk_days_range is None:
                lkbk_days_range = mins
            else:
                lkbk_days_range = lkbk_days_range.append(mins)
                    
        # get slice of data for 'today'
        today_data_all[today] = stock_primary.ix[today_time_range,:]
        lkbk_days_data_all[today] = stock_primary.ix[lkbk_days_range,:]
                                    
Пример #5
0
# backup file of console prints, just in case
f = open(dir_name + '/oost_' + start_day_str + '.txt', 'w')

sum_err = {}
ct = 0
for k in range(11):
    sum_err[k] = 0

for i in range(lkbk, 60, lkbk + 1):
    try:
        today = training_set[i]
        today_data = today_data_all[today].ix[:10, :, :]
        lkbk_days_data = lkbk_days_data_all[today].ix[today_data.items, :, :]

        utils._print(f, '\n\n>>>>>>>>>>> set %d' % (i + 1))
        utils._print(f, 'today = %s' % today)
        utils._print(
            f, 'top10 ' + inputComponentIndexName +
            ' components : %s' % today_data.items)

        close_name = '% Change(close)'
        liq_name = '% Change(liquidity)'

        today_close = today_data.ix[:, close_name, :]
        today_liq = today_data.ix[:, liq_name, :]
        today_close.columns = [(x + '_close') for x in today_close.columns]
        today_liq.columns = [(x + '_liq') for x in today_liq.columns]

        lkbk_close = lkbk_days_data.ix[:, close_name, :]
        lkbk_liq = lkbk_days_data.ix[:, liq_name, :]