def handle_data_grid_search(context): for symbol in ['B', 'A']: try: MA1 = mean( get_history(context, symbol, field='ask', period=context.params.current[0])) MA2 = mean( get_history(context, symbol, field='ask', period=context.params.current[1])) if MA1 < MA2: order(context, symbol, 1) elif MA1 > MA2: order(context, symbol, -1) except: pass
def handle_data(context): context.count += 1 if not context.count % 10: order(context, '1', 1)
def handle_data_opt(context): if context.params.random_thresh == context.params.random_nr: order(context, 'AAPL', 1) if context.params.random_thresh == context.params.random_nr: order(context, 'MSFT', -1)
def handle_data_web(context): order(context, 'F', random.randint(-2, 2)) order(context, 'CSCO', random.randint(-2, 2))
def handle_data_step(context): context.cnt += 1 if context.cnt == 2: order(context, 'step_function', 1, field='one') elif context.cnt == 180: order(context, 'step_function', -1)
def handle_data_switchover(context): if random.randint(0, 10) == 2: order(context, 'NASDAQ:MSFT', 1)
def handle_data_stream(context): if random.randint(0, 1000) == 23: order(context, 'A', random.randint(-1, 2)) if random.randint(0, 1000) == 23: order(context, 'B', random.randint(-1, 2)) MA = mean(get_history(context, 'B', field='ask', period=3))