def test_precompute(): ticks = load_ticks('dc', 'pp', 2015, range(9,10), use_cache=True) s = Strategy(ticks, 3.75, show_freq=None) ind = PivotProfile(s, 5*60*2, int(1 * 3.75 * 60 * 60 * 2)) t0 = time.time() ind.precompute() t1 = time.time() print 't_precompute =', t1 - t0, 'sec' s.add_indicator(ind) t0 = time.time() s.run() t1 = time.time() print 't =', t1 - t0, 'sec' s2 = Strategy(ticks, 3.75, show_freq=None) ind2 = PivotProfile(s2, 5*60*2, int(1 * 3.75 * 60 * 60 * 2)) s2.add_indicator(ind2) t0 = time.time() s2.run() t1 = time.time() print 't =', t1 - t0, 'sec' sal = ind.saliency[0][ind.saliency[3]:-ind.saliency[3]] sal2 = ind2.saliency[0][ind2.saliency[3]:-ind2.saliency[3]] print np.abs(sal - sal2).mean(), np.abs(sal - sal2).max(), np.abs(sal).mean()
def test_macd(): ticks = load_ticks('dc', 'pp', 2015, range(9,10), use_cache=True) s = Strategy('pp09_macd', ticks, 3.75) inds = [MACD(s, 1*60*2, 5*60*2, standardized=False, escape_opening=1), MACD(s, 2*60*2, 10*60*2, standardized=False, escape_opening=1), MACD(s, 10*60*2, 60*60*2, standardized=False, escape_opening=0) ] for ind in inds: s.add_indicator(ind) s.run()
def test_output(year=2015, month_range=range(1, 13), name=''): for exchange, commodity, tick_size, hours_per_day in futures: ticks = load_ticks(exchange, commodity, year, month_range) name = base_dir+commodity+str(year%100)+str(month_range[0]).zfill(2)+'-'+str(year%100)+str(month_range[-1]).zfill(2)+'_pivot'+name s = Strategy(name, ticks, tick_size, hours_per_day, save_freq=10)#, show_freq=10) # ind_xs = SRProfile(s, 0.5*60*2, int(30*60*2)) ind_s = PivotProfile(s, 5*60*2, int(1 * hours_per_day * 60 * 60 * 2 * 1.5)) ind_m = PivotProfile(s, 30*60*2, int(5 * hours_per_day * 60 * 60 * 2 * 1.5)) for ind in [ ind_m, ind_s, # ind_xs, ]: ind.precompute() s.add_indicator(ind) s.run() return s
def test_output(year=2016, month_range=range(1, 6), exp_name=''): for exchange, commodity, tick_size, hours_per_day in futures: ticks = load_ticks(exchange, commodity, year, month_range) name = base_dir+commodity+str(year%100)+str(month_range[0]).zfill(2)+'-'+str(year%100)+str(month_range[-1]).zfill(2)+'_common'+exp_name s = Strategy(name, ticks, tick_size, hours_per_day, save_freq=10)#, show_freq=10) inds = [ # MACD(s, 10, 1*60*2, escape_opening=0), # MACD(s, 10, 5*60*2, escape_opening=0), # MACD(s, 1*60*2, 10*60*2, escape_opening=0), # MACD(s, 5*60*2, 30*60*2, escape_opening=0), # MACD(s, 5*60*2, 60*60*2, escape_opening=0), # MACD(s, 5*60*2, 120*60*2, escape_opening=0), # MACD(s, 5*60*2, 240*60*2, escape_opening=0), # MA(s, 5*2), # MA(s, 1*60*2), # MA(s, 5*60*2), # MA(s, 10*60*2), # MA(s, 30*60*2), # MA(s, 60*60*2), # MA(s, 120*60*2), # MA(s, 240*60*2), PastXtrm(s, 5*60*2), PastXtrm(s, 10*60*2), PastXtrm(s, 30*60*2), PastXtrm(s, 60*60*2), PastXtrm(s, 120*60*2), PastXtrm(s, 240*60*2), FutureXtrm(s, 5*60*2), FutureXtrm(s, 10*60*2), FutureXtrm(s, 30*60*2), FutureXtrm(s, 60*60*2), FutureXtrm(s, 120*60*2), FutureXtrm(s, 240*60*2), TimeInfo(s) ] for ind in inds: s.add_indicator(ind) print 'Running', name with Timer() as t: s.run() print 'Run took %f sec.' % t.interval return s