克隆策略
{"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-107:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-779:data1","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:data"},{"DestinationInputPortId":"-107:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-161:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-819:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-837:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-5546:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-819:input_data","SourceOutputPortId":"-107:data"},{"DestinationInputPortId":"-5546:training_ds","SourceOutputPortId":"-648:data"},{"DestinationInputPortId":"-161:instruments","SourceOutputPortId":"-152:data"},{"DestinationInputPortId":"-213:instruments","SourceOutputPortId":"-152:data"},{"DestinationInputPortId":"-142:instruments","SourceOutputPortId":"-152:data"},{"DestinationInputPortId":"-837:input_data","SourceOutputPortId":"-161:data"},{"DestinationInputPortId":"-5546:predict_ds","SourceOutputPortId":"-187:data"},{"DestinationInputPortId":"-2908:input_1","SourceOutputPortId":"-779:data"},{"DestinationInputPortId":"-779:data2","SourceOutputPortId":"-819:data"},{"DestinationInputPortId":"-2911:input_1","SourceOutputPortId":"-837:data"},{"DestinationInputPortId":"-224:input_data","SourceOutputPortId":"-207:data"},{"DestinationInputPortId":"-207:data1","SourceOutputPortId":"-213:data"},{"DestinationInputPortId":"-5546:test_ds","SourceOutputPortId":"-224:data"},{"DestinationInputPortId":"-648:input_data","SourceOutputPortId":"-2908:data_1"},{"DestinationInputPortId":"-187:input_data","SourceOutputPortId":"-2911:data_1"},{"DestinationInputPortId":"-207:data2","SourceOutputPortId":"-2911:data_1"},{"DestinationInputPortId":"-142:options_data","SourceOutputPortId":"-5546:predictions"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2016-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2019-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,"IsPartOfPartialRun":null,"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, -6)/shift(close, -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,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特\nrank_swing_volatility_60_0\nswing_volatility_30_0\n#ta_rsi_14_0\n#########ta_cci_14_0\n#avg_turn_5\n#########rank_return_20\n#avg_amount_5\n#rank_avg_turn_5\n#mean(turn_0*return_0, 15)\n#rank_swing_volatility_120_0\n#########mean(return_0*turn_0, 180)\n#rank_swing_volatility_60_0\n#std(return_0, 180)\n#volatility_120_0\n#rank_swing_volatility_5_0\n#ta_aroon_up_28_0\n#swing_volatility_60_0\n#std(turn_0, 10)\n#std(return_0, 60)\n##########mean(turn_0*return_0, 90)\n##########std(avg_amount_0, 60)\n##########std(mean(deal_number_0, 180), 180)\n#avg_amount_5\n##(-1 * correlation(high_0, rank(volume_0), 5))\n##((-1 * rank(std(high_0, 10))) * correlation(high_0, volume_0, 10))\n##(-1 * rank(covariance(rank(close_0), rank(volume_0), 5)))\n#std(avg_turn_0, 10)\n############################3rank_swing_volatility_60_0\n############################3swing_volatility_30_0\n############################3ta_rsi_14_0","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,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-107","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":"300","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-107"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-107"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-107","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-142","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.07\n context.options['hold_days'] = 5","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n today = data.current_dt.strftime('%Y-%m-%d')\n stock_hold_now = [equity.symbol for equity in context.portfolio.positions ]\n ##大盘风控模块,读取风控数据 \n #benckmark_risk=context.benckmark_risk[today]\n #context.symbol\n ##当risk为1时,市场有风险,全部平仓,不再执行其它操作\n #if benckmark_risk > 0:\n # for instrument in stock_hold_now:\n # context.order_target(symbol(instrument), 0)\n # print(today,'大盘风控止损触发,全仓卖出')\n # return\n\n \n # 按日期过滤得到今日的预测数据\n ranker_prediction = context.ranker_prediction[\n context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]\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 positions = {e.symbol: p.amount * p.last_sale_price\n for e, p in context.portfolio.positions.items()}\n \n #----------------------------START:持有固定交易日天数卖出---------------------------\n today = data.current_dt.strftime('%Y-%m-%d')\n # 不是建仓期(在前hold_days属于建仓期)\n if not is_staging:\n equities = {e.symbol: p for e, p in context.portfolio.positions.items() if p.amount>0}\n for instrument in equities:\n sid = equities[instrument].sid # 交易标的\n # 今天和上次交易的时间相隔hold_days就全部卖出\n dt = pd.to_datetime(D.trading_days(end_date = today).iloc[-context.options['hold_days']].values[0])\n if pd.to_datetime(equities[instrument].last_sale_date.strftime('%Y-%m-%d')) <= dt and data.can_trade(context.symbol(instrument)):\n context.order_target_percent(sid, 0)\n cash_for_buy += positions[instrument]\n #--------------------------------END:持有固定天数卖出--------------------------- \n \n\n # 3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票\n buy_cash_weights = context.stock_weights\n counto = 1\n buy_instruments = list(ranker_prediction.instrument[:len(buy_cash_weights)])\n while (' '.join(buy_instruments)) in positions.keys():\n buy_instruments = list(ranker_prediction.instrument[counto:len(buy_cash_weights)+counto])\n counto += 1\n \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 #print(context.symbol(instrument), cash)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"def bigquant_run(context):\n #在数据准备函数中一次性计算每日的大盘风控条件相比于在handle中每日计算风控条件可以提高回测速度\n # 多取50天的数据便于计算均值(保证回测的第一天均值不为Nan值),其中context.start_date和context.end_date是回测指定的起始时间和终止时间\n start_date= (pd.to_datetime(context.start_date) - datetime.timedelta(days=50)).strftime('%Y-%m-%d') \n df=DataSource('bar1d_index_CN_STOCK_A').read(start_date=start_date,end_date=context.end_date,fields=['close'])\n benckmark_data=df[df.instrument=='000001.HIX']\n #计算上证指数5日涨幅\n benckmark_data['ret5']=benckmark_data['close']/benckmark_data['close'].shift(1)-1\n #计算大盘风控条件,如果5日涨幅小于-4%则设置风险状态risk为1,否则为0\n benckmark_data['risk'] = np.where(benckmark_data['ret5']<-0.04,1,0)\n #修改日期格式为字符串(便于在handle中使用字符串日期索引来查看每日的风险状态)\n benckmark_data['date']=benckmark_data['date'].apply(lambda x:x.strftime('%Y-%m-%d'))\n #设置日期为索引\n benckmark_data.set_index('date',inplace=True)\n #把风控序列输出给全局变量context.benckmark_risk\n context.benckmark_risk=benckmark_data['risk']\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"volume_limit","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_buy","Value":"close","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"order_price_field_sell","Value":"close","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"capital_base","Value":"500000","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"auto_cancel_non_tradable_orders","Value":"False","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":"-142"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-142"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-142"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-142"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-142"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-142","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":19,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-648","ModuleId":"BigQuantSpace.dropnan.dropnan-v2","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-648"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-648"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-648","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-152","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2019-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2020-09-21","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":"-152"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-152","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-161","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":"300","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-161"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-161"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-161","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-187","ModuleId":"BigQuantSpace.dropnan.dropnan-v2","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-187"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-187"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-187","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":22,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-779","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":"-779"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-779"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-779","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-819","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":"-819"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-819"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-819","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":24,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-837","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":"-837"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-837"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-837","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":26,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-207","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":"-207"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-207"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-207","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-213","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, -6)/shift(close, -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":"-213"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-213","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-224","ModuleId":"BigQuantSpace.dropnan.dropnan-v2","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-224"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-224"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-224","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-2908","ModuleId":"BigQuantSpace.filtet_st_stock.filtet_st_stock-v7","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-2908"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-2908","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-2911","ModuleId":"BigQuantSpace.filtet_st_stock.filtet_st_stock-v7","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-2911"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-2911","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-5546","ModuleId":"BigQuantSpace.stock_ranker.stock_ranker-v2","ModuleParameters":[{"Name":"learning_algorithm","Value":"排序","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_leaves","Value":"5","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"minimum_docs_per_leaf","Value":1000,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"number_of_trees","Value":"10","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":"slim_data","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-5546"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-5546"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"base_model","NodeId":"-5546"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"test_ds","NodeId":"-5546"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_model","NodeId":"-5546"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"predict_ds","NodeId":"-5546"}],"OutputPortsInternal":[{"Name":"model","NodeId":"-5546","OutputType":null},{"Name":"predictions","NodeId":"-5546","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"IsPartOfPartialRun":null,"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='-215,-94,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='-316,69,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='422,-106,200,200'/><NodePosition Node='-107' Position='12,33,200,200'/><NodePosition Node='-142' Position='253,897,200,200'/><NodePosition Node='-648' Position='100,506,200,200'/><NodePosition Node='-152' Position='1080,-152,200,200'/><NodePosition Node='-161' Position='1142,25,200,200'/><NodePosition Node='-187' Position='1062,433,200,200'/><NodePosition Node='-779' Position='-193,253,200,200'/><NodePosition Node='-819' Position='20,126,200,200'/><NodePosition Node='-837' Position='1150,133,200,200'/><NodePosition Node='-207' Position='711,321,200,200'/><NodePosition Node='-213' Position='676,107,200,200'/><NodePosition Node='-224' Position='659,447,200,200'/><NodePosition Node='-2908' Position='-161,392,200,200'/><NodePosition Node='-2911' Position='1146,248,200,200'/><NodePosition Node='-5546' Position='248,694,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 [1]:
# 本代码由可视化策略环境自动生成 2020年9月22日 11:10
# 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
# 回测引擎:初始化函数,只执行一次
def m19_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.07
context.options['hold_days'] = 5
# 回测引擎:每日数据处理函数,每天执行一次
def m19_handle_data_bigquant_run(context, data):
today = data.current_dt.strftime('%Y-%m-%d')
stock_hold_now = [equity.symbol for equity in context.portfolio.positions ]
##大盘风控模块,读取风控数据
#benckmark_risk=context.benckmark_risk[today]
#context.symbol
##当risk为1时,市场有风险,全部平仓,不再执行其它操作
#if benckmark_risk > 0:
# for instrument in stock_hold_now:
# context.order_target(symbol(instrument), 0)
# print(today,'大盘风控止损触发,全仓卖出')
# return
# 按日期过滤得到今日的预测数据
ranker_prediction = context.ranker_prediction[
context.ranker_prediction.date == data.current_dt.strftime('%Y-%m-%d')]
# 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)
positions = {e.symbol: p.amount * p.last_sale_price
for e, p in context.portfolio.positions.items()}
#----------------------------START:持有固定交易日天数卖出---------------------------
today = data.current_dt.strftime('%Y-%m-%d')
# 不是建仓期(在前hold_days属于建仓期)
if not is_staging:
equities = {e.symbol: p for e, p in context.portfolio.positions.items() if p.amount>0}
for instrument in equities:
sid = equities[instrument].sid # 交易标的
# 今天和上次交易的时间相隔hold_days就全部卖出
dt = pd.to_datetime(D.trading_days(end_date = today).iloc[-context.options['hold_days']].values[0])
if pd.to_datetime(equities[instrument].last_sale_date.strftime('%Y-%m-%d')) <= dt and data.can_trade(context.symbol(instrument)):
context.order_target_percent(sid, 0)
cash_for_buy += positions[instrument]
#--------------------------------END:持有固定天数卖出---------------------------
# 3. 生成买入订单:按StockRanker预测的排序,买入前面的stock_count只股票
buy_cash_weights = context.stock_weights
counto = 1
buy_instruments = list(ranker_prediction.instrument[:len(buy_cash_weights)])
while (' '.join(buy_instruments)) in positions.keys():
buy_instruments = list(ranker_prediction.instrument[counto:len(buy_cash_weights)+counto])
counto += 1
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)
#print(context.symbol(instrument), cash)
def m19_prepare_bigquant_run(context):
#在数据准备函数中一次性计算每日的大盘风控条件相比于在handle中每日计算风控条件可以提高回测速度
# 多取50天的数据便于计算均值(保证回测的第一天均值不为Nan值),其中context.start_date和context.end_date是回测指定的起始时间和终止时间
start_date= (pd.to_datetime(context.start_date) - datetime.timedelta(days=50)).strftime('%Y-%m-%d')
df=DataSource('bar1d_index_CN_STOCK_A').read(start_date=start_date,end_date=context.end_date,fields=['close'])
benckmark_data=df[df.instrument=='000001.HIX']
#计算上证指数5日涨幅
benckmark_data['ret5']=benckmark_data['close']/benckmark_data['close'].shift(1)-1
#计算大盘风控条件,如果5日涨幅小于-4%则设置风险状态risk为1,否则为0
benckmark_data['risk'] = np.where(benckmark_data['ret5']<-0.04,1,0)
#修改日期格式为字符串(便于在handle中使用字符串日期索引来查看每日的风险状态)
benckmark_data['date']=benckmark_data['date'].apply(lambda x:x.strftime('%Y-%m-%d'))
#设置日期为索引
benckmark_data.set_index('date',inplace=True)
#把风控序列输出给全局变量context.benckmark_risk
context.benckmark_risk=benckmark_data['risk']
m1 = M.instruments.v2(
start_date='2016-01-01',
end_date='2019-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, -6)/shift(close, -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="""# #号开始的表示注释
# 多个特征,每行一个,可以包含基础特征和衍生特
rank_swing_volatility_60_0
swing_volatility_30_0
#ta_rsi_14_0
#########ta_cci_14_0
#avg_turn_5
#########rank_return_20
#avg_amount_5
#rank_avg_turn_5
#mean(turn_0*return_0, 15)
#rank_swing_volatility_120_0
#########mean(return_0*turn_0, 180)
#rank_swing_volatility_60_0
#std(return_0, 180)
#volatility_120_0
#rank_swing_volatility_5_0
#ta_aroon_up_28_0
#swing_volatility_60_0
#std(turn_0, 10)
#std(return_0, 60)
##########mean(turn_0*return_0, 90)
##########std(avg_amount_0, 60)
##########std(mean(deal_number_0, 180), 180)
#avg_amount_5
##(-1 * correlation(high_0, rank(volume_0), 5))
##((-1 * rank(std(high_0, 10))) * correlation(high_0, volume_0, 10))
##(-1 * rank(covariance(rank(close_0), rank(volume_0), 5)))
#std(avg_turn_0, 10)
############################3rank_swing_volatility_60_0
############################3swing_volatility_30_0
############################3ta_rsi_14_0"""
)
m15 = M.general_feature_extractor.v7(
instruments=m1.data,
features=m3.data,
start_date='',
end_date='',
before_start_days=300
)
m24 = 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,
user_functions={}
)
m10 = M.join.v3(
data1=m2.data,
data2=m24.data,
on='date,instrument',
how='inner',
sort=False
)
m6 = M.filtet_st_stock.v7(
input_1=m10.data
)
m5 = M.dropnan.v2(
input_data=m6.data_1
)
m16 = M.instruments.v2(
start_date='2019-01-01',
end_date='2020-09-21',
market='CN_STOCK_A',
instrument_list='',
max_count=0
)
m18 = M.general_feature_extractor.v7(
instruments=m16.data,
features=m3.data,
start_date='',
end_date='',
before_start_days=300
)
m26 = M.derived_feature_extractor.v3(
input_data=m18.data,
features=m3.data,
date_col='date',
instrument_col='instrument',
drop_na=False,
remove_extra_columns=False,
user_functions={}
)
m7 = M.filtet_st_stock.v7(
input_1=m26.data
)
m22 = M.dropnan.v2(
input_data=m7.data_1
)
m9 = M.advanced_auto_labeler.v2(
instruments=m16.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, -6)/shift(close, -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
)
m8 = M.join.v3(
data1=m9.data,
data2=m7.data_1,
on='date,instrument',
how='inner',
sort=False
)
m11 = M.dropnan.v2(
input_data=m8.data
)
m4 = M.stock_ranker.v2(
training_ds=m5.data,
features=m3.data,
test_ds=m11.data,
predict_ds=m22.data,
learning_algorithm='排序',
number_of_leaves=5,
minimum_docs_per_leaf=1000,
number_of_trees=10,
learning_rate=0.1,
max_bins=1023,
feature_fraction=1,
data_row_fraction=1,
ndcg_discount_base=1,
slim_data=True
)
m19 = M.trade.v4(
instruments=m16.data,
options_data=m4.predictions,
start_date='',
end_date='',
initialize=m19_initialize_bigquant_run,
handle_data=m19_handle_data_bigquant_run,
prepare=m19_prepare_bigquant_run,
volume_limit=0,
order_price_field_buy='close',
order_price_field_sell='close',
capital_base=500000,
auto_cancel_non_tradable_orders=False,
data_frequency='daily',
price_type='真实价格',
product_type='股票',
plot_charts=True,
backtest_only=False,
benchmark=''
)
日志 126 条,错误日志
0 条
[2020-09-22 11:03:10.359422] INFO: moduleinvoker: instruments.v2 开始运行..
[2020-09-22 11:03:10.373027] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:10.374073] INFO: moduleinvoker: instruments.v2 运行完成[0.014659s].
[2020-09-22 11:03:10.376580] INFO: moduleinvoker: advanced_auto_labeler.v2 开始运行..
[2020-09-22 11:03:13.388172] INFO: 自动标注(股票): 加载历史数据: 2201766 行
[2020-09-22 11:03:13.389353] INFO: 自动标注(股票): 开始标注 ..
[2020-09-22 11:03:19.045355] INFO: moduleinvoker: advanced_auto_labeler.v2 运行完成[8.668748s].
[2020-09-22 11:03:19.050083] INFO: moduleinvoker: input_features.v1 开始运行..
[2020-09-22 11:03:19.059398] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:19.061016] INFO: moduleinvoker: input_features.v1 运行完成[0.010919s].
[2020-09-22 11:03:19.069561] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2020-09-22 11:03:19.084064] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:19.085596] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[0.016026s].
[2020-09-22 11:03:19.092195] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2020-09-22 11:03:19.216406] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:19.218017] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[0.125805s].
[2020-09-22 11:03:19.223509] INFO: moduleinvoker: join.v3 开始运行..
[2020-09-22 11:03:21.061113] INFO: join: /y_2015, 行数=0/475482, 耗时=1.044848s
[2020-09-22 11:03:22.317044] INFO: join: /y_2016, 行数=637465/641546, 耗时=1.246204s
[2020-09-22 11:03:23.693112] INFO: join: /y_2017, 行数=738250/743233, 耗时=1.344114s
[2020-09-22 11:03:25.054782] INFO: join: /y_2018, 行数=792197/816987, 耗时=1.342399s
[2020-09-22 11:03:26.267541] INFO: join: 最终行数: 2167912
[2020-09-22 11:03:26.322548] INFO: moduleinvoker: join.v3 运行完成[7.099031s].
[2020-09-22 11:03:26.330649] INFO: moduleinvoker: filtet_st_stock.v7 开始运行..
[2020-09-22 11:03:34.295177] INFO: moduleinvoker: filtet_st_stock.v7 运行完成[7.964521s].
[2020-09-22 11:03:34.301238] INFO: moduleinvoker: dropnan.v2 开始运行..
[2020-09-22 11:03:36.259922] INFO: dropnan: /data, 2090488/2129459
[2020-09-22 11:03:36.628833] INFO: dropnan: 行数: 2090488/2129459
[2020-09-22 11:03:36.656316] INFO: moduleinvoker: dropnan.v2 运行完成[2.355049s].
[2020-09-22 11:03:36.659026] INFO: moduleinvoker: instruments.v2 开始运行..
[2020-09-22 11:03:36.667101] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:36.668704] INFO: moduleinvoker: instruments.v2 运行完成[0.009671s].
[2020-09-22 11:03:36.674901] INFO: moduleinvoker: general_feature_extractor.v7 开始运行..
[2020-09-22 11:03:36.680573] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:36.682234] INFO: moduleinvoker: general_feature_extractor.v7 运行完成[0.007335s].
[2020-09-22 11:03:36.684790] INFO: moduleinvoker: derived_feature_extractor.v3 开始运行..
[2020-09-22 11:03:36.690073] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:36.691325] INFO: moduleinvoker: derived_feature_extractor.v3 运行完成[0.006533s].
[2020-09-22 11:03:36.693874] INFO: moduleinvoker: filtet_st_stock.v7 开始运行..
[2020-09-22 11:03:36.699018] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:36.700452] INFO: moduleinvoker: filtet_st_stock.v7 运行完成[0.006566s].
[2020-09-22 11:03:36.702896] INFO: moduleinvoker: dropnan.v2 开始运行..
[2020-09-22 11:03:36.708033] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:36.709342] INFO: moduleinvoker: dropnan.v2 运行完成[0.006443s].
[2020-09-22 11:03:36.711860] INFO: moduleinvoker: advanced_auto_labeler.v2 开始运行..
[2020-09-22 11:03:36.716904] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:36.718237] INFO: moduleinvoker: advanced_auto_labeler.v2 运行完成[0.006376s].
[2020-09-22 11:03:36.720747] INFO: moduleinvoker: join.v3 开始运行..
[2020-09-22 11:03:36.727690] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:36.729257] INFO: moduleinvoker: join.v3 运行完成[0.008503s].
[2020-09-22 11:03:36.731630] INFO: moduleinvoker: dropnan.v2 开始运行..
[2020-09-22 11:03:36.736767] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:03:36.738292] INFO: moduleinvoker: dropnan.v2 运行完成[0.00665s].
[2020-09-22 11:03:36.745751] INFO: moduleinvoker: stock_ranker.v2 开始运行..
[2020-09-22 11:03:36.759638] INFO: moduleinvoker: stock_ranker_train.v6 开始运行..
[2020-09-22 11:03:38.013842] INFO: StockRanker: 特征预处理 ..
[2020-09-22 11:03:38.408860] INFO: StockRanker: prepare data: training ..
[2020-09-22 11:03:39.307545] INFO: StockRanker: sort ..
[2020-09-22 11:03:58.352850] INFO: StockRanker: prepare data: test ..
[2020-09-22 11:03:58.743885] INFO: StockRanker: sort ..
[2020-09-22 11:04:08.870135] INFO: StockRanker训练: 35405b3e 准备训练: 2090488 行数, test: 1451608 rows
[2020-09-22 11:04:08.871312] INFO: StockRanker训练: AI模型训练,将在2090488*2=418.10万数据上对模型训练进行10轮迭代训练。预计将需要2~3分钟。请耐心等待。
[2020-09-22 11:04:08.886958] INFO: StockRanker训练: 正在训练 ..
[2020-09-22 11:04:08.922061] INFO: StockRanker训练: 任务状态: Pending
[2020-09-22 11:06:09.226301] INFO: StockRanker训练: 任务状态: Running
[2020-09-22 11:06:29.480348] INFO: StockRanker训练: 00:00:20.3322386, finished iteration 1
[2020-09-22 11:06:49.549414] INFO: StockRanker训练: 00:00:38.1795135, finished iteration 2
[2020-09-22 11:07:09.616530] INFO: StockRanker训练: 00:00:54.5797436, finished iteration 3
[2020-09-22 11:07:19.648447] INFO: StockRanker训练: 00:01:10.7713604, finished iteration 4
[2020-09-22 11:07:39.711037] INFO: StockRanker训练: 00:01:28.3157926, finished iteration 5
[2020-09-22 11:07:59.784665] INFO: StockRanker训练: 00:01:46.9397708, finished iteration 6
[2020-09-22 11:08:19.871996] INFO: StockRanker训练: 00:02:05.4682186, finished iteration 7
[2020-09-22 11:08:39.942804] INFO: StockRanker训练: 00:02:24.4808169, finished iteration 8
[2020-09-22 11:08:50.006216] INFO: StockRanker训练: 00:02:43.7858161, finished iteration 9
[2020-09-22 11:09:10.072756] INFO: StockRanker训练: 00:03:02.6215030, finished iteration 10
[2020-09-22 11:09:20.114277] INFO: StockRanker训练: 任务状态: Succeeded
[2020-09-22 11:09:23.100941] INFO: moduleinvoker: stock_ranker_train.v6 运行完成[346.341292s].
[2020-09-22 11:09:23.103757] INFO: moduleinvoker: stock_ranker_predict.v5 开始运行..
[2020-09-22 11:09:25.141113] INFO: StockRanker预测: /data ..
[2020-09-22 11:09:31.244965] INFO: moduleinvoker: stock_ranker_predict.v5 运行完成[8.141185s].
[2020-09-22 11:09:31.292639] INFO: moduleinvoker: stock_ranker.v2 运行完成[354.546893s].
[2020-09-22 11:09:32.210476] INFO: moduleinvoker: backtest.v8 开始运行..
[2020-09-22 11:09:32.216164] INFO: backtest: biglearning backtest:V8.4.2
[2020-09-22 11:09:32.646627] INFO: backtest: product_type:stock by specified
[2020-09-22 11:09:32.739422] INFO: moduleinvoker: cached.v2 开始运行..
[2020-09-22 11:09:32.746009] INFO: moduleinvoker: 命中缓存
[2020-09-22 11:09:32.746957] INFO: moduleinvoker: cached.v2 运行完成[0.007536s].
[2020-09-22 11:09:34.111994] INFO: algo: TradingAlgorithm V1.6.9
[2020-09-22 11:09:35.561442] INFO: algo: trading transform...
[2020-09-22 11:09:44.432004] INFO: algo: handle_splits get splits [dt:2019-05-10 00:00:00+00:00] [asset:Equity(1365 [000062.SZA]), ratio:0.680497944355011]
[2020-09-22 11:09:44.433155] INFO: Position: position stock handle split[sid:1365, orig_amount:1900, new_amount:2792.0, orig_cost:19.829999923706055, new_cost:13.4943, ratio:0.680497944355011, last_sale_price:13.119999885559082]
[2020-09-22 11:09:44.433994] INFO: Position: after split: PositionStock(asset:Equity(1365 [000062.SZA]), amount:2792.0, cost_basis:13.4943, last_sale_price:19.279998779296875)
[2020-09-22 11:09:44.434732] INFO: Position: returning cash: 0.959
[2020-09-22 11:09:44.772719] INFO: algo: handle_splits get splits [dt:2019-05-16 00:00:00+00:00] [asset:Equity(1386 [000031.SZA]), ratio:0.9844632744789124]
[2020-09-22 11:09:45.228680] INFO: algo: handle_splits get splits [dt:2019-05-27 00:00:00+00:00] [asset:Equity(1348 [000411.SZA]), ratio:0.9896824955940247]
[2020-09-22 11:09:46.563116] INFO: algo: handle_splits get splits [dt:2019-06-18 00:00:00+00:00] [asset:Equity(1163 [000061.SZA]), ratio:0.9981651902198792]
[2020-09-22 11:09:46.564225] INFO: Position: position stock handle split[sid:1163, orig_amount:7000, new_amount:7012.0, orig_cost:5.37228559766497, new_cost:5.3624, ratio:0.9981651902198792, last_sale_price:5.440000057220459]
[2020-09-22 11:09:46.565066] INFO: Position: after split: PositionStock(asset:Equity(1163 [000061.SZA]), amount:7012.0, cost_basis:5.3624, last_sale_price:5.449999809265137)
[2020-09-22 11:09:46.565891] INFO: Position: returning cash: 4.718
[2020-09-22 11:09:46.836707] INFO: algo: handle_splits get splits [dt:2019-06-21 00:00:00+00:00] [asset:Equity(3226 [000963.SZA]), ratio:0.824142575263977]
[2020-09-22 11:09:47.624987] INFO: algo: handle_splits get splits [dt:2019-07-05 00:00:00+00:00] [asset:Equity(1305 [000046.SZA]), ratio:0.9742709994316101]
[2020-09-22 11:09:47.626140] INFO: Position: position stock handle split[sid:1305, orig_amount:6800, new_amount:6979.0, orig_cost:5.710000038146973, new_cost:5.5631, ratio:0.9742709994316101, last_sale_price:5.680000305175781]
[2020-09-22 11:09:47.627019] INFO: Position: after split: PositionStock(asset:Equity(1305 [000046.SZA]), amount:6979.0, cost_basis:5.5631, last_sale_price:5.830000400543213)
[2020-09-22 11:09:47.627757] INFO: Position: returning cash: 3.2805
[2020-09-22 11:10:06.959194] INFO: algo: handle_splits get splits [dt:2020-05-18 00:00:00+00:00] [asset:Equity(4160 [000011.SZA]), ratio:0.9606558084487915]
[2020-09-22 11:10:06.960311] INFO: Position: position stock handle split[sid:4160, orig_amount:4000, new_amount:4163.0, orig_cost:9.149999618530273, new_cost:8.79, ratio:0.9606558084487915, last_sale_price:8.789999961853027]
[2020-09-22 11:10:06.961148] INFO: Position: after split: PositionStock(asset:Equity(4160 [000011.SZA]), amount:4163.0, cost_basis:8.79, last_sale_price:9.149999618530273)
[2020-09-22 11:10:06.961912] INFO: Position: returning cash: 7.2273
[2020-09-22 11:10:08.275089] INFO: algo: handle_splits get splits [dt:2020-06-05 00:00:00+00:00] [asset:Equity(3803 [000099.SZA]), ratio:0.9927953481674194]
[2020-09-22 11:10:08.276209] INFO: Position: position stock handle split[sid:3803, orig_amount:5400, new_amount:5439.0, orig_cost:7.020000457763672, new_cost:6.9694, ratio:0.9927953481674194, last_sale_price:6.889999866485596]
[2020-09-22 11:10:08.277058] INFO: Position: after split: PositionStock(asset:Equity(3803 [000099.SZA]), amount:5439.0, cost_basis:6.9694, last_sale_price:6.940000057220459)
[2020-09-22 11:10:08.277785] INFO: Position: returning cash: 1.2915
[2020-09-22 11:10:09.097123] INFO: algo: handle_splits get splits [dt:2020-06-19 00:00:00+00:00] [asset:Equity(4042 [000565.SZA]), ratio:0.9978947043418884]
[2020-09-22 11:10:09.098236] INFO: Position: position stock handle split[sid:4042, orig_amount:7800, new_amount:7816.0, orig_cost:4.789999961853027, new_cost:4.7799, ratio:0.9978947043418884, last_sale_price:4.739999294281006]
[2020-09-22 11:10:09.099082] INFO: Position: after split: PositionStock(asset:Equity(4042 [000565.SZA]), amount:7816.0, cost_basis:4.7799, last_sale_price:4.749999523162842)
[2020-09-22 11:10:09.099808] INFO: Position: returning cash: 2.1612
[2020-09-22 11:10:09.891834] INFO: algo: handle_splits get splits [dt:2020-07-03 00:00:00+00:00] [asset:Equity(679 [000656.SZA]), ratio:0.9544533491134644]
[2020-09-22 11:10:11.214669] INFO: algo: handle_splits get splits [dt:2020-07-17 00:00:00+00:00] [asset:Equity(1386 [000031.SZA]), ratio:0.9708404541015625]
[2020-09-22 11:10:11.215859] INFO: Position: position stock handle split[sid:1386, orig_amount:6400, new_amount:6592.0, orig_cost:5.829999923706055, new_cost:5.66, ratio:0.9708404541015625, last_sale_price:5.659999847412109]
[2020-09-22 11:10:11.216739] INFO: Position: after split: PositionStock(asset:Equity(1386 [000031.SZA]), amount:6592.0, cost_basis:5.66, last_sale_price:5.829999923706055)
[2020-09-22 11:10:11.217506] INFO: Position: returning cash: 1.281
[2020-09-22 11:10:15.552595] INFO: Performance: Simulated 420 trading days out of 420.
[2020-09-22 11:10:15.553685] INFO: Performance: first open: 2019-01-02 09:30:00+00:00
[2020-09-22 11:10:15.554512] INFO: Performance: last close: 2020-09-21 15:00:00+00:00
[2020-09-22 11:10:22.020893] INFO: moduleinvoker: backtest.v8 运行完成[49.810427s].
[2020-09-22 11:10:22.022228] INFO: moduleinvoker: trade.v4 运行完成[50.726527s].
In [2]:
#m13.result.best_params_
In [3]:
#dt = m4.predictions.read_df()[-30000:]
#dt.to_csv('3.csv')