BigQuant A股股票选股模板策略介绍

新手专区
精选
标签: #<Tag:0x00007f0dd721acc8> #<Tag:0x00007f0dd721ab88>

(小Q) #1

在平台策略编写文件导航器中,有近20个模板策略,可供大家借鉴学习,本文进行简要介绍。

编写策略界面下,我们可以找到模板策略文件夹,存放了一些常用的策略/功能实现模板。

进入模板策略文件夹,可以看到股票期货两个文件夹,分别存放了股票策略模板和期货策略模板。

以股票文件夹为例,进入文件夹后可以看到如下策略。

我们对部分策略/功能进行初步介绍:

AI选股策略 ——综合过滤

在实盘操作中,往往有很多其他因素。综合过滤模板展示了如何过滤掉ST股票、 选取指定概念板块股、过滤退市股等操作。

多头排列回踩均线选股策略

  • 买入条件:满足条件 1)5日均线大于10日均线,10日均线大于20日均线,20日均线大于40日均线,40日均线大于120日均线;2)今日最低价小于10日收盘价均线 的股票,次日以开盘价买入;
  • 买入后,如果5日均线小于40日均线,则次日以开盘价卖出。
  • 允许最多同时持有20只股票

固定止盈止损功能

  • 本例中,止盈条件为固定点位止盈:赚3元就卖出,并使用 stopwin_stock 用来记录止盈的股票列表;
  • 止损条件为固定百分比止损:亏10%就卖出,并使用 stoploss_stock 用来记录止损的股票列表。

等资金权重配置

查看回测/模拟模块属性栏中的“初始化函数”框体内的代码,将其中的:

每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[0.339160, 0.213986, 0.169580, …]

context.stock_weights = T.norm([1 / math.log(i + 2) for i in range(0, stock_count)])

改为等权重配置:

context.stock_weights = [1 / stock_count for i in range(0, stock_count)]

移动止损功能

在开发策略时,经常使用个股的固定点位/百分比止盈止损功能。

本策略以买入后最高价下跌10%止损为例,介绍移动止损功能的实现步骤

海龟策略

  • 当今天的收盘价大于过去20个交易日中的最高价时,以收盘价买入;
  • 买入后,当收盘价小于过去10个交易日中的最低价时,以收盘价卖出;

多条件选股策略

  • 买入条件:满足 1)今日开盘价大于昨日收盘价;2)5日收盘价均线大于10日收盘价均线的股票按PE升序排名取前十名,次日以开盘价买入;
  • 买入后,如果5日收盘价均线小于10日收盘价均线,则次日以开盘价卖出。

股票事件驱动策略

  • 由于财务公告通常在晚上发布,在财务报表公告的第二日开盘买入归属母公司股东的净利润同比增长率百分比大于30%的且降序排名靠前股票(总持仓量不超过50只);
  • 买入并持有40个交易日后,以第二日开盘价卖出;

双均线策略

  • 当收盘价5日均线大于10日均线时,以第二日开盘价买入;
  • 买入后,当收盘价的5日均线小于10日均线时,以第二日开盘价卖出;

大盘风控功能

  • 在开发策略时,经常需要根据大盘指数计算相关技术指标来进行仓位风险控制。

  • 本策略以上证指数5日累计涨幅作为风险控制指标,如果5日累计涨幅小于-4%,则执行清仓止损。

AI选股策略 ——指定验证集概念板块

  • 在预测集流程中的缺失数据处理模块m14前加入模块“选取指定概念板块股”m27(从“用户模块”——“共享模块”中找到并拖入画布)
  • 连接模块m18和模块m27即可实现指定验证集股票范围为指定的概念板块。

GBDT多因子选股策略

本例使用GBDT算法进行模型训练和数据预测

  • 新建可视化AI模板策略

  • 在左侧模块导航栏“机器学习”中拖出“GBDT训练”和“GBDT预测”模块替换原有的 StockRanker 训练模块和 StockRanker 预测模块

使用深度学习技术预测股票价格

  • 买入条件:预测的上涨概率>0.5,则买入或保持已有持仓。
  • 卖出条件 :预测的上涨概率<0.5,则卖出已有股票。

TALIB指标选股策略

  • 买入条件:满足 1)今日开盘价大于昨日收盘价;2)5日收盘价均线大于10日收盘价均线的股票按PE升序排名取前十名,次日以开盘价买入;
  • 买入后,如果5日收盘价均线小于10日收盘价均线,则次日以开盘价卖出。

配对交易策略

  • 对于股价有长期协整关系的两只股票X和Y, 可以通过历史数据回归计算两只股票的股价关系,即 Y = a*X + b, 得到相关系数a和残差项b;
  • 如果两个股票所属同一行业,我们可以认为两者的股价未来应该保持上述关系,即序列 zscore=(b-mean(b,N))/std(b,N) 存在比较稳定的均值回归特性,保持在-1和1之间往复震荡;
  • 当zscore小于-1时,Y股票低估,此时卖出X, 全仓买入Y;
  • 当zscore大于 1时,X股票低估,此时卖出Y, 全仓买入X;

价值选股策略

  • 每隔30个交易日,以开盘价买入当日0<PB<1.5且0<PE<15且有成交量的股票;
  • 每隔30个交易日,将不符合上述标准的持仓股票在第二天以收盘价卖出。

期货日线MACD策略

  • 相关指标定义如下:
    DIF=EMA(close,12)−EMA(close,26)
    DEM=EMA(DIF,9)

  • DIF从下而上穿过DEA,买入开仓;

  • DIF从上往下穿过DEA,卖出开仓;

期货AR分钟策略

  • 当收盘价 ≥ 最近60日收盘价最高值时,平空开多;
  • 当收盘价 ≤ 最近60日收盘价最低值时,平多开空;

期货日线布林带策略

  • 相关定义如下:
    中轨 = N时间段的close价格简单移动平均线
    上轨 = 中轨 + K × N时间段的标准差
    下轨 = 中轨 − K × N时间段的标准差
    当前价格相对位置 percent_b = (close - lower)/(upper - lower)
    本例中N取20,K取2

  • 当percent_b ≥ 1时,以第二日开盘价平空开多;

  • 当percent_b ≤ 0时,以第二日开盘价平多卖空;

使用深度学习技术预测股票价格

  • 买入条件:预测的上涨概率>0.5,则买入或保持已有持仓。
  • 卖出条件 :预测的上涨概率<0.5,则卖出已有股票。

使用深度学习DNN构建选股模型


该模型来自社区帖子“ 使用深度学习DNN构建选股模型

大家可以很方便地通过打开这些策略克隆进行学习或个性化修改。

结语:本文介绍了BigQuant常用模板策略的使用,希望能够帮助大家快速上手策略开发,同时也希望大家在社区踊跃贡献自己的策略,很可能会作为模板示例分享给大家~


请老师们,帮帮忙,还有大神帮我看看,我这边加入了模板的移动止盈止损之后回测就报错了 好久了都没办法改
(iQuant) #2

鉴于很多用户询问止赢止损、大盘风控和ST股退市股卖出过滤的混合问题,这里进行一个模版说明。

首先,所有的测试集数据在预测之前过滤,可能会导致持仓后的股票丢失排序而无法卖出或排序混乱。
因此我们尽量使用数据合并功能,把股票名称、大盘风控等指标合并到预测结果中,保证输入给回测模块的股票数据的完整性。
我们尽量在回测模块外通过数据源等模块进行数据抽取。这里介绍常用的几种数据读取,包括:

  • 从 instruments_CN_STOCK_A表中抽取股票名称列name;
  • 从 指数特征抽取模块中抽取指数的相关风控条件因子(例如过去五日涨幅<-0.05就判定为有风险,否则为无风险)
  • 从预测分支抽取所需的其他数据比如涨跌停状态price_limit_status_0等。这里使用了一个技巧即:用来后续过滤使用的因子/指标单独放在一个证券代码列表模块中而不作为模型因子参与模型的训练。注意连接个算法模块的仅是第一个输入特征列表的输出结果!

通过数据合并后,我们的预测数据在原来的date\instrument\score\position列的基础上,增加了每日所需的大盘风控条件bm_0列、股票名称name列和涨跌停状态price_limit_status_0,以便于我们后续在回测模块中条件判断和使用。最后利用排序模块
按照每天的股票预测得分或排名进行重新排序。这里要特别注意预测结果的每日顺序是否正确!

随后我们通过初始化函数读入的数据中就包含了所需要的数据列,我们直接在主函数中引用这些列名就可以实现每日的数据获取了。

    today = data.current_dt.strftime('%Y-%m-%d')
    # 按日期过滤得到今日的预测数据
    ranker_prediction = context.ranker_prediction[
        context.ranker_prediction.date == today]

然后我们利用每日的数据ranker_prediction的各列进行条件判断:

1.大盘风控代码
    #大盘风控模块,读取风控数据    
    benckmark_risk=ranker_prediction['bm_0'].values[0]

    #当risk为1时,市场有风险,全部平仓,不再执行其它操作
    if benckmark_risk > 0:
        for instrument in positions.keys():
            context.order_target(context.symbol(instrument), 0)
        print(today,'大盘风控止损触发,全仓卖出')
        return
2.资金分配并定义卖出列表
    # 1. 资金分配
    # 平均持仓时间是hold_days,每日都将买入股票,每日预期使用 1/hold_days 的资金
    # 实际操作中,会存在一定的买入误差,所以在前hold_days天,等量使用资金;之后,尽量使用剩余资金(这里设置最多用等量的1.5倍)
    is_staging = context.trading_day_index < context.options['hold_days'] # 是否在建仓期间(前 hold_days 天)
    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)
    stock_sold = [] # 记录卖出的股票,防止多次卖出出现空单
3. 根据需要加入止赢止损模块
    #------------------------START:止赢止损模块(含建仓期)---------------
    current_stopwin_stock=[]
    current_stoploss_stock = []   
    positions_cost={e.symbol:p.cost_basis for e,p in context.portfolio.positions.items()}
    if len(positions)>0:
        for instrument in positions.keys():
            stock_cost=positions_cost[instrument]  
            stock_market_price=data.current(context.symbol(instrument),'price')  
            # 赚9%且为可交易状态就止盈
            if stock_market_price/stock_cost-1>=0.09 and data.can_trade(context.symbol(instrument)):
                context.order_target_percent(context.symbol(instrument),0)
                cash_for_sell -= positions[instrument]
                current_stopwin_stock.append(instrument)
            # 亏5%并且为可交易状态就止损
            if stock_market_price/stock_cost-1 <= -0.05 and data.can_trade(context.symbol(instrument)):   
                context.order_target_percent(context.symbol(instrument),0)
                cash_for_sell -= positions[instrument]
                current_stoploss_stock.append(instrument)
        if len(current_stopwin_stock)>0:
            print(today,'止盈股票列表',current_stopwin_stock)
            stock_sold += current_stopwin_stock # 注意此处卖出的股票要记录到列表中
        if len(current_stoploss_stock)>0:
            print(today,'止损股票列表',current_stoploss_stock)
            stock_sold += current_stoploss_stock   # 注意此处卖出的股票要记录到列表中
    #--------------------------END: 止赢止损模块--------------------------
4. 根据需要增加固定天数卖出逻辑
    #--------------------------START:持有固定天数卖出(不含建仓期)-----------
    current_stopdays_stock = []
    positions_lastdate = {e.symbol:p.last_sale_date for e,p in context.portfolio.positions.items()}
    # 不是建仓期(在前hold_days属于建仓期)
    if not is_staging:
        for instrument in positions.keys():
            #如果上面的止盈止损已经卖出过了,就不要重复卖出以防止产生空单
            if instrument in stock_sold:
                continue
            # 今天和上次交易的时间相隔hold_days就全部卖出 datetime.timedelta(context.options['hold_days'])也可以换成自己需要的天数,比如datetime.timedelta(5)
            if data.current_dt - positions_lastdate[instrument]>=datetime.timedelta(5) and data.can_trade(context.symbol(instrument)):
                context.order_target_percent(context.symbol(instrument), 0)
                current_stopdays_stock.append(instrument)
                cash_for_sell -= positions[instrument]
        if len(current_stopdays_stock)>0:        
            print(today,'固定天数卖出列表',current_stopdays_stock)
            stock_sold += current_stopdays_stock  # 注意此处卖出的股票要记录到列表中
    #-------------------------  END:持有固定天数卖出-----------------------
5. 根据需要增加持仓ST股和退市股卖出逻辑
    #-------------------------- START: ST和退市股卖出 ---------------------  
    st_stock_list = []
    for instrument in positions.keys():
        try:
            instrument_name = ranker_prediction[ranker_prediction.instrument==instrument].name.values[0]
            # 如果股票状态变为了st或者退市 则卖出
            if 'ST' in instrument_name or '退' in instrument_name:
                if instrument in stock_sold:
                    continue
                if data.can_trade(context.symbol(instrument)):
                    context.order_target(context.symbol(instrument), 0)
                    st_stock_list.append(instrument)
                    cash_for_sell -= positions[instrument]
        except:
            continue
    if st_stock_list!=[]:
        print(today,'持仓出现st股/退市股',st_stock_list,'进行卖出处理')    
        stock_sold += st_stock_list  # 注意此处卖出的股票要记录到列表中
    #-------------------------- END: ST和退市股卖出 --------------------- 
6. 轮仓卖出逻辑
    # 3. 生成轮仓卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰
    if not is_staging and cash_for_sell > 0:
        instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(
                lambda x: x in positions)])))
        for instrument in instruments:
            # 如果资金够了就不卖出了
            if cash_for_sell <= 0:
                break
            #防止多个止损条件同时满足,出现多次卖出产生空单
            if instrument in stock_sold:
                continue
            context.order_target(context.symbol(instrument), 0)
            cash_for_sell -= positions[instrument]
            stock_sold.append(instrument)  # 轮仓卖出的股票可以选择添加到卖出列表中
7.轮仓买入逻辑
    # 4. 生成轮仓买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票
    # 计算今日跌停的股票
    dt_list = list(ranker_prediction[ranker_prediction.price_limit_status_0==1].instrument)
    # 计算今日ST/退市的股票
    st_list = list(ranker_prediction[ranker_prediction.name.str.contains('ST')|ranker_prediction.name.str.contains('退')].instrument)
    # 计算所有禁止买入的股票池banned_list,包括已卖出的股票和跌停的股票以及ST/退市股票
    banned_list = stock_sold+dt_list+st_list
    buy_cash_weights = context.stock_weights
    buy_instruments=[k for k in list(ranker_prediction.instrument) if k not in banned_list][:len(buy_cash_weights)]
    max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument
    for i, instrument in enumerate(buy_instruments):
        cash = cash_for_buy * buy_cash_weights[i]
        if cash > max_cash_per_instrument - positions.get(instrument, 0):
            # 确保股票持仓量不会超过每次股票最大的占用资金量
            cash = max_cash_per_instrument - positions.get(instrument, 0)
        if cash > 0:
            context.order_value(context.symbol(instrument), cash)

最后附上该策略:

克隆策略

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-404:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data1","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:data"},{"DestinationInputPortId":"-404:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-411:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-8068:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-318:features_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"-329:data1","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:predictions"},{"DestinationInputPortId":"-418:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-1918:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-218:input_1","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-224:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-8068:training_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:data","SourceOutputPortId":"-86:data"},{"DestinationInputPortId":"-323:input_ds","SourceOutputPortId":"-86:data"},{"DestinationInputPortId":"-411:input_data","SourceOutputPortId":"-404:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"-411:data"},{"DestinationInputPortId":"-425:input_data","SourceOutputPortId":"-418:data"},{"DestinationInputPortId":"-86:input_data","SourceOutputPortId":"-425:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:model","SourceOutputPortId":"-8068:model"},{"DestinationInputPortId":"-224:features","SourceOutputPortId":"-148:data"},{"DestinationInputPortId":"-218:input_2","SourceOutputPortId":"-184:data"},{"DestinationInputPortId":"-202:data2","SourceOutputPortId":"-189:data"},{"DestinationInputPortId":"-189:data2","SourceOutputPortId":"-196:data"},{"DestinationInputPortId":"-490:input_ds","SourceOutputPortId":"-202:data"},{"DestinationInputPortId":"-196:input_ds","SourceOutputPortId":"-218:data_1"},{"DestinationInputPortId":"-189:data1","SourceOutputPortId":"-224:data"},{"DestinationInputPortId":"-418:features","SourceOutputPortId":"-318:data"},{"DestinationInputPortId":"-425:features","SourceOutputPortId":"-318:data"},{"DestinationInputPortId":"-329:data2","SourceOutputPortId":"-323:data"},{"DestinationInputPortId":"-202:data1","SourceOutputPortId":"-329:data"},{"DestinationInputPortId":"-1918:options_data","SourceOutputPortId":"-490:sorted_data"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2010-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-15","ModuleId":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","ModuleParameters":[{"Name":"label_expr","Value":"# #号开始的表示注释\n# 0. 每行一个,顺序执行,从第二个开始,可以使用label字段\n# 1. 可用数据字段见 https://bigquant.com/docs/data_history_data.html\n# 添加benchmark_前缀,可使用对应的benchmark数据\n# 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/big_expr.html>`_\n\n# 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\nshift(close, -5) / shift(open, -1)\n\n# 极值处理:用1%和99%分位的值做clip\nclip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 将分数映射到分类,这里使用20个分类\nall_wbins(label, 20)\n\n# 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)\nwhere(shift(high, -1) == shift(low, -1), NaN, label)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"000300.SHA","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na_label","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"cast_label_int","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nreturn_5\nreturn_10\nreturn_20\navg_amount_0/avg_amount_5\navg_amount_5/avg_amount_20\nrank_avg_amount_0/rank_avg_amount_5\nrank_avg_amount_5/rank_avg_amount_10\nrank_return_0\nrank_return_5\nrank_return_10\nrank_return_0/rank_return_5\nrank_return_5/rank_return_10\npe_ttm_0\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-53","ModuleId":"BigQuantSpace.join.join-v3","ModuleParameters":[{"Name":"on","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"how","Value":"inner","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sort","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data1","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","ModuleId":"BigQuantSpace.stock_ranker_predict.stock_ranker_predict-v5","ModuleParameters":[{"Name":"m_lazy_run","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"model","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60"}],"OutputPortsInternal":[{"Name":"predictions","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","OutputType":null},{"Name":"m_lazy_run","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2017-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"Comment":"预测数据,用于回测和模拟","CommentCollapsed":false},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"Comment":"","CommentCollapsed":true},{"Id":"-86","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-86"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-86","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":14,"Comment":"","CommentCollapsed":true},{"Id":"-404","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-404"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-404"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-404","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"Comment":"","CommentCollapsed":true},{"Id":"-411","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-411"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-411"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-411","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"Comment":"","CommentCollapsed":true},{"Id":"-418","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-418"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-418"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-418","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"Comment":"","CommentCollapsed":true},{"Id":"-425","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-425"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-425"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-425","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"Comment":"","CommentCollapsed":true},{"Id":"-1918","ModuleId":"BigQuantSpace.trade.trade-v4","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"initialize","Value":"# 回测引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n # 加载预测数据\n context.ranker_prediction = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)\n # 设置买入的股票数量,这里买入预测股票列表排名靠前的5只\n stock_count = 3\n # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[0.339160, 0.213986, 0.169580, ..]\n context.stock_weights = T.norm([1 / math.log(i + 2) for i in range(0, stock_count)])\n # 设置每只股票占用的最大资金比例\n context.max_cash_per_instrument = 0.6\n context.options['hold_days'] = 5\n\n from zipline.finance.slippage import SlippageModel\n class FixedPriceSlippage(SlippageModel):\n def process_order(self, data, order, bar_volume=0, trigger_check_price=0):\n if order.limit is None:\n price_field = self._price_field_buy if order.amount > 0 else self._price_field_sell\n price = data.current(order.asset, price_field)\n else:\n price = data.current(order.asset, self._price_field_buy)\n # 返回希望成交的价格和数量\n return (price, order.amount)\n # 设置price_field,默认是开盘买入,收盘卖出\n context.fix_slippage = FixedPriceSlippage(price_field_buy='open', price_field_sell='close')\n context.set_slippage(us_equities=context.fix_slippage)","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n # 获取当前持仓\n positions = {e.symbol: p.amount * p.last_sale_price\n for e, p in context.portfolio.positions.items()}\n \n today = data.current_dt.strftime('%Y-%m-%d')\n # 按日期过滤得到今日的预测数据\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == today]\n \n #大盘风控模块,读取风控数据 \n benckmark_risk=ranker_prediction['bm_0'].values[0]\n\n #当risk为1时,市场有风险,全部平仓,不再执行其它操作\n if benckmark_risk > 0:\n for instrument in positions.keys():\n context.order_target(context.symbol(instrument), 0)\n print(today,'大盘风控止损触发,全仓卖出')\n return\n \n # 1. 资金分配\n # 平均持仓时间是hold_days,每日都将买入股票,每日预期使用 1/hold_days 的资金\n # 实际操作中,会存在一定的买入误差,所以在前hold_days天,等量使用资金;之后,尽量使用剩余资金(这里设置最多用等量的1.5倍)\n is_staging = context.trading_day_index < context.options['hold_days'] # 是否在建仓期间(前 hold_days 天)\n cash_avg = context.portfolio.portfolio_value / context.options['hold_days']\n cash_for_buy = min(context.portfolio.cash, (1 if is_staging else 1.5) * cash_avg)\n cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)\n \n \n # 2. 根据需要加入移动止赢止损模块、固定天数卖出模块、ST或退市股卖出模块\n stock_sold = [] # 记录卖出的股票,防止多次卖出出现空单\n \n #------------------------START:止赢止损模块(含建仓期)---------------\n current_stopwin_stock=[]\n current_stoploss_stock = [] \n positions_cost={e.symbol:p.cost_basis for e,p in context.portfolio.positions.items()}\n if len(positions)>0:\n for instrument in positions.keys():\n stock_cost=positions_cost[instrument] \n stock_market_price=data.current(context.symbol(instrument),'price') \n # 赚9%且为可交易状态就止盈\n if stock_market_price/stock_cost-1>=0.09 and data.can_trade(context.symbol(instrument)):\n context.order_target_percent(context.symbol(instrument),0)\n cash_for_sell -= positions[instrument]\n current_stopwin_stock.append(instrument)\n # 亏5%并且为可交易状态就止损\n if stock_market_price/stock_cost-1 <= -0.05 and data.can_trade(context.symbol(instrument)): \n context.order_target_percent(context.symbol(instrument),0)\n cash_for_sell -= positions[instrument]\n current_stoploss_stock.append(instrument)\n if len(current_stopwin_stock)>0:\n print(today,'止盈股票列表',current_stopwin_stock)\n stock_sold += current_stopwin_stock\n if len(current_stoploss_stock)>0:\n print(today,'止损股票列表',current_stoploss_stock)\n stock_sold += current_stoploss_stock\n #--------------------------END: 止赢止损模块--------------------------\n \n #--------------------------START:持有固定天数卖出(不含建仓期)-----------\n current_stopdays_stock = []\n positions_lastdate = {e.symbol:p.last_sale_date for e,p in context.portfolio.positions.items()}\n # 不是建仓期(在前hold_days属于建仓期)\n if not is_staging:\n for instrument in positions.keys():\n #如果上面的止盈止损已经卖出过了,就不要重复卖出以防止产生空单\n if instrument in stock_sold:\n continue\n # 今天和上次交易的时间相隔hold_days就全部卖出 datetime.timedelta(context.options['hold_days'])也可以换成自己需要的天数,比如datetime.timedelta(5)\n if data.current_dt - positions_lastdate[instrument]>=datetime.timedelta(5) and data.can_trade(context.symbol(instrument)):\n context.order_target_percent(context.symbol(instrument), 0)\n current_stopdays_stock.append(instrument)\n cash_for_sell -= positions[instrument]\n if len(current_stopdays_stock)>0: \n print(today,'固定天数卖出列表',current_stopdays_stock)\n stock_sold += current_stopdays_stock\n #------------------------- END:持有固定天数卖出-----------------------\n \n #-------------------------- START: ST和退市股卖出 --------------------- \n st_stock_list = []\n for instrument in positions.keys():\n try:\n instrument_name = ranker_prediction[ranker_prediction.instrument==instrument].name.values[0]\n # 如果股票状态变为了st或者退市 则卖出\n if 'ST' in instrument_name or '退' in instrument_name:\n if instrument in stock_sold:\n continue\n if data.can_trade(context.symbol(instrument)):\n context.order_target(context.symbol(instrument), 0)\n st_stock_list.append(instrument)\n cash_for_sell -= positions[instrument]\n except:\n continue\n if st_stock_list!=[]:\n print(today,'持仓出现st股/退市股',st_stock_list,'进行卖出处理') \n stock_sold += st_stock_list\n\n #-------------------------- END: ST和退市股卖出 --------------------- \n \n \n # 3. 生成轮仓卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰\n if not is_staging and cash_for_sell > 0:\n instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(\n lambda x: x in positions)])))\n for instrument in instruments:\n # 如果资金够了就不卖出了\n if cash_for_sell <= 0:\n break\n #防止多个止损条件同时满足,出现多次卖出产生空单\n if instrument in stock_sold:\n continue\n context.order_target(context.symbol(instrument), 0)\n cash_for_sell -= positions[instrument]\n stock_sold.append(instrument)\n\n # 4. 生成轮仓买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票\n # 计算今日跌停的股票\n dt_list = list(ranker_prediction[ranker_prediction.price_limit_status_0==1].instrument)\n # 计算今日ST/退市的股票\n st_list = list(ranker_prediction[ranker_prediction.name.str.contains('ST')|ranker_prediction.name.str.contains('退')].instrument)\n # 计算所有禁止买入的股票池\n banned_list = stock_sold+dt_list+st_list\n buy_cash_weights = context.stock_weights\n buy_instruments=[k for k in list(ranker_prediction.instrument) if k not in banned_list][:len(buy_cash_weights)]\n max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument\n for i, instrument in enumerate(buy_instruments):\n cash = cash_for_buy * buy_cash_weights[i]\n if cash > max_cash_per_instrument - positions.get(instrument, 0):\n # 确保股票持仓量不会超过每次股票最大的占用资金量\n cash = max_cash_per_instrument - positions.get(instrument, 0)\n if cash > 0:\n context.order_value(context.symbol(instrument), cash)\n \n\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"def bigquant_run(context, data):\n # 获取涨跌停状态数据\n df_price_limit_status = context.ranker_prediction.set_index('date')\n today=data.current_dt.strftime('%Y-%m-%d')\n # 得到当前未完成订单\n for orders in get_open_orders().values():\n # 循环,撤销订单\n for _order in orders:\n ins=str(_order.sid.symbol)\n try:\n #判断一下如果当日涨停,则取消卖单\n if df_price_limit_status[df_price_limit_status.instrument==ins].price_limit_status_0.ix[today]>2 and _order.amount<0:\n cancel_order(_order)\n print(today,'尾盘涨停取消卖单',ins) \n except:\n continue","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"volume_limit","Value":0.025,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_buy","Value":"open","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_sell","Value":"close","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"capital_base","Value":"1000001","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"daily","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"price_type","Value":"后复权","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"product_type","Value":"股票","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-1918"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-1918"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-1918"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-1918"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-1918"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-1918","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-8068","ModuleId":"BigQuantSpace.stock_ranker_train.stock_ranker_train-v6","ModuleParameters":[{"Name":"learning_algorithm","Value":"排序","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_leaves","Value":30,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"minimum_docs_per_leaf","Value":1000,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_trees","Value":20,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"learning_rate","Value":0.1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_bins","Value":1023,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_row_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"ndcg_discount_base","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"m_lazy_run","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-8068"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-8068"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"test_ds","NodeId":"-8068"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"base_model","NodeId":"-8068"}],"OutputPortsInternal":[{"Name":"model","NodeId":"-8068","OutputType":null},{"Name":"feature_gains","NodeId":"-8068","OutputType":null},{"Name":"m_lazy_run","NodeId":"-8068","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-148","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nname","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-148"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-148","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":20,"Comment":"","CommentCollapsed":true},{"Id":"-184","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nbm_0 = where(close/shift(close,5)-1<-0.05,1,0)","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-184"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-184","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":24,"Comment":"","CommentCollapsed":true},{"Id":"-189","ModuleId":"BigQuantSpace.join.join-v3","ModuleParameters":[{"Name":"on","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"how","Value":"left","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sort","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data1","NodeId":"-189"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-189"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-189","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":25,"Comment":"","CommentCollapsed":true},{"Id":"-196","ModuleId":"BigQuantSpace.select_columns.select_columns-v3","ModuleParameters":[{"Name":"columns","Value":"date,bm_0","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"reverse_select","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_ds","NodeId":"-196"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"columns_ds","NodeId":"-196"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-196","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":26,"Comment":"","CommentCollapsed":true},{"Id":"-202","ModuleId":"BigQuantSpace.join.join-v3","ModuleParameters":[{"Name":"on","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"how","Value":"left","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sort","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data1","NodeId":"-202"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-202"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-202","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":27,"Comment":"","CommentCollapsed":true},{"Id":"-218","ModuleId":"BigQuantSpace.index_feature_extract.index_feature_extract-v2","ModuleParameters":[{"Name":"before_days","Value":100,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"index","Value":"000300.HIX","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-218"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-218"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-218","OutputType":null},{"Name":"data_2","NodeId":"-218","OutputType":null},{"Name":"data_3","NodeId":"-218","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":29,"Comment":"","CommentCollapsed":true},{"Id":"-224","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"instruments_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-224"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-224"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-224","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":22,"Comment":"","CommentCollapsed":true},{"Id":"-318","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nprice_limit_status_0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-318"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-318","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"Comment":"","CommentCollapsed":true},{"Id":"-323","ModuleId":"BigQuantSpace.select_columns.select_columns-v3","ModuleParameters":[{"Name":"columns","Value":"date,instrument,price_limit_status_0","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"reverse_select","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_ds","NodeId":"-323"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"columns_ds","NodeId":"-323"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-323","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"Comment":"","CommentCollapsed":true},{"Id":"-329","ModuleId":"BigQuantSpace.join.join-v3","ModuleParameters":[{"Name":"on","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"how","Value":"inner","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sort","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data1","NodeId":"-329"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-329"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-329","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"Comment":"","CommentCollapsed":true},{"Id":"-490","ModuleId":"BigQuantSpace.sort.sort-v4","ModuleParameters":[{"Name":"sort_by","Value":"position","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"group_by","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"keep_columns","Value":"--","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"ascending","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_ds","NodeId":"-490"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"sort_by_ds","NodeId":"-490"}],"OutputPortsInternal":[{"Name":"sorted_data","NodeId":"-490","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":12,"Comment":"","CommentCollapsed":true}],"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-8' Position='248,98,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='79,197,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='699,-9,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='268,365,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-60' Position='782,629,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='997,123,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='376,449,200,200'/><NodePosition Node='-86' Position='1011,485,200,200'/><NodePosition Node='-404' Position='381,188,200,200'/><NodePosition Node='-411' Position='385,280,200,200'/><NodePosition Node='-418' Position='1002,254,200,200'/><NodePosition Node='-425' Position='1008,376,200,200'/><NodePosition Node='-1918' Position='1266.814453125,954.5596923828125,200,200'/><NodePosition Node='-8068' Position='591,536,200,200'/><NodePosition Node='-148' Position='1399.639892578125,464.9910888671875,200,200'/><NodePosition Node='-184' Position='1708.272705078125,360.0231628417969,200,200'/><NodePosition Node='-189' Position='1506.639892578125,682.874755859375,200,200'/><NodePosition Node='-196' Position='1690.5235595703125,564.9910888671875,200,200'/><NodePosition Node='-202' Position='1240,798,200,200'/><NodePosition Node='-218' Position='1709.639892578125,464.9910888671875,200,200'/><NodePosition Node='-224' Position='1396.639892578125,562.9910888671875,200,200'/><NodePosition Node='-318' Position='678,107,200,200'/><NodePosition Node='-323' Position='1079.6038818359375,598.1163330078125,200,200'/><NodePosition Node='-329' Position='1083.440185546875,704.3490600585938,200,200'/><NodePosition Node='-490' Position='1311.400390625,876.4510803222656,200,200'/></NodePositions><NodeGroups /></DataV1>"},"IsDraft":true,"ParentExperimentId":null,"WebService":{"IsWebServiceExperiment":false,"Inputs":[],"Outputs":[],"Parameters":[{"Name":"交易日期","Value":"","ParameterDefinition":{"Name":"交易日期","FriendlyName":"交易日期","DefaultValue":"","ParameterType":"String","HasDefaultValue":true,"IsOptional":true,"ParameterRules":[],"HasRules":false,"MarkupType":0,"CredentialDescriptor":null}}],"WebServiceGroupId":null,"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions></NodePositions><NodeGroups /></DataV1>"},"DisableNodesUpdate":false,"Category":"user","Tags":[],"IsPartialRun":true}
    In [24]:
    # 本代码由可视化策略环境自动生成 2020年3月10日 16:56
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 回测引擎:初始化函数,只执行一次
    def m4_initialize_bigquant_run(context):
        # 加载预测数据
        context.ranker_prediction = context.options['data'].read_df()
    
        # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
        context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
        # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)
        # 设置买入的股票数量,这里买入预测股票列表排名靠前的5只
        stock_count = 3
        # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[0.339160, 0.213986, 0.169580, ..]
        context.stock_weights = T.norm([1 / math.log(i + 2) for i in range(0, stock_count)])
        # 设置每只股票占用的最大资金比例
        context.max_cash_per_instrument = 0.6
        context.options['hold_days'] = 5
    
        from zipline.finance.slippage import SlippageModel
        class FixedPriceSlippage(SlippageModel):
            def process_order(self, data, order, bar_volume=0, trigger_check_price=0):
                if order.limit is None:
                    price_field = self._price_field_buy if order.amount > 0 else self._price_field_sell
                    price = data.current(order.asset, price_field)
                else:
                    price = data.current(order.asset, self._price_field_buy)
                # 返回希望成交的价格和数量
                return (price, order.amount)
        # 设置price_field,默认是开盘买入,收盘卖出
        context.fix_slippage = FixedPriceSlippage(price_field_buy='open', price_field_sell='close')
        context.set_slippage(us_equities=context.fix_slippage)
    # 回测引擎:每日数据处理函数,每天执行一次
    def m4_handle_data_bigquant_run(context, data):
        # 获取当前持仓
        positions = {e.symbol: p.amount * p.last_sale_price
                     for e, p in context.portfolio.positions.items()}
        
        today = data.current_dt.strftime('%Y-%m-%d')
        # 按日期过滤得到今日的预测数据
        ranker_prediction = context.ranker_prediction[
            context.ranker_prediction.date == today]
        
        #大盘风控模块,读取风控数据    
        benckmark_risk=ranker_prediction['bm_0'].values[0]
    
        #当risk为1时,市场有风险,全部平仓,不再执行其它操作
        if benckmark_risk > 0:
            for instrument in positions.keys():
                context.order_target(context.symbol(instrument), 0)
            print(today,'大盘风控止损触发,全仓卖出')
            return
        
        # 1. 资金分配
        # 平均持仓时间是hold_days,每日都将买入股票,每日预期使用 1/hold_days 的资金
        # 实际操作中,会存在一定的买入误差,所以在前hold_days天,等量使用资金;之后,尽量使用剩余资金(这里设置最多用等量的1.5倍)
        is_staging = context.trading_day_index < context.options['hold_days'] # 是否在建仓期间(前 hold_days 天)
        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. 根据需要加入移动止赢止损模块、固定天数卖出模块、ST或退市股卖出模块
        stock_sold = [] # 记录卖出的股票,防止多次卖出出现空单
        
        #------------------------START:止赢止损模块(含建仓期)---------------
        current_stopwin_stock=[]
        current_stoploss_stock = []   
        positions_cost={e.symbol:p.cost_basis for e,p in context.portfolio.positions.items()}
        if len(positions)>0:
            for instrument in positions.keys():
                stock_cost=positions_cost[instrument]  
                stock_market_price=data.current(context.symbol(instrument),'price')  
                # 赚9%且为可交易状态就止盈
                if stock_market_price/stock_cost-1>=0.09 and data.can_trade(context.symbol(instrument)):
                    context.order_target_percent(context.symbol(instrument),0)
                    cash_for_sell -= positions[instrument]
                    current_stopwin_stock.append(instrument)
                # 亏5%并且为可交易状态就止损
                if stock_market_price/stock_cost-1 <= -0.05 and data.can_trade(context.symbol(instrument)):   
                    context.order_target_percent(context.symbol(instrument),0)
                    cash_for_sell -= positions[instrument]
                    current_stoploss_stock.append(instrument)
            if len(current_stopwin_stock)>0:
                print(today,'止盈股票列表',current_stopwin_stock)
                stock_sold += current_stopwin_stock
            if len(current_stoploss_stock)>0:
                print(today,'止损股票列表',current_stoploss_stock)
                stock_sold += current_stoploss_stock
        #--------------------------END: 止赢止损模块--------------------------
        
        #--------------------------START:持有固定天数卖出(不含建仓期)-----------
        current_stopdays_stock = []
        positions_lastdate = {e.symbol:p.last_sale_date for e,p in context.portfolio.positions.items()}
        # 不是建仓期(在前hold_days属于建仓期)
        if not is_staging:
            for instrument in positions.keys():
                #如果上面的止盈止损已经卖出过了,就不要重复卖出以防止产生空单
                if instrument in stock_sold:
                    continue
                # 今天和上次交易的时间相隔hold_days就全部卖出 datetime.timedelta(context.options['hold_days'])也可以换成自己需要的天数,比如datetime.timedelta(5)
                if data.current_dt - positions_lastdate[instrument]>=datetime.timedelta(5) and data.can_trade(context.symbol(instrument)):
                    context.order_target_percent(context.symbol(instrument), 0)
                    current_stopdays_stock.append(instrument)
                    cash_for_sell -= positions[instrument]
            if len(current_stopdays_stock)>0:        
                print(today,'固定天数卖出列表',current_stopdays_stock)
                stock_sold += current_stopdays_stock
        #-------------------------  END:持有固定天数卖出-----------------------
        
        #-------------------------- START: ST和退市股卖出 ---------------------  
        st_stock_list = []
        for instrument in positions.keys():
            try:
                instrument_name = ranker_prediction[ranker_prediction.instrument==instrument].name.values[0]
                # 如果股票状态变为了st或者退市 则卖出
                if 'ST' in instrument_name or '退' in instrument_name:
                    if instrument in stock_sold:
                        continue
                    if data.can_trade(context.symbol(instrument)):
                        context.order_target(context.symbol(instrument), 0)
                        st_stock_list.append(instrument)
                        cash_for_sell -= positions[instrument]
            except:
                continue
        if st_stock_list!=[]:
            print(today,'持仓出现st股/退市股',st_stock_list,'进行卖出处理')    
            stock_sold += st_stock_list
    
        #-------------------------- END: ST和退市股卖出 --------------------- 
        
        
        # 3. 生成轮仓卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰
        if not is_staging and cash_for_sell > 0:
            instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(
                    lambda x: x in positions)])))
            for instrument in instruments:
                # 如果资金够了就不卖出了
                if cash_for_sell <= 0:
                    break
                #防止多个止损条件同时满足,出现多次卖出产生空单
                if instrument in stock_sold:
                    continue
                context.order_target(context.symbol(instrument), 0)
                cash_for_sell -= positions[instrument]
                stock_sold.append(instrument)
    
        # 4. 生成轮仓买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票
        # 计算今日跌停的股票
        dt_list = list(ranker_prediction[ranker_prediction.price_limit_status_0==1].instrument)
        # 计算今日ST/退市的股票
        st_list = list(ranker_prediction[ranker_prediction.name.str.contains('ST')|ranker_prediction.name.str.contains('退')].instrument)
        # 计算所有禁止买入的股票池
        banned_list = stock_sold+dt_list+st_list
        buy_cash_weights = context.stock_weights
        buy_instruments=[k for k in list(ranker_prediction.instrument) if k not in banned_list][:len(buy_cash_weights)]
        max_cash_per_instrument = context.portfolio.portfolio_value * context.max_cash_per_instrument
        for i, instrument in enumerate(buy_instruments):
            cash = cash_for_buy * buy_cash_weights[i]
            if cash > max_cash_per_instrument - positions.get(instrument, 0):
                # 确保股票持仓量不会超过每次股票最大的占用资金量
                cash = max_cash_per_instrument - positions.get(instrument, 0)
            if cash > 0:
                context.order_value(context.symbol(instrument), cash)
        
    
    
    # 回测引擎:准备数据,只执行一次
    def m4_prepare_bigquant_run(context):
        pass
    def m4_before_trading_start_bigquant_run(context, data):
        # 获取涨跌停状态数据
        df_price_limit_status = context.ranker_prediction.set_index('date')
        today=data.current_dt.strftime('%Y-%m-%d')
        # 得到当前未完成订单
        for orders in get_open_orders().values():
            # 循环,撤销订单
            for _order in orders:
                ins=str(_order.sid.symbol)
                try:
                    #判断一下如果当日涨停,则取消卖单
                    if  df_price_limit_status[df_price_limit_status.instrument==ins].price_limit_status_0.ix[today]>2 and _order.amount<0:
                        cancel_order(_order)
                        print(today,'尾盘涨停取消卖单',ins) 
                except:
                    continue
    
    m1 = M.instruments.v2(
        start_date='2010-01-01',
        end_date='2015-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m2 = M.advanced_auto_labeler.v2(
        instruments=m1.data,
        label_expr="""# #号开始的表示注释
    # 0. 每行一个,顺序执行,从第二个开始,可以使用label字段
    # 1. 可用数据字段见 https://bigquant.com/docs/data_history_data.html
    #   添加benchmark_前缀,可使用对应的benchmark数据
    # 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/big_expr.html>`_
    
    # 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
    shift(close, -5) / shift(open, -1)
    
    # 极值处理:用1%和99%分位的值做clip
    clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))
    
    # 将分数映射到分类,这里使用20个分类
    all_wbins(label, 20)
    
    # 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)
    where(shift(high, -1) == shift(low, -1), NaN, label)
    """,
        start_date='',
        end_date='',
        benchmark='000300.SHA',
        drop_na_label=True,
        cast_label_int=True
    )
    
    m3 = M.input_features.v1(
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    return_5
    return_10
    return_20
    avg_amount_0/avg_amount_5
    avg_amount_5/avg_amount_20
    rank_avg_amount_0/rank_avg_amount_5
    rank_avg_amount_5/rank_avg_amount_10
    rank_return_0
    rank_return_5
    rank_return_10
    rank_return_0/rank_return_5
    rank_return_5/rank_return_10
    pe_ttm_0
    """
    )
    
    m15 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m16 = M.derived_feature_extractor.v3(
        input_data=m15.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    m7 = M.join.v3(
        data1=m2.data,
        data2=m16.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m13 = M.dropnan.v1(
        input_data=m7.data
    )
    
    m5 = M.stock_ranker_train.v6(
        training_ds=m13.data,
        features=m3.data,
        learning_algorithm='排序',
        number_of_leaves=30,
        minimum_docs_per_leaf=1000,
        number_of_trees=20,
        learning_rate=0.1,
        max_bins=1023,
        feature_fraction=1,
        data_row_fraction=1,
        ndcg_discount_base=1,
        m_lazy_run=False
    )
    
    m6 = M.input_features.v1(
        features_ds=m3.data,
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    price_limit_status_0"""
    )
    
    m9 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2015-01-01'),
        end_date=T.live_run_param('trading_date', '2017-01-01'),
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m17 = M.general_feature_extractor.v7(
        instruments=m9.data,
        features=m6.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m18 = M.derived_feature_extractor.v3(
        input_data=m17.data,
        features=m6.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    m14 = M.dropnan.v1(
        input_data=m18.data
    )
    
    m8 = M.stock_ranker_predict.v5(
        model=m5.model,
        data=m14.data,
        m_lazy_run=False
    )
    
    m10 = M.select_columns.v3(
        input_ds=m14.data,
        columns='date,instrument,price_limit_status_0',
        reverse_select=False
    )
    
    m11 = M.join.v3(
        data1=m8.predictions,
        data2=m10.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m20 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    name"""
    )
    
    m22 = M.use_datasource.v1(
        instruments=m9.data,
        features=m20.data,
        datasource_id='instruments_CN_STOCK_A',
        start_date='',
        end_date=''
    )
    
    m24 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    bm_0 = where(close/shift(close,5)-1<-0.05,1,0)"""
    )
    
    m29 = M.index_feature_extract.v2(
        input_1=m9.data,
        input_2=m24.data,
        before_days=100,
        index='000300.HIX'
    )
    
    m26 = M.select_columns.v3(
        input_ds=m29.data_1,
        columns='date,bm_0',
        reverse_select=False
    )
    
    m25 = M.join.v3(
        data1=m22.data,
        data2=m26.data,
        on='date',
        how='left',
        sort=True
    )
    
    m27 = M.join.v3(
        data1=m11.data,
        data2=m25.data,
        on='date,instrument',
        how='left',
        sort=False
    )
    
    m12 = M.sort.v4(
        input_ds=m27.data,
        sort_by='position',
        group_by='date',
        keep_columns='--',
        ascending=True
    )
    
    m4 = M.trade.v4(
        instruments=m9.data,
        options_data=m12.sorted_data,
        start_date='',
        end_date='',
        initialize=m4_initialize_bigquant_run,
        handle_data=m4_handle_data_bigquant_run,
        prepare=m4_prepare_bigquant_run,
        before_trading_start=m4_before_trading_start_bigquant_run,
        volume_limit=0.025,
        order_price_field_buy='open',
        order_price_field_sell='close',
        capital_base=1000001,
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='后复权',
        product_type='股票',
        plot_charts=True,
        backtest_only=False,
        benchmark=''
    )
    
    设置测试数据集,查看训练迭代过程的NDCG
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-1eb4dc73bba244f5ab8301dd0d063372"}/bigcharts-data-end
    2015-01-08 止盈股票列表 ['300109.SZA']
    2015-01-09 止盈股票列表 ['300038.SZA', '300367.SZA']
    2015-01-12 止盈股票列表 ['300238.SZA']
    2015-01-12 止损股票列表 ['000981.SZA']
    2015-01-12 固定天数卖出列表 ['300391.SZA']
    2015-01-13 止盈股票列表 ['300380.SZA']
    2015-01-14 止盈股票列表 ['000821.SZA', '002190.SZA']
    2015-01-19 固定天数卖出列表 ['300139.SZA']
    2015-01-21 尾盘涨停取消卖单 600643.SHA
    2015-01-21 止盈股票列表 ['300169.SZA', '002579.SZA', '000959.SZA', '600643.SHA']
    2015-01-21 固定天数卖出列表 ['000809.SZA']
    2015-01-22 止盈股票列表 ['002057.SZA']
    2015-01-26 固定天数卖出列表 ['002016.SZA']
    2015-01-27 止盈股票列表 ['002631.SZA']
    2015-01-27 固定天数卖出列表 ['002461.SZA', '002484.SZA', '600338.SHA']
    2015-01-28 止损股票列表 ['002714.SZA']
    2015-01-28 固定天数卖出列表 ['002164.SZA']
    2015-01-29 止盈股票列表 ['300249.SZA']
    2015-02-02 大盘风控止损触发,全仓卖出
    2015-02-06 止损股票列表 ['002648.SZA']
    2015-02-09 固定天数卖出列表 ['002472.SZA']
    2015-02-12 止盈股票列表 ['000705.SZA']
    2015-02-16 固定天数卖出列表 ['600444.SHA', '000597.SZA']
    2015-02-17 固定天数卖出列表 ['300317.SZA']
    2015-02-25 固定天数卖出列表 ['000567.SZA', '603010.SHA', '600793.SHA', '001896.SZA', '000038.SZA', '600378.SHA']
    2015-03-02 尾盘涨停取消卖单 600338.SHA
    2015-03-02 止盈股票列表 ['600338.SHA']
    2015-03-03 止盈股票列表 ['002240.SZA']
    2015-03-03 固定天数卖出列表 ['000885.SZA']
    2015-03-04 固定天数卖出列表 ['000985.SZA', '000589.SZA']
    2015-03-10 固定天数卖出列表 ['300320.SZA']
    2015-03-11 固定天数卖出列表 ['300261.SZA']
    2015-03-16 固定天数卖出列表 ['000619.SZA']
    2015-03-17 止盈股票列表 ['002629.SZA']
    2015-03-17 固定天数卖出列表 ['002639.SZA']
    2015-03-18 止盈股票列表 ['002703.SZA']
    2015-03-18 固定天数卖出列表 ['002688.SZA', '002425.SZA']
    2015-03-20 尾盘涨停取消卖单 600793.SHA
    2015-03-24 固定天数卖出列表 ['600715.SHA']
    2015-03-26 止盈股票列表 ['002425.SZA']
    2015-03-30 止盈股票列表 ['600071.SHA']
    2015-03-30 固定天数卖出列表 ['002541.SZA', '002210.SZA']
    2015-03-31 止盈股票列表 ['000017.SZA']
    2015-03-31 固定天数卖出列表 ['600072.SHA']
    2015-04-01 固定天数卖出列表 ['300094.SZA', '600617.SHA']
    2015-04-02 止盈股票列表 ['300100.SZA', '600647.SHA']
    2015-04-03 尾盘涨停取消卖单 600647.SHA
    2015-04-03 尾盘涨停取消卖单 000797.SZA
    2015-04-03 止盈股票列表 ['000797.SZA', '600421.SHA', '000560.SZA', '600647.SHA']
    2015-04-07 止盈股票列表 ['600295.SHA', '300173.SZA', '300375.SZA', '300282.SZA']
    2015-04-07 固定天数卖出列表 ['000421.SZA', '600782.SHA']
    2015-04-08 固定天数卖出列表 ['002706.SZA', '300391.SZA']
    2015-04-09 止损股票列表 ['002689.SZA']
    2015-04-13 止盈股票列表 ['600671.SHA']
    2015-04-14 固定天数卖出列表 ['600452.SHA']
    2015-04-15 止损股票列表 ['300236.SZA']
    2015-04-15 固定天数卖出列表 ['002619.SZA']
    2015-04-17 止盈股票列表 ['600731.SHA']
    2015-04-21 止盈股票列表 ['603600.SHA', '300226.SZA']
    2015-04-21 固定天数卖出列表 ['002537.SZA']
    2015-04-23 尾盘涨停取消卖单 600768.SHA
    2015-04-23 止盈股票列表 ['600768.SHA']
    2015-04-27 固定天数卖出列表 ['002058.SZA', '300100.SZA']
    2015-04-28 固定天数卖出列表 ['300138.SZA', '000004.SZA']
    2015-05-04 止盈股票列表 ['600985.SHA', '300266.SZA']
    2015-05-04 固定天数卖出列表 ['300123.SZA']
    2015-05-05 止损股票列表 ['002662.SZA']
    2015-05-06 止损股票列表 ['002591.SZA', '002381.SZA']
    2015-05-07 大盘风控止损触发,全仓卖出
    2015-05-11 止盈股票列表 ['600399.SHA']
    2015-05-13 尾盘涨停取消卖单 600156.SHA
    2015-05-13 止盈股票列表 ['600156.SHA']
    2015-05-14 止盈股票列表 ['601010.SHA']
    2015-05-15 止盈股票列表 ['002473.SZA']
    2015-05-18 尾盘涨停取消卖单 002473.SZA
    2015-05-18 止盈股票列表 ['002473.SZA', '600305.SHA']
    2015-05-18 固定天数卖出列表 ['600984.SHA']
    2015-05-19 尾盘涨停取消卖单 600984.SHA
    2015-05-19 止盈股票列表 ['600984.SHA', '000678.SZA']
    2015-05-19 固定天数卖出列表 ['000656.SZA']
    2015-05-20 尾盘涨停取消卖单 600984.SHA
    2015-05-20 止盈股票列表 ['600984.SHA', '000032.SZA']
    2015-05-20 固定天数卖出列表 ['002700.SZA']
    2015-05-21 止盈股票列表 ['600715.SHA']
    2015-05-22 尾盘涨停取消卖单 600715.SHA
    2015-05-22 止盈股票列表 ['600715.SHA']
    2015-05-25 尾盘涨停取消卖单 600715.SHA
    2015-05-25 止盈股票列表 ['600715.SHA']
    2015-05-25 固定天数卖出列表 ['000716.SZA']
    2015-05-26 止盈股票列表 ['002703.SZA', '300398.SZA']
    2015-05-27 止盈股票列表 ['600679.SHA', '600671.SHA']
    2015-05-27 固定天数卖出列表 ['002141.SZA']
    2015-05-28 止损股票列表 ['600163.SHA', '600731.SHA', '002534.SZA', '300120.SZA', '002393.SZA']
    2015-06-01 止盈股票列表 ['000524.SZA', '002514.SZA']
    2015-06-01 固定天数卖出列表 ['600679.SHA', '002619.SZA']
    2015-06-02 尾盘涨停取消卖单 000524.SZA
    2015-06-02 尾盘涨停取消卖单 002514.SZA
    2015-06-02 尾盘涨停取消卖单 300023.SZA
    2015-06-02 止盈股票列表 ['000524.SZA', '300023.SZA', '002514.SZA', '002572.SZA', '002599.SZA']
    2015-06-03 尾盘涨停取消卖单 000524.SZA
    2015-06-03 止盈股票列表 ['000524.SZA', '300354.SZA', '002671.SZA']
    2015-06-04 尾盘涨停取消卖单 000524.SZA
    2015-06-04 止盈股票列表 ['000524.SZA']
    2015-06-08 尾盘涨停取消卖单 600242.SHA
    2015-06-08 止盈股票列表 ['603088.SHA']
    2015-06-08 止损股票列表 ['300174.SZA']
    2015-06-08 固定天数卖出列表 ['600771.SHA', '600242.SHA']
    2015-06-12 尾盘涨停取消卖单 300380.SZA
    2015-06-12 止盈股票列表 ['300380.SZA']
    2015-06-15 止损股票列表 ['300385.SZA', '300359.SZA']
    2015-06-16 止盈股票列表 ['300349.SZA']
    2015-06-16 止损股票列表 ['300380.SZA', '002124.SZA', '601222.SHA']
    2015-06-18 大盘风控止损触发,全仓卖出
    2015-06-19 尾盘涨停取消卖单 300119.SZA
    2015-06-19 大盘风控止损触发,全仓卖出
    2015-06-23 大盘风控止损触发,全仓卖出
    2015-06-25 大盘风控止损触发,全仓卖出
    2015-06-26 大盘风控止损触发,全仓卖出
    2015-06-29 大盘风控止损触发,全仓卖出
    2015-06-30 大盘风控止损触发,全仓卖出
    2015-07-01 大盘风控止损触发,全仓卖出
    2015-07-02 大盘风控止损触发,全仓卖出
    2015-07-03 大盘风控止损触发,全仓卖出
    2015-07-07 大盘风控止损触发,全仓卖出
    2015-07-08 大盘风控止损触发,全仓卖出
    2015-07-09 尾盘涨停取消卖单 600235.SHA
    2015-07-09 尾盘涨停取消卖单 603268.SHA
    2015-07-09 大盘风控止损触发,全仓卖出
    2015-07-10 尾盘涨停取消卖单 600235.SHA
    2015-07-10 尾盘涨停取消卖单 603268.SHA
    2015-07-13 尾盘涨停取消卖单 600235.SHA
    2015-07-13 止盈股票列表 ['600235.SHA', '603268.SHA']
    2015-07-13 固定天数卖出列表 ['600770.SHA']
    2015-07-14 尾盘涨停取消卖单 600770.SHA
    2015-07-14 止盈股票列表 ['600770.SHA', '600391.SHA', '600287.SHA']
    2015-07-15 止损股票列表 ['600200.SHA', '600105.SHA', '002576.SZA', '300366.SZA', '300457.SZA']
    2015-07-16 尾盘涨停取消卖单 300366.SZA
    2015-07-16 止盈股票列表 ['002715.SZA']
    2015-07-17 尾盘涨停取消卖单 002715.SZA
    2015-07-17 尾盘涨停取消卖单 600391.SHA
    2015-07-17 止盈股票列表 ['600391.SHA', '300359.SZA', '002715.SZA']
    2015-07-20 尾盘涨停取消卖单 600391.SHA
    2015-07-20 尾盘涨停取消卖单 300359.SZA
    2015-07-20 止盈股票列表 ['600391.SHA', '300216.SZA', '300359.SZA', '002590.SZA', '000048.SZA', '002659.SZA']
    2015-07-20 固定天数卖出列表 ['002307.SZA', '600287.SHA']
    2015-07-21 尾盘涨停取消卖单 300359.SZA
    2015-07-21 尾盘涨停取消卖单 000048.SZA
    2015-07-21 止盈股票列表 ['300359.SZA', '002631.SZA', '000048.SZA', '000961.SZA', '600986.SHA', '002682.SZA']
    2015-07-22 尾盘涨停取消卖单 002682.SZA
    2015-07-22 止盈股票列表 ['000554.SZA', '002682.SZA']
    2015-07-23 止盈股票列表 ['600848.SHA']
    2015-07-24 止损股票列表 ['300069.SZA']
    2015-07-27 大盘风控止损触发,全仓卖出
    2015-07-28 尾盘涨停取消卖单 000721.SZA
    2015-07-28 大盘风控止损触发,全仓卖出
    2015-07-29 尾盘涨停取消卖单 300069.SZA
    2015-07-29 尾盘涨停取消卖单 000592.SZA
    2015-07-29 大盘风控止损触发,全仓卖出
    2015-07-30 大盘风控止损触发,全仓卖出
    2015-07-31 大盘风控止损触发,全仓卖出
    2015-08-03 止损股票列表 ['000716.SZA']
    2015-08-04 止盈股票列表 ['002298.SZA']
    2015-08-04 止损股票列表 ['000716.SZA']
    2015-08-05 止损股票列表 ['300384.SZA']
    2015-08-07 尾盘涨停取消卖单 600570.SHA
    2015-08-07 止盈股票列表 ['600570.SHA', '300016.SZA', '002201.SZA']
    2015-08-10 止盈股票列表 ['300226.SZA', '600890.SHA', '300220.SZA']
    2015-08-11 尾盘涨停取消卖单 600890.SHA
    2015-08-11 止盈股票列表 ['600890.SHA']
    2015-08-18 大盘风控止损触发,全仓卖出
    2015-08-20 大盘风控止损触发,全仓卖出
    2015-08-21 大盘风控止损触发,全仓卖出
    2015-08-24 大盘风控止损触发,全仓卖出
    2015-08-25 大盘风控止损触发,全仓卖出
    2015-08-26 大盘风控止损触发,全仓卖出
    2015-08-27 大盘风控止损触发,全仓卖出
    2015-08-28 大盘风控止损触发,全仓卖出
    2015-09-01 止损股票列表 ['002387.SZA', '600433.SHA', '000821.SZA']
    2015-09-02 尾盘涨停取消卖单 002387.SZA
    2015-09-02 止盈股票列表 ['300033.SZA']
    2015-09-02 止损股票列表 ['600433.SHA']
    2015-09-07 固定天数卖出列表 ['002387.SZA', '601137.SHA']
    2015-09-08 止盈股票列表 ['000821.SZA', '002461.SZA', '600171.SHA', '300388.SZA']
    2015-09-09 尾盘涨停取消卖单 000821.SZA
    2015-09-09 止盈股票列表 ['000821.SZA', '603008.SHA', '000592.SZA', '002515.SZA']
    2015-09-14 止损股票列表 ['300101.SZA', '600807.SHA', '600184.SHA', '002190.SZA', '000738.SZA', '000768.SZA', '600391.SHA']
    2015-09-15 大盘风控止损触发,全仓卖出
    2015-09-16 尾盘涨停取消卖单 300277.SZA
    2015-09-16 尾盘涨停取消卖单 002190.SZA
    2015-09-16 尾盘涨停取消卖单 000738.SZA
    2015-09-16 尾盘涨停取消卖单 000768.SZA
    2015-09-16 尾盘涨停取消卖单 600391.SHA
    2015-09-16 止损股票列表 ['002190.SZA', '000738.SZA', '000768.SZA', '600391.SHA']
    2015-09-16 固定天数卖出列表 ['300277.SZA']
    2015-09-21 止盈股票列表 ['000930.SZA', '001696.SZA', '000547.SZA']
    2015-09-22 止盈股票列表 ['002673.SZA']
    2015-09-22 固定天数卖出列表 ['601886.SHA', '000012.SZA']
    2015-09-23 固定天数卖出列表 ['000564.SZA']
    2015-09-24 止盈股票列表 ['603166.SHA']
    2015-09-25 止损股票列表 ['300128.SZA', '002759.SZA', '603021.SHA', '002729.SZA']
    2015-09-29 止损股票列表 ['002217.SZA']
    2015-09-30 止损股票列表 ['002592.SZA']
    2015-09-30 固定天数卖出列表 ['002645.SZA']
    2015-10-08 固定天数卖出列表 ['600121.SHA', '600797.SHA', '000930.SZA']
    2015-10-12 止盈股票列表 ['600355.SHA', '000720.SZA']
    2015-10-13 止盈股票列表 ['002414.SZA', '002217.SZA']
    2015-10-14 止盈股票列表 ['603600.SHA']
    2015-10-15 止盈股票列表 ['000650.SZA']
    2015-10-19 止盈股票列表 ['300089.SZA']
    2015-10-20 固定天数卖出列表 ['600202.SHA']
    2015-10-21 止损股票列表 ['600202.SHA', '603017.SHA', '000510.SZA', '603198.SHA', '000887.SZA', '300316.SZA', '000712.SZA']
    2015-10-26 固定天数卖出列表 ['300135.SZA']
    2015-11-09 固定天数卖出列表 ['300184.SZA']
    2015-11-12 止盈股票列表 ['300135.SZA']
    2015-11-16 止盈股票列表 ['002671.SZA']
    2015-11-17 止盈股票列表 ['600987.SHA']
    2015-11-23 止盈股票列表 ['002238.SZA', '000411.SZA']
    2015-11-23 固定天数卖出列表 ['300214.SZA']
    2015-11-24 尾盘涨停取消卖单 000411.SZA
    2015-11-24 止盈股票列表 ['000411.SZA', '000025.SZA']
    2015-11-24 固定天数卖出列表 ['002225.SZA']
    2015-11-25 尾盘涨停取消卖单 000025.SZA
    2015-11-25 止盈股票列表 ['000025.SZA']
    2015-11-25 固定天数卖出列表 ['600211.SHA']
    2015-11-26 尾盘涨停取消卖单 000025.SZA
    2015-11-26 止盈股票列表 ['000025.SZA', '601015.SHA']
    2015-11-27 尾盘涨停取消卖单 000025.SZA
    2015-11-27 大盘风控止损触发,全仓卖出
    2015-11-30 尾盘涨停取消卖单 000025.SZA
    2015-11-30 尾盘涨停取消卖单 002213.SZA
    2015-11-30 止盈股票列表 ['000025.SZA']
    2015-11-30 固定天数卖出列表 ['002213.SZA']
    2015-12-01 止盈股票列表 ['000025.SZA']
    2015-12-03 止盈股票列表 ['002690.SZA']
    2015-12-07 止盈股票列表 ['002301.SZA']
    2015-12-07 固定天数卖出列表 ['000908.SZA']
    2015-12-08 止盈股票列表 ['300308.SZA']
    2015-12-09 固定天数卖出列表 ['601566.SHA']
    2015-12-10 止损股票列表 ['002210.SZA']
    2015-12-14 固定天数卖出列表 ['002158.SZA']
    2015-12-15 固定天数卖出列表 ['002669.SZA']
    2015-12-16 固定天数卖出列表 ['300134.SZA']
    2015-12-17 尾盘涨停取消卖单 300134.SZA
    2015-12-17 止盈股票列表 ['300134.SZA', '300094.SZA']
    2015-12-21 尾盘涨停取消卖单 600615.SHA
    2015-12-21 止盈股票列表 ['600615.SHA']
    2015-12-21 固定天数卖出列表 ['002067.SZA']
    2015-12-23 固定天数卖出列表 ['600643.SHA']
    2015-12-28 止损股票列表 ['002676.SZA', '300393.SZA']
    2015-12-28 固定天数卖出列表 ['002459.SZA']
    2015-12-29 止损股票列表 ['600058.SHA']
    2015-12-31 止损股票列表 ['300418.SZA']
    2016-01-04 大盘风控止损触发,全仓卖出
    2016-01-05 大盘风控止损触发,全仓卖出
    2016-01-06 尾盘涨停取消卖单 002599.SZA
    2016-01-06 大盘风控止损触发,全仓卖出
    2016-01-07 大盘风控止损触发,全仓卖出
    2016-01-08 大盘风控止损触发,全仓卖出
    2016-01-11 大盘风控止损触发,全仓卖出
    2016-01-12 大盘风控止损触发,全仓卖出
    2016-01-13 大盘风控止损触发,全仓卖出
    2016-01-15 大盘风控止损触发,全仓卖出
    2016-01-20 止盈股票列表 ['600179.SHA', '300368.SZA']
    2016-01-21 止损股票列表 ['300309.SZA']
    2016-01-25 固定天数卖出列表 ['600288.SHA', '002072.SZA', '300420.SZA']
    2016-01-26 大盘风控止损触发,全仓卖出
    2016-01-27 大盘风控止损触发,全仓卖出
    2016-01-28 大盘风控止损触发,全仓卖出
    2016-01-29 大盘风控止损触发,全仓卖出
    2016-02-01 大盘风控止损触发,全仓卖出
    2016-02-03 止盈股票列表 ['000953.SZA']
    2016-02-04 尾盘涨停取消卖单 000953.SZA
    2016-02-04 止盈股票列表 ['002473.SZA', '000953.SZA', '002301.SZA']
    2016-02-05 止盈股票列表 ['000720.SZA']
    2016-02-05 固定天数卖出列表 ['002473.SZA']
    2016-02-15 止盈股票列表 ['600226.SHA']
    2016-02-15 止损股票列表 ['002473.SZA']
    2016-02-15 固定天数卖出列表 ['600150.SHA', '300354.SZA', '002363.SZA', '300215.SZA', '002205.SZA']
    2016-02-16 尾盘涨停取消卖单 002363.SZA
    2016-02-16 止盈股票列表 ['000626.SZA']
    2016-02-16 固定天数卖出列表 ['002363.SZA']
    2016-02-17 止盈股票列表 ['600568.SHA', '002568.SZA', '300368.SZA']
    2016-02-22 止盈股票列表 ['300032.SZA']
    2016-02-23 止盈股票列表 ['002782.SZA']
    2016-02-23 固定天数卖出列表 ['300355.SZA']
    2016-02-24 止盈股票列表 ['002308.SZA']
    2016-02-24 止损股票列表 ['300242.SZA']
    2016-02-24 固定天数卖出列表 ['002373.SZA']
    2016-02-25 止损股票列表 ['002373.SZA', '000901.SZA', '000889.SZA', '600479.SHA', '002368.SZA', '300452.SZA']
    2016-02-26 止损股票列表 ['002308.SZA']
    2016-02-29 大盘风控止损触发,全仓卖出
    2016-03-01 大盘风控止损触发,全仓卖出
    2016-03-04 止损股票列表 ['002373.SZA', '300083.SZA']
    2016-03-08 尾盘涨停取消卖单 000785.SZA
    2016-03-08 止盈股票列表 ['000785.SZA']
    2016-03-09 固定天数卖出列表 ['000712.SZA']
    2016-03-10 止损股票列表 ['002373.SZA']
    2016-03-11 止损股票列表 ['300379.SZA']
    2016-03-14 尾盘涨停取消卖单 300379.SZA
    2016-03-14 固定天数卖出列表 ['300069.SZA']
    2016-03-15 固定天数卖出列表 ['300368.SZA', '300379.SZA', '002494.SZA']
    2016-03-21 止盈股票列表 ['000901.SZA', '000066.SZA']
    2016-03-22 止盈股票列表 ['600490.SHA', '002053.SZA']
    2016-03-23 固定天数卖出列表 ['600871.SHA']
    2016-04-06 止盈股票列表 ['300196.SZA']
    2016-04-12 止损股票列表 ['600654.SHA']
    2016-04-13 固定天数卖出列表 ['000791.SZA']
    2016-04-15 止盈股票列表 ['300028.SZA']
    2016-04-18 固定天数卖出列表 ['000908.SZA']
    2016-04-20 止损股票列表 ['300456.SZA', '601515.SHA', '603718.SHA']
    2016-04-25 止损股票列表 ['600654.SHA']
    2016-04-26 止盈股票列表 ['600452.SHA']
    2016-04-26 固定天数卖出列表 ['300430.SZA']
    2016-05-06 止损股票列表 ['002018.SZA']
    2016-05-09 止损股票列表 ['002018.SZA', '002312.SZA', '600803.SHA', '002440.SZA']
    2016-05-10 止损股票列表 ['600745.SHA']
    2016-05-11 止损股票列表 ['002018.SZA']
    2016-05-12 止损股票列表 ['300023.SZA']
    2016-05-16 止盈股票列表 ['300081.SZA', '300459.SZA']
    2016-05-17 尾盘涨停取消卖单 300081.SZA
    2016-05-17 止盈股票列表 ['300081.SZA']
    2016-05-18 止损股票列表 ['002018.SZA']
    2016-05-20 尾盘涨停取消卖单 002326.SZA
    2016-05-20 止盈股票列表 ['002326.SZA', '300162.SZA', '300431.SZA']
    2016-05-23 固定天数卖出列表 ['000838.SZA', '600678.SHA']
    2016-05-25 固定天数卖出列表 ['002757.SZA', '300443.SZA']
    2016-05-27 止损股票列表 ['600365.SHA']
    2016-05-30 固定天数卖出列表 ['002018.SZA']
    2016-05-31 尾盘涨停取消卖单 002018.SZA
    2016-05-31 止盈股票列表 ['002312.SZA']
    2016-05-31 固定天数卖出列表 ['002018.SZA']
    2016-06-01 止盈股票列表 ['300117.SZA']
    2016-06-03 尾盘涨停取消卖单 300410.SZA
    2016-06-03 止盈股票列表 ['002208.SZA', '300410.SZA']
    2016-06-06 固定天数卖出列表 ['002044.SZA']
    2016-06-13 止损股票列表 ['600365.SHA', '300063.SZA']
    2016-06-13 固定天数卖出列表 ['000989.SZA']
    2016-06-20 止损股票列表 ['600250.SHA']
    2016-06-20 固定天数卖出列表 ['002083.SZA']
    2016-06-21 止损股票列表 ['002667.SZA']
    2016-06-21 固定天数卖出列表 ['000043.SZA']
    2016-06-27 固定天数卖出列表 ['002302.SZA', '600792.SHA']
    2016-06-29 固定天数卖出列表 ['300071.SZA']
    2016-07-04 固定天数卖出列表 ['600153.SHA']
    2016-07-11 止损股票列表 ['600452.SHA']
    2016-07-18 固定天数卖出列表 ['600969.SHA', '000715.SZA', '300029.SZA']
    2016-07-19 固定天数卖出列表 ['600898.SHA', '000090.SZA']
    2016-07-25 固定天数卖出列表 ['002520.SZA', '600510.SHA']
    2016-07-26 固定天数卖出列表 ['002406.SZA']
    2016-07-27 止损股票列表 ['603889.SHA', '002282.SZA', '600857.SHA']
    2016-07-27 固定天数卖出列表 ['600425.SHA', '601218.SHA']
    2016-07-28 止损股票列表 ['603686.SHA']
    2016-08-01 止损股票列表 ['002798.SZA']
    2016-08-02 固定天数卖出列表 ['300486.SZA']
    2016-08-08 止盈股票列表 ['300513.SZA']
    2016-08-18 止盈股票列表 ['002569.SZA']
    2016-08-19 尾盘涨停取消卖单 002569.SZA
    2016-08-19 止盈股票列表 ['002569.SZA']
    2016-08-22 尾盘涨停取消卖单 002569.SZA
    2016-08-22 止盈股票列表 ['002569.SZA', '300372.SZA']
    2016-08-23 止盈股票列表 ['300225.SZA']
    2016-09-06 固定天数卖出列表 ['601579.SHA']
    2016-09-12 止损股票列表 ['601116.SHA']
    2016-09-13 固定天数卖出列表 ['603699.SHA']
    2016-09-19 固定天数卖出列表 ['600381.SHA', '002414.SZA']
    2016-09-21 止盈股票列表 ['000638.SZA']
    2016-09-26 止损股票列表 ['002052.SZA', '300517.SZA']
    2016-10-10 尾盘涨停取消卖单 300451.SZA
    2016-10-10 止盈股票列表 ['300451.SZA', '300242.SZA']
    2016-10-14 尾盘涨停取消卖单 002802.SZA
    2016-10-14 止盈股票列表 ['002802.SZA']
    2016-10-18 固定天数卖出列表 ['600793.SHA']
    2016-10-25 尾盘涨停取消卖单 600381.SHA
    2016-11-01 固定天数卖出列表 ['300041.SZA', '300255.SZA']
    2016-11-30 固定天数卖出列表 ['300204.SZA']
    2016-12-07 尾盘涨停取消卖单 600671.SHA
    2016-12-07 止盈股票列表 ['600671.SHA']
    2016-12-12 止损股票列表 ['002703.SZA', '300211.SZA', '603007.SHA', '002207.SZA']
    
    • 收益率545.9%
    • 年化收益率162.04%
    • 基准收益率-6.33%
    • 阿尔法1.01
    • 贝塔0.67
    • 夏普比率2.72
    • 胜率0.62
    • 盈亏比1.02
    • 收益波动率36.98%
    • 信息比率0.2
    • 最大回撤27.62%
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-ce77eebeec1c4657bf488f2e58602e16"}/bigcharts-data-end

    老师您好,我想请教一下这个指数特征抽取模块应该怎么用呢?指数特征抽取(index_feature_extract)使用错误