def initialize(context): # 设定股票 g.stock = '159605.XSHE' # 设置开始买入价格 g.price = 0.796 # 设定纳指ETF作为基准 set_benchmark('159605.XSHE') # True为开启动态复权模式,使用真实价格交易 #set_option('use_real_price', True) # 股票类交易手续费是:买入时佣金万分之三,卖出时佣金万分之三加千分之一印花税, 每笔交易佣金最低扣5块钱 set_order_cost(OrderCost(open_tax=0, close_tax=0.001, \ open_commission=0.00005, close_commission=0.00005,\ close_today_commission=0, min_commission=0.1), type='stock') # 每日交易 run_daily(trade2, time='every_bar') #网格交易1 def trade2(context): stock = g.stock close_data = attribute_history(stock, 5, '1d', ['close']) current_price = close_data['close'][-1] cha = current_price - g.price if cha < -0.005: g.price = g.price - 0.003 order(g.stock, 10000) elif cha > 0.005: g.price = g.price + 0.01 order(g.stock, -10000)
您需要登录后才能查看源码,点击登录