@Channelchan
2018-01-06T07:13:55.000000Z
字数 1094
阅读 125404
import rqalphafrom rqalpha.api import *def init(context):context.s1 = '000001.XSHE'def handle_bar(context, bar_dict):cur_position = context.portfolio.positions[context.s1].quantityshares = context.portfolio.cash/bar_dict[context.s1].closeif cur_position==0:order_shares(context.s1, shares)
def init(context):context.s1 = '000001.XSHE'context.s2 = '600036.XSHG'def handle_bar(context, bar_dict):if context.s1 not in context.portfolio.positions:order_target_percent(context.s1, 0.5)if context.s2 not in context.portfolio.positions:order_target_percent(context.s2, 0.5)
连续两天MA下跌卖出一手股指期货,连续两天MA上涨买入平仓。
def init(context):context.future = get_future_contracts("IF")[0]def handle_bar(context, bar_dict):prices = history_bars(context.future, 12, '1d', 'close')ma = talib.EMA(prices, 10)sell_qty = context.portfolio.positions[future].sell_quantityif ma[-1] < ma[-2] and ma[-2] < ma[-3] and sell_qty == 0:sell_open(context.future, 1)if ma[-1] > ma[-2] and ma[-2]>ma[-3] and sell_qty > 0:buy_close(context.future, 1)
