def create_strategy(args): strategy = strategy_builder(args) return strategy
ticks = ES_ticks(datetime(2003, 8, 8)) signals_params = [ ('short_tops', 3, 'HH', 'low', 5, 6), ('long_tops', 2, 'LL', 'high', None, None), ('short_tops', 2, 'HH', 'low', 5, 8), ('long_tops', 4, 'LL', 'HH', None, None), ('short_tops', 10, 'high', 'low', 2, 3), ('long_tops', 2, 'HL', 'high', 4, 2), ('short_tops', 5, 'high', 'HL', 7, 4), ('long_tops', 10, 'HL', 'HH', 3, 8), ('long_tops', 10, 'low', 'high', 6, 3), ('long_tops', 4, 'low', 'high', 6, 8) ] strategy = strategy_builder(signals_params) def run_prof(): t1 = time.time() for tick in ticks: t.ticks.append(tick) for signal in strategy: processed_signal = signal.check_entry(t) t2 = time.time() print "run_prof() took %s seconds to complete" % str(t2 - t1) return t if __name__ == '__main__': t = run_prof()
start = datetime(2004, 1, 1) end = datetime(2007, 1, 1) ticks = None print "picking random weekday..." while not ticks: weekday = random_weekday(start, end) print "random weekday: %s" % str(weekday) ticks = ES_ticks(weekday) if not ticks: print "no ticks found for: %s, trying again..." % str(weekday) print "tick data loaded..." tt0 = time.time() for id, map in strategy_map.items(): t = Ticker(increment=0.25, commission=0.1) strategy = strategy_builder(map['params']) t0 = time.time() simulation = SimulationRunner(t, ticks, strategy) orders = simulation.run() t1 = time.time() map['orders'] = orders map['simulation_time'] = t1 - t0 print "tested strategy: %s" % id tt1 = time.time() print "running %s simulations took %s seconds" % (nr_of_strategies, repr(tt1 - tt0)) reduced_map = {} for id, map in strategy_map.items(): orders = map['orders'] deltas = [details['delta'] for details in orders.values()