AI可视化模板的细化

策略分享
标签: #<Tag:0x00007f728c2363a0>

(达达) #1
克隆策略

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-29: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":"287d2cb0-f53c-4101-bdf8-104b137c8601-29:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-1004:input_2","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-70:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-1009:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-1199:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-29:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-81:options_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:predictions"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-70:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-81:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-70:data"},{"DestinationInputPortId":"-1009:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76:data"},{"DestinationInputPortId":"-354:training_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:data","SourceOutputPortId":"-86:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-60:model","SourceOutputPortId":"-354:model"},{"DestinationInputPortId":"-1199:features","SourceOutputPortId":"-606:data"},{"DestinationInputPortId":"-1004:input_1","SourceOutputPortId":"-606:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76:features","SourceOutputPortId":"-606:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35:input_data","SourceOutputPortId":"-1199:data"},{"DestinationInputPortId":"-354:features","SourceOutputPortId":"-1004:data_1"},{"DestinationInputPortId":"-86:input_data","SourceOutputPortId":"-1009:data"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2014-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2016-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":false,"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, -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,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nclose_0\nopen_0\nturn_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":false,"moduleIdForCode":3,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-29","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v6","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":"287d2cb0-f53c-4101-bdf8-104b137c8601-29"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-29"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-29","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-35","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v2","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-35","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"IsPartOfPartialRun":null,"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":6,"IsPartOfPartialRun":null,"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":7,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2016-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":8,"IsPartOfPartialRun":null,"Comment":"预测数据,用于回测和模拟","CommentCollapsed":false},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-70","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v6","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":"287d2cb0-f53c-4101-bdf8-104b137c8601-70"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-70"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-70","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":9,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-76","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v2","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"def dma(X,A):\n result=pd.DataFrame(np.zeros((len(X),X.columns.size)),index=list(X.index),columns=X.columns)\n result.iloc[0]=X.iloc[0]*A.iloc[0]\n for i in range(1,len(X)):\n result.iloc[i]=A.iloc[i]*X.iloc[i]+(1-A.iloc[i])*result.iloc[i-1] \n return result\ndef cal_cyc(df,N):\n hsl=pd.pivot_table(df,values='turn_0',index=['date'],columns=['instrument'])/100\n if N>0: \n AN=dma(N*hsl/(1+(N-1)*hsl),(1+(N-1)*hsl)/N)\n else:\n AN=hsl\n mclose=pd.pivot_table(df,values='close_0',index=['date'],columns=['instrument'])\n mopen=pd.pivot_table(df,values='open_0',index=['date'],columns=['instrument'])\n mid=(mclose+mopen)/2\n AN_1=AN.shift(1)\n AN_1.iloc[0]=0\n if N>0:\n CYCN=dma(mid*hsl/(AN-AN_1*(1-hsl)*4/5),1-(N-1)*AN_1*(1-hsl)/N/AN)\n else:\n CYCN=dma(mid*hsl/(AN-AN_1*(1-hsl)),1-AN_1*(1-hsl)/AN)\n cycn=CYCN.T.unstack().reset_index()\n cycn.columns=['date','instrument','cyc'+str(N)]\n df1=df.merge(cycn,on=['date','instrument']).copy()\n df1['close_0']=df1['cyc'+str(N)]\n return df1['close_0']\n# 按股票代码groupby计算个股超额收益率数据\ndef cyc(df,close_0,open_0,turn_0):\n return cal_cyc(df,5)\n\nbigquant_run = {\n 'cyc': cyc\n}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-76","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-81","ModuleId":"BigQuantSpace.trade.trade-v3","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\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 cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)\n positions = {e.symbol: p.amount * p.last_sale_price\n for e, p in context.perf_tracker.position_tracker.positions.items()}\n\n # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰\n if not is_staging and cash_for_sell > 0:\n equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}\n instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(\n lambda x: x in equities and not context.has_unfinished_sell_order(equities[x]))])))\n # print('rank order for sell %s' % instruments)\n for instrument in instruments:\n context.order_target(context.symbol(instrument), 0)\n cash_for_sell -= positions[instrument]\n if cash_for_sell <= 0:\n break\n\n # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票\n buy_cash_weights = context.stock_weights\n buy_instruments = list(ranker_prediction.instrument[: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","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass\n","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 = 5\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.2\n context.options['hold_days'] = 5\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"","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":1000000,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"000300.SHA","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":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"amount_integer","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-81"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-81"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-81","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":11,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"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":12,"IsPartOfPartialRun":null,"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":13,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-354","ModuleId":"BigQuantSpace.stock_ranker_train.stock_ranker_train-v5","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":"m_lazy_run","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-354"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-354"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"test_ds","NodeId":"-354"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"base_model","NodeId":"-354"}],"OutputPortsInternal":[{"Name":"model","NodeId":"-354","OutputType":null},{"Name":"feature_gains","NodeId":"-354","OutputType":null},{"Name":"m_lazy_run","NodeId":"-354","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":14,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-606","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\ncyc(close_0,open_0,turn_0)\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-606"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-606","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":15,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-1199","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v2","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"def dma(X,A):\n result=pd.DataFrame(np.zeros((len(X),X.columns.size)),index=list(X.index),columns=X.columns)\n result.iloc[0]=X.iloc[0]*A.iloc[0]\n for i in range(1,len(X)):\n result.iloc[i]=A.iloc[i]*X.iloc[i]+(1-A.iloc[i])*result.iloc[i-1] \n return result\ndef cal_cyc(df,N):\n hsl=pd.pivot_table(df,values='turn_0',index=['date'],columns=['instrument'])/100\n if N>0: \n AN=dma(N*hsl/(1+(N-1)*hsl),(1+(N-1)*hsl)/N)\n else:\n AN=hsl\n mclose=pd.pivot_table(df,values='close_0',index=['date'],columns=['instrument'])\n mopen=pd.pivot_table(df,values='open_0',index=['date'],columns=['instrument'])\n mid=(mclose+mopen)/2\n AN_1=AN.shift(1)\n AN_1.iloc[0]=0\n if N>0:\n CYCN=dma(mid*hsl/(AN-AN_1*(1-hsl)*4/5),1-(N-1)*AN_1*(1-hsl)/N/AN)\n else:\n CYCN=dma(mid*hsl/(AN-AN_1*(1-hsl)),1-AN_1*(1-hsl)/AN)\n cycn=CYCN.T.unstack().reset_index()\n cycn.columns=['date','instrument','cyc'+str(N)]\n df1=df.merge(cycn,on=['date','instrument']).copy()\n df1['close_0']=df1['cyc'+str(N)]\n return df1['close_0']\n# 按股票代码groupby计算个股超额收益率数据\ndef cyc(df,close_0,open_0,turn_0):\n return cal_cyc(df,5)\n\nbigquant_run = {\n 'cyc': cyc\n}\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-1199"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-1199"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1199","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-1004","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n # 示例代码如下。在这里编写您的代码\n df1=input_1.read_pickle()\n df2=input_2.read_pickle()\n df=df1+df2\n print(df)\n data_1 = DataSource.write_pickle(df)\n return Outputs(data_1=data_1, data_2=None, data_3=None)\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-1004"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-1004"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-1004"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-1004","OutputType":null},{"Name":"data_2","NodeId":"-1004","OutputType":null},{"Name":"data_3","NodeId":"-1004","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-1009","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v2","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-1009"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-1009"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-1009","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"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='75,-96,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='-129,124,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='580,-197,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-29' Position='165,52,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-35' Position='289,310,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='127,405,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-60' Position='674,653,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1049,-112,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-70' Position='947,67,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-76' Position='799,198,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-81' Position='926,744,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='240,502,200,200'/><NodePosition Node='-86' Position='809,456,200,200'/><NodePosition Node='-354' Position='378,568,200,200'/><NodePosition Node='-606' Position='554,57,200,200'/><NodePosition Node='-1199' Position='234,177,200,200'/><NodePosition Node='-1004' Position='598,315,200,200'/><NodePosition Node='-1009' Position='911,324,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 [10]:
    # 本代码由可视化策略环境自动生成 2018年4月13日 21:20
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m1 = M.instruments.v2(
        start_date='2014-01-01',
        end_date='2016-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0,
        m_cached=False
    )
    
    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="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    close_0
    open_0
    turn_0""",
        m_cached=False
    )
    
    m4 = M.general_feature_extractor.v6(
        instruments=m1.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0,
        m_cached=False
    )
    
    m8 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2016-01-01'),
        end_date=T.live_run_param('trading_date', '2017-01-01'),
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m9 = M.general_feature_extractor.v6(
        instruments=m8.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0,
        m_cached=False
    )
    
    m15 = M.input_features.v1(
        features="""
    # #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    cyc(close_0,open_0,turn_0)
    """,
        m_cached=False
    )
    
    def dma(X,A):
        result=pd.DataFrame(np.zeros((len(X),X.columns.size)),index=list(X.index),columns=X.columns)
        result.iloc[0]=X.iloc[0]*A.iloc[0]
        for i in range(1,len(X)):
            result.iloc[i]=A.iloc[i]*X.iloc[i]+(1-A.iloc[i])*result.iloc[i-1]        
        return result
    def cal_cyc(df,N):
        hsl=pd.pivot_table(df,values='turn_0',index=['date'],columns=['instrument'])/100
        if N>0:    
            AN=dma(N*hsl/(1+(N-1)*hsl),(1+(N-1)*hsl)/N)
        else:
            AN=hsl
        mclose=pd.pivot_table(df,values='close_0',index=['date'],columns=['instrument'])
        mopen=pd.pivot_table(df,values='open_0',index=['date'],columns=['instrument'])
        mid=(mclose+mopen)/2
        AN_1=AN.shift(1)
        AN_1.iloc[0]=0
        if N>0:
            CYCN=dma(mid*hsl/(AN-AN_1*(1-hsl)*4/5),1-(N-1)*AN_1*(1-hsl)/N/AN)
        else:
            CYCN=dma(mid*hsl/(AN-AN_1*(1-hsl)),1-AN_1*(1-hsl)/AN)
        cycn=CYCN.T.unstack().reset_index()
        cycn.columns=['date','instrument','cyc'+str(N)]
        df1=df.merge(cycn,on=['date','instrument']).copy()
        df1['close_0']=df1['cyc'+str(N)]
        return df1['close_0']
    # 按股票代码groupby计算个股超额收益率数据
    def cyc(df,close_0,open_0,turn_0):
        return cal_cyc(df,5)
    
    m16_user_functions_bigquant_run = {
        'cyc':  cyc
    }
    
    
    m16 = M.derived_feature_extractor.v2(
        input_data=m4.data,
        features=m15.data,
        date_col='date',
        instrument_col='instrument',
        user_functions=m16_user_functions_bigquant_run
    )
    
    m5 = M.derived_feature_extractor.v2(
        input_data=m16.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        user_functions={}
    )
    
    m6 = M.join.v3(
        data1=m2.data,
        data2=m5.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m12 = M.dropnan.v1(
        input_data=m6.data
    )
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m17_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        df1=input_1.read_pickle()
        df2=input_2.read_pickle()
        df=df1+df2
        print(df)
        data_1 = DataSource.write_pickle(df)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    m17 = M.cached.v3(
        input_1=m15.data,
        input_2=m3.data,
        run=m17_run_bigquant_run
    )
    
    m14 = M.stock_ranker_train.v5(
        training_ds=m12.data,
        features=m17.data_1,
        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,
        m_lazy_run=False
    )
    
    def dma(X,A):
        result=pd.DataFrame(np.zeros((len(X),X.columns.size)),index=list(X.index),columns=X.columns)
        result.iloc[0]=X.iloc[0]*A.iloc[0]
        for i in range(1,len(X)):
            result.iloc[i]=A.iloc[i]*X.iloc[i]+(1-A.iloc[i])*result.iloc[i-1]        
        return result
    def cal_cyc(df,N):
        hsl=pd.pivot_table(df,values='turn_0',index=['date'],columns=['instrument'])/100
        if N>0:    
            AN=dma(N*hsl/(1+(N-1)*hsl),(1+(N-1)*hsl)/N)
        else:
            AN=hsl
        mclose=pd.pivot_table(df,values='close_0',index=['date'],columns=['instrument'])
        mopen=pd.pivot_table(df,values='open_0',index=['date'],columns=['instrument'])
        mid=(mclose+mopen)/2
        AN_1=AN.shift(1)
        AN_1.iloc[0]=0
        if N>0:
            CYCN=dma(mid*hsl/(AN-AN_1*(1-hsl)*4/5),1-(N-1)*AN_1*(1-hsl)/N/AN)
        else:
            CYCN=dma(mid*hsl/(AN-AN_1*(1-hsl)),1-AN_1*(1-hsl)/AN)
        cycn=CYCN.T.unstack().reset_index()
        cycn.columns=['date','instrument','cyc'+str(N)]
        df1=df.merge(cycn,on=['date','instrument']).copy()
        df1['close_0']=df1['cyc'+str(N)]
        return df1['close_0']
    # 按股票代码groupby计算个股超额收益率数据
    def cyc(df,close_0,open_0,turn_0):
        return cal_cyc(df,5)
    
    m10_user_functions_bigquant_run = {
        'cyc':  cyc
    }
    m10 = M.derived_feature_extractor.v2(
        input_data=m9.data,
        features=m15.data,
        date_col='date',
        instrument_col='instrument',
        user_functions=m10_user_functions_bigquant_run
    )
    
    m18 = M.derived_feature_extractor.v2(
        input_data=m10.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        user_functions={}
    )
    
    m13 = M.dropnan.v1(
        input_data=m18.data
    )
    
    m7 = M.stock_ranker_predict.v5(
        model=m14.model,
        data=m13.data,
        m_lazy_run=False
    )
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m11_handle_data_bigquant_run(context, data):
        # 按日期过滤得到今日的预测数据
        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)
        cash_for_sell = cash_avg - (context.portfolio.cash - cash_for_buy)
        positions = {e.symbol: p.amount * p.last_sale_price
                     for e, p in context.perf_tracker.position_tracker.positions.items()}
    
        # 2. 生成卖出订单:hold_days天之后才开始卖出;对持仓的股票,按机器学习算法预测的排序末位淘汰
        if not is_staging and cash_for_sell > 0:
            equities = {e.symbol: e for e, p in context.perf_tracker.position_tracker.positions.items()}
            instruments = list(reversed(list(ranker_prediction.instrument[ranker_prediction.instrument.apply(
                    lambda x: x in equities and not context.has_unfinished_sell_order(equities[x]))])))
            # print('rank order for sell %s' % instruments)
            for instrument in instruments:
                context.order_target(context.symbol(instrument), 0)
                cash_for_sell -= positions[instrument]
                if cash_for_sell <= 0:
                    break
    
        # 3. 生成买入订单:按机器学习算法预测的排序,买入前面的stock_count只股票
        buy_cash_weights = context.stock_weights
        buy_instruments = list(ranker_prediction.instrument[: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 m11_prepare_bigquant_run(context):
        pass
    
    # 回测引擎:初始化函数,只执行一次
    def m11_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 = 5
        # 每只的股票的权重,如下的权重分配会使得靠前的股票分配多一点的资金,[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.2
        context.options['hold_days'] = 5
    
    m11 = M.trade.v3(
        instruments=m8.data,
        options_data=m7.predictions,
        start_date='',
        end_date='',
        handle_data=m11_handle_data_bigquant_run,
        prepare=m11_prepare_bigquant_run,
        initialize=m11_initialize_bigquant_run,
        volume_limit=0.025,
        order_price_field_buy='open',
        order_price_field_sell='close',
        capital_base=1000000,
        benchmark='000300.SHA',
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='真实价格',
        plot_charts=True,
        backtest_only=False,
        amount_integer=False
    )
    
    [2018-04-12 20:49:07.953714] INFO: bigquant: instruments.v2 开始运行..
    [2018-04-12 20:49:07.989334] INFO: bigquant: instruments.v2 运行完成[0.035604s].
    [2018-04-12 20:49:08.009076] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
    [2018-04-12 20:49:25.825677] INFO: 自动数据标注: 加载历史数据: 1139646 行
    [2018-04-12 20:49:25.828011] INFO: 自动数据标注: 开始标注 ..
    [2018-04-12 20:49:29.881960] INFO: bigquant: advanced_auto_labeler.v2 运行完成[21.872863s].
    [2018-04-12 20:49:29.906899] INFO: bigquant: input_features.v1 开始运行..
    [2018-04-12 20:49:29.918624] INFO: bigquant: input_features.v1 运行完成[0.011725s].
    [2018-04-12 20:49:29.947292] INFO: bigquant: general_feature_extractor.v6 开始运行..
    [2018-04-12 20:49:56.484131] INFO: 基础特征抽取: 年份 2014, 特征行数=569948
    [2018-04-12 20:49:58.536735] INFO: 基础特征抽取: 年份 2015, 特征行数=569698
    [2018-04-12 20:50:21.251885] INFO: 基础特征抽取: 年份 2016, 特征行数=0
    [2018-04-12 20:50:21.313158] INFO: 基础特征抽取: 总行数: 1139646
    [2018-04-12 20:50:21.319280] INFO: bigquant: general_feature_extractor.v6 运行完成[51.371986s].
    [2018-04-12 20:50:21.329312] INFO: bigquant: instruments.v2 开始运行..
    [2018-04-12 20:50:21.345034] INFO: bigquant: 命中缓存
    [2018-04-12 20:50:21.349291] INFO: bigquant: instruments.v2 运行完成[0.019995s].
    [2018-04-12 20:50:21.376950] INFO: bigquant: general_feature_extractor.v6 开始运行..
    [2018-04-12 20:50:23.053482] INFO: 基础特征抽取: 年份 2016, 特征行数=641546
    [2018-04-12 20:50:24.503376] INFO: 基础特征抽取: 年份 2017, 特征行数=0
    [2018-04-12 20:50:24.523157] INFO: 基础特征抽取: 总行数: 641546
    [2018-04-12 20:50:24.529078] INFO: bigquant: general_feature_extractor.v6 运行完成[3.152097s].
    [2018-04-12 20:50:24.540849] INFO: bigquant: input_features.v1 开始运行..
    [2018-04-12 20:50:24.557163] INFO: bigquant: input_features.v1 运行完成[0.016299s].
    [2018-04-12 20:50:24.578076] INFO: bigquant: derived_feature_extractor.v2 开始运行..
    [2018-04-12 20:50:36.544079] INFO: derived_feature_extractor: 提取完成 cyc(close_0,open_0,turn_0), 11.193s
    [2018-04-12 20:50:36.912839] INFO: derived_feature_extractor: /y_2014, 569948
    [2018-04-12 20:50:37.760230] INFO: derived_feature_extractor: /y_2015, 569698
    [2018-04-12 20:50:38.332797] INFO: bigquant: derived_feature_extractor.v2 运行完成[13.754727s].
    [2018-04-12 20:50:38.353888] INFO: bigquant: derived_feature_extractor.v2 开始运行..
    [2018-04-12 20:50:39.377893] INFO: derived_feature_extractor: /y_2014, 569948
    [2018-04-12 20:50:40.069920] INFO: derived_feature_extractor: /y_2015, 569698
    [2018-04-12 20:50:41.067688] INFO: bigquant: derived_feature_extractor.v2 运行完成[2.713753s].
    [2018-04-12 20:50:41.087496] INFO: bigquant: join.v3 开始运行..
    [2018-04-12 20:50:43.872655] INFO: join: /y_2014, 行数=567866/569948, 耗时=1.970536s
    [2018-04-12 20:50:45.741040] INFO: join: /y_2015, 行数=546721/569698, 耗时=1.813615s
    [2018-04-12 20:50:46.204652] INFO: join: 最终行数: 1114587
    [2018-04-12 20:50:46.212554] INFO: bigquant: join.v3 运行完成[5.125032s].
    [2018-04-12 20:50:46.240826] INFO: bigquant: dropnan.v1 开始运行..
    [2018-04-12 20:50:47.414898] INFO: dropnan: /y_2014, 397213/567866
    [2018-04-12 20:50:48.045079] INFO: dropnan: /y_2015, 149538/546721
    [2018-04-12 20:50:48.072210] INFO: dropnan: 行数: 546751/1114587
    [2018-04-12 20:50:48.108157] INFO: bigquant: dropnan.v1 运行完成[1.867319s].
    [2018-04-12 20:50:48.270206] INFO: bigquant: cached.v3 开始运行..
    ['cyc(close_0,open_0,turn_0)', 'close_0', 'open_0', 'turn_0']
    [2018-04-12 20:50:48.385666] INFO: bigquant: cached.v3 运行完成[0.115449s].
    [2018-04-12 20:50:48.404484] INFO: bigquant: stock_ranker_train.v5 开始运行..
    [2018-04-12 20:50:49.030274] INFO: df2bin: prepare bins ..
    [2018-04-12 20:50:49.651986] INFO: df2bin: prepare data: training ..
    [2018-04-12 20:50:49.978873] INFO: df2bin: sort ..
    [2018-04-12 20:51:00.643856] INFO: stock_ranker_train: 1fa68d7a 准备训练: 546751 行数
    [2018-04-12 20:51:53.185365] INFO: bigquant: stock_ranker_train.v5 运行完成[64.780863s].
    [2018-04-12 20:51:53.214697] INFO: bigquant: derived_feature_extractor.v2 开始运行..
    [2018-04-12 20:51:59.802942] INFO: derived_feature_extractor: 提取完成 cyc(close_0,open_0,turn_0), 6.152s
    [2018-04-12 20:52:00.059530] INFO: derived_feature_extractor: /y_2016, 641546
    [2018-04-12 20:52:00.570004] INFO: bigquant: derived_feature_extractor.v2 运行完成[7.35531s].
    [2018-04-12 20:52:00.611938] INFO: bigquant: derived_feature_extractor.v2 开始运行..
    [2018-04-12 20:52:01.292288] INFO: derived_feature_extractor: /y_2016, 641546
    [2018-04-12 20:52:01.857077] INFO: bigquant: derived_feature_extractor.v2 运行完成[1.245113s].
    [2018-04-12 20:52:01.875119] INFO: bigquant: dropnan.v1 开始运行..
    [2018-04-12 20:52:02.945377] INFO: dropnan: /y_2016, 434223/641546
    [2018-04-12 20:52:02.972832] INFO: dropnan: 行数: 434223/641546
    [2018-04-12 20:52:03.023616] INFO: bigquant: dropnan.v1 运行完成[1.148475s].
    [2018-04-12 20:52:03.043352] INFO: bigquant: stock_ranker_predict.v5 开始运行..
    [2018-04-12 20:52:03.609712] INFO: df2bin: prepare data: prediction ..
    [2018-04-12 20:52:13.276952] INFO: stock_ranker_predict: 准备预测: 434223 行
    [2018-04-12 20:52:18.052535] INFO: bigquant: stock_ranker_predict.v5 运行完成[15.009127s].
    [2018-04-12 20:52:18.178473] INFO: bigquant: backtest.v7 开始运行..
    [2018-04-12 20:52:18.611469] INFO: algo: set price type:original
    [2018-04-12 20:53:07.418839] INFO: algo: get splits [2016-05-16 00:00:00+00:00] [asset:Equity(1191 [000521.SZA]), ratio:0.9894736597276048]
    [2018-04-12 20:53:07.420901] INFO: Position: position handle split[sid:1191, orig_amount:5600, new_amount:5659.0, orig_cost:5.851755015109159,new_cost:5.79, ratio:0.9894736597276048, last_sale_price:5.639999671720224]
    [2018-04-12 20:53:07.422147] INFO: Position: after split: asset: Equity(1191 [000521.SZA]), amount: 5659.0, cost_basis: 5.79, last_sale_price: 5.699999809265137
    [2018-04-12 20:53:07.423333] INFO: Position: returning cash: 3.24
    [2018-04-12 20:53:07.618135] INFO: algo: get splits [2016-05-20 00:00:00+00:00] [asset:Equity(456 [600273.SHA]), ratio:0.9817742294602245]
    [2018-04-12 20:53:07.624547] INFO: Position: position handle split[sid:456, orig_amount:3200, new_amount:3259.0, orig_cost:8.192456628898066,new_cost:8.04, ratio:0.9817742294602245, last_sale_price:8.08000145903707]
    [2018-04-12 20:53:07.626572] INFO: Position: after split: asset: Equity(456 [600273.SHA]), amount: 3259.0, cost_basis: 8.04, last_sale_price: 8.229999542236328
    [2018-04-12 20:53:07.631601] INFO: Position: returning cash: 3.27
    [2018-04-12 20:53:07.785861] INFO: algo: get splits [2016-05-24 00:00:00+00:00] [asset:Equity(2177 [002752.SZA]), ratio:0.6638655701596802]
    [2018-04-12 20:53:07.788689] INFO: Position: position handle split[sid:2177, orig_amount:2800, new_amount:4217.0, orig_cost:24.647392876760655,new_cost:16.36, ratio:0.6638655701596802, last_sale_price:16.590000598290406]
    [2018-04-12 20:53:07.795412] INFO: Position: after split: asset: Equity(2177 [002752.SZA]), amount: 4217.0, cost_basis: 16.36, last_sale_price: 24.99
    [2018-04-12 20:53:07.797475] INFO: Position: returning cash: 11.97
    [2018-04-12 20:53:08.163680] INFO: algo: get splits [2016-05-27 00:00:00+00:00] [asset:Equity(1469 [300421.SZA]), ratio:0.9871792033778699]
    [2018-04-12 20:53:08.172230] INFO: Position: position handle split[sid:1469, orig_amount:5100, new_amount:5166.0, orig_cost:28.436965588257014,new_cost:28.07, ratio:0.9871792033778699, last_sale_price:26.94999225221585]
    [2018-04-12 20:53:08.175986] INFO: Position: after split: asset: Equity(1469 [300421.SZA]), amount: 5166.0, cost_basis: 28.07, last_sale_price: 27.3
    [2018-04-12 20:53:08.178562] INFO: Position: returning cash: 6.34
    [2018-04-12 20:53:08.349422] INFO: algo: get splits [2016-05-31 00:00:00+00:00] [asset:Equity(387 [002705.SZA]), ratio:0.7576515545312362]
    [2018-04-12 20:53:08.351661] INFO: algo: get splits [2016-05-31 00:00:00+00:00] [asset:Equity(1302 [603555.SHA]), ratio:0.9820074030483669]
    [2018-04-12 20:53:08.353605] INFO: Position: position handle split[sid:1302, orig_amount:1900, new_amount:1934.0, orig_cost:24.507351026214632,new_cost:24.07, ratio:0.9820074030483669, last_sale_price:24.560005150239657]
    [2018-04-12 20:53:08.355071] INFO: Position: after split: asset: Equity(1302 [603555.SHA]), amount: 1934.0, cost_basis: 24.07, last_sale_price: 25.01
    [2018-04-12 20:53:08.356653] INFO: Position: returning cash: 19.95
    [2018-04-12 20:53:08.933389] INFO: algo: get splits [2016-06-13 00:00:00+00:00] [asset:Equity(1431 [002189.SZA]), ratio:0.9992935223224572]
    [2018-04-12 20:53:08.940932] INFO: Position: position handle split[sid:1431, orig_amount:1800, new_amount:1801.0, orig_cost:28.708610962183766,new_cost:28.69, ratio:0.9992935223224572, last_sale_price:28.280005919325085]
    [2018-04-12 20:53:08.943080] INFO: Position: after split: asset: Equity(1431 [002189.SZA]), amount: 1801.0, cost_basis: 28.69, last_sale_price: 28.299999237060547
    [2018-04-12 20:53:08.951140] INFO: Position: returning cash: 7.71
    [2018-04-12 20:53:09.498052] INFO: algo: get splits [2016-06-21 00:00:00+00:00] [asset:Equity(251 [603222.SHA]), ratio:0.49879269733631143]
    [2018-04-12 20:53:09.506502] INFO: Position: position handle split[sid:251, orig_amount:6600, new_amount:13231.0, orig_cost:28.938682766160483,new_cost:14.43, ratio:0.49879269733631143, last_sale_price:14.46000018161508]
    [2018-04-12 20:53:09.511288] INFO: Position: after split: asset: Equity(251 [603222.SHA]), amount: 13231.0, cost_basis: 14.43, last_sale_price: 28.989999771118164
    [2018-04-12 20:53:09.513302] INFO: Position: returning cash: 13.74
    [2018-04-12 20:53:09.770084] INFO: algo: get splits [2016-06-23 00:00:00+00:00] [asset:Equity(1396 [000851.SZA]), ratio:0.998359185488799]
    [2018-04-12 20:53:09.777379] INFO: Position: position handle split[sid:1396, orig_amount:2900, new_amount:2904.0, orig_cost:12.103630038322203,new_cost:12.08, ratio:0.998359185488799, last_sale_price:12.169998471108459]
    [2018-04-12 20:53:09.795949] INFO: Position: after split: asset: Equity(1396 [000851.SZA]), amount: 2904.0, cost_basis: 12.08, last_sale_price: 12.19
    [2018-04-12 20:53:09.802216] INFO: Position: returning cash: 9.32
    [2018-04-12 20:53:09.921066] INFO: algo: get splits [2016-06-24 00:00:00+00:00] [asset:Equity(2270 [601789.SHA]), ratio:0.49453540851178746]
    [2018-04-12 20:53:10.045480] INFO: algo: get splits [2016-06-27 00:00:00+00:00] [asset:Equity(3024 [601890.SHA]), ratio:0.9930714167844676]
    [2018-04-12 20:53:10.434824] INFO: algo: get splits [2016-07-01 00:00:00+00:00] [asset:Equity(1383 [000404.SZA]), ratio:0.991683773268475]
    [2018-04-12 20:53:10.440256] INFO: Position: position handle split[sid:1383, orig_amount:4300, new_amount:4336.0, orig_cost:8.202460178667906,new_cost:8.13, ratio:0.991683773268475, last_sale_price:9.53999789884273]
    [2018-04-12 20:53:10.447637] INFO: Position: after split: asset: Equity(1383 [000404.SZA]), amount: 4336.0, cost_basis: 8.13, last_sale_price: 9.62
    [2018-04-12 20:53:10.452700] INFO: Position: returning cash: 0.57
    [2018-04-12 20:53:10.756575] INFO: algo: get splits [2016-07-06 00:00:00+00:00] [asset:Equity(2686 [601599.SHA]), ratio:0.4978051823801034]
    [2018-04-12 20:53:11.449338] INFO: algo: get splits [2016-07-18 00:00:00+00:00] [asset:Equity(2688 [603997.SHA]), ratio:0.993596069919467]
    [2018-04-12 20:53:11.456112] INFO: algo: get splits [2016-07-18 00:00:00+00:00] [asset:Equity(438 [603979.SHA]), ratio:0.830501306053785]
    [2018-04-12 20:53:11.461474] INFO: Position: position handle split[sid:438, orig_amount:1500, new_amount:1806.0, orig_cost:24.947482922721182,new_cost:20.72, ratio:0.830501306053785, last_sale_price:20.529991715389574]
    [2018-04-12 20:53:11.466822] INFO: Position: after split: asset: Equity(438 [603979.SHA]), amount: 1806.0, cost_basis: 20.72, last_sale_price: 24.719999313354492
    [2018-04-12 20:53:11.473215] INFO: Position: returning cash: 2.83
    [2018-04-12 20:53:26.378194] INFO: Performance: Simulated 244 trading days out of 244.
    [2018-04-12 20:53:26.381401] INFO: Performance: first open: 2016-01-04 01:30:00+00:00
    [2018-04-12 20:53:26.387949] INFO: Performance: last close: 2016-12-30 07:00:00+00:00
    
    • 收益率3.48%
    • 年化收益率3.6%
    • 基准收益率-11.28%
    • 阿尔法0.17
    • 贝塔1.13
    • 夏普比率0.01
    • 胜率0.538
    • 盈亏比0.772
    • 收益波动率31.45%
    • 信息比率0.8
    • 最大回撤25.17%
    [2018-04-12 20:53:30.597165] INFO: bigquant: backtest.v7 运行完成[72.418671s].
    

    在AI策略中对股票特征做过滤,以过滤ST股票为例