问答交流

资金管理问题

由lianghua2020创建,最终由lianghua2020 被浏览 48 用户

cash_avg = context.portfolio.portfolio_value / context.options['hold_days']
cash_for_buy = min(context.portfolio.cash, (1 if is_staging else 1.5) * cash_avg)
cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)
请问这个怎么理解?
# 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰
    if not is_staging and cash_for_sell > 0:
        equities = {e.symbol: e for e, p in context.portfolio.positions.items()}
        instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(
                lambda x: x in equities)])))

        for instrument in instruments:
            context.order_target(context.symbol(instrument), 0)
            cash_for_sell -= positions[instrument]
            if cash_for_sell <= 0:
                break
生成卖出订单时,cash_for_sell条件是怎样控制卖出订单的?

\

标签

交易策略
评论
  • 你好,cash_for_sell这个变量在这里指的是要卖出的资金量,也就是我还要出售多少资金量的该支股票,因此,只有资金量为正数时,才执行卖出指令。更加具体的关于AI模板策略交易逻辑的解读,请参考这篇[文档](https://bigquant.com/wiki/doc/moban-celve-luoji-Q1ktCRf5d7)
{link}