如何在生成卖单的时候,设置持有的最大天数,比如超过5天的股票,无论盈利结果如何都卖出!?


(jh_ufo) #1
# 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰
if not is_staging and cash_for_sell > 0:
    equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}
    instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(
            lambda x: x in equities and not context.has_unfinished_sell_order(equities[x]))])))
    #  print('rank order for sell %s ' % instruments)
    for instrument in instruments:
        context.order_target(context.symbol(instrument), 0)
        cash_for_sell -= positions[instrument]
        if cash_for_sell <= 0:
            break

(达达) #2

看一下这篇学院教程