策略-修改了调仓天数为每天-每天选5支

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

(wcf) #1
克隆策略

策略简介

因子:样例因子(18个)

标注:未来5日涨幅分类,涨幅靠前的为1,涨幅靠后的为0

算法:决策树算法

类型:分类问题

训练集:10-15年

测试集:15-19年

选股依据:根据上涨概率值排序买入

持股数:30

持仓天数:5

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-787:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15: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":"-787:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-794:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-803:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-810:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-8155:input_2","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-8144:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-131:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"-803:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-144:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-8155:input_1","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:data"},{"DestinationInputPortId":"-8155:input_3","SourceOutputPortId":"-86:data"},{"DestinationInputPortId":"-794:input_data","SourceOutputPortId":"-787:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"-794:data"},{"DestinationInputPortId":"-810:input_data","SourceOutputPortId":"-803:data"},{"DestinationInputPortId":"-86:input_data","SourceOutputPortId":"-810:data"},{"DestinationInputPortId":"-8144:train_ds","SourceOutputPortId":"-8155:data_1"},{"DestinationInputPortId":"-8144:test_ds","SourceOutputPortId":"-8155:data_2"},{"DestinationInputPortId":"-131:training_ds","SourceOutputPortId":"-8144:train_data"},{"DestinationInputPortId":"-131:predict_ds","SourceOutputPortId":"-8144:test_data"},{"DestinationInputPortId":"-144:options_data","SourceOutputPortId":"-131:predictions"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2017-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":"shift(close, -5) / shift(open, -1)-1\nrank(label)\nwhere(label>=0.75,1,where(label<=0.25, 0, NaN))","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":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"cast_label_int","Value":"False","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":"(close_0-mean(close_0,12))/mean(close_0,12)*100\nrank(std(amount_0,15))\nrank_avg_amount_0/rank_avg_amount_8\nts_argmin(low_0,20)\nrank_return_30\n(low_1-close_0)/close_0\nta_bbands_lowerband_14_0\nmean(mf_net_pct_s_0,4)\namount_0/avg_amount_3\nreturn_0/return_5\nreturn_1/return_5\nrank_avg_amount_7/rank_avg_amount_10\nta_sma_10_0/close_0\nsqrt(high_0*low_0)-amount_0/volume_0*adjust_factor_0\navg_turn_15/(turn_0+1e-5)\nreturn_10\nmf_net_pct_s_0\n(close_0-open_0)/close_1\n ","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"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":7,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2019-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2020-02-26","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"IsPartOfPartialRun":null,"Comment":"预测数据,用于回测和模拟","CommentCollapsed":false},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":13,"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":14,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-787","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-787"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-787"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-787","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-794","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":"-794"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-794"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-794","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-803","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":"50","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-803"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-803"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-803","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-810","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":"-810"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-810"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-810","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-8155","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 train_df = input_1.read()\n features = input_2.read()\n feature_min = train_df[features].quantile(0.005)\n feature_max = train_df[features].quantile(0.995)\n train_df[features] = train_df[features].clip(feature_min,feature_max,axis=1)\n data_1 = DataSource.write_df(train_df)\n test_df = input_3.read()\n test_df[features] = test_df[features].clip(feature_min,feature_max,axis=1)\n data_2 = DataSource.write_df(test_df)\n return Outputs(data_1=data_1, data_2=data_2, data_3=None)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"input_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"params","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-8155"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-8155"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-8155"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-8155","OutputType":null},{"Name":"data_2","NodeId":"-8155","OutputType":null},{"Name":"data_3","NodeId":"-8155","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-8144","ModuleId":"BigQuantSpace.RobustScaler.RobustScaler-v13","ModuleParameters":[{"Name":"scale_type","Value":"standard","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"quantile_range_min","Value":"0.01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"quantile_range_max","Value":"0.99","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"global_scale","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"train_ds","NodeId":"-8144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-8144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"test_ds","NodeId":"-8144"}],"OutputPortsInternal":[{"Name":"train_data","NodeId":"-8144","OutputType":null},{"Name":"test_data","NodeId":"-8144","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-131","ModuleId":"BigQuantSpace.decision_tree_classifier.decision_tree_classifier-v1","ModuleParameters":[{"Name":"criterion","Value":"gini","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_depth","Value":30,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"min_samples_per_leaf","Value":200,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"key_cols","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"other_train_parameters","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-131"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-131"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"model","NodeId":"-131"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"predict_ds","NodeId":"-131"}],"OutputPortsInternal":[{"Name":"output_model","NodeId":"-131","OutputType":null},{"Name":"predictions","NodeId":"-131","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-144","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 \n context.indicator_data = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n context.rebalance_days = 1\n context.stock_num = 5\n if 'index' not in context.extension:\n context.extension['index'] = 0\n \n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n \n context.extension['index'] += 1\n # 不在换仓日就return,相当于后面的代码只会一个月运行一次,买入的股票会持有1个月\n if context.extension['index'] % context.rebalance_days != 0:\n return \n \n # 当前的日期\n date = data.current_dt.strftime('%Y-%m-%d')\n \n cur_data = context.indicator_data[context.indicator_data['date'] == date]\n # 根据日期获取调仓需要买入的股票的列表\n #stock_to_buy = list(cur_data.instrument[:context.stock_num])\n cur_data = cur_data[cur_data['pred_label'] == 1.0]\n \n stock_to_buy = list(cur_data.sort_values('classes_prob_1.0',ascending=False).instrument)[:context.stock_num]\n if date == '2017-02-06':\n print(date, len(stock_to_buy), stock_to_buy)\n # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表\n stock_hold_now = [equity.symbol for equity in context.portfolio.positions]\n # 继续持有的股票:调仓时,如果买入的股票已经存在于目前的持仓里,那么应继续持有\n no_need_to_sell = [i for i in stock_hold_now if i in stock_to_buy]\n # 需要卖出的股票\n stock_to_sell = [i for i in stock_hold_now if i not in no_need_to_sell]\n \n # 卖出\n for stock in stock_to_sell:\n # 如果该股票停牌,则没法成交。因此需要用can_trade方法检查下该股票的状态\n # 如果返回真值,则可以正常下单,否则会出错\n # 因为stock是字符串格式,我们用symbol方法将其转化成平台可以接受的形式:Equity格式\n\n if data.can_trade(context.symbol(stock)):\n # order_target_percent是平台的一个下单接口,表明下单使得该股票的权重为0,\n # 即卖出全部股票,可参考回测文档\n context.order_target_percent(context.symbol(stock), 0)\n \n # 如果当天没有买入的股票,就返回\n if len(stock_to_buy) == 0:\n return\n\n # 等权重买入 \n weight = 1 / len(stock_to_buy)\n \n # 买入\n for stock in stock_to_buy:\n if data.can_trade(context.symbol(stock)):\n # 下单使得某只股票的持仓权重达到weight,因为\n # weight大于0,因此是等权重买入\n context.order_target_percent(context.symbol(stock), weight)\n ","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"# 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。\ndef bigquant_run(context, data):\n pass\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"volume_limit","Value":"0","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":"100000","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"daily","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"price_type","Value":"真实价格","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"product_type","Value":"股票","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-144"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-144","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":11,"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='61,2,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='-66,122,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='656,-21,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='151,308,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1077,122,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='149,395,200,200'/><NodePosition Node='-86' Position='1078,418,200,200'/><NodePosition Node='-787' Position='301,127,200,200'/><NodePosition Node='-794' Position='304,212,200,200'/><NodePosition Node='-803' Position='1078,236,200,200'/><NodePosition Node='-810' Position='1081,327,200,200'/><NodePosition Node='-8155' Position='525,513,200,200'/><NodePosition Node='-8144' Position='538,594,200,200'/><NodePosition Node='-131' Position='533,675,200,200'/><NodePosition Node='-144' Position='422,770,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年3月5日 09:32
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m6_run_bigquant_run(input_1, input_2, input_3):
        train_df = input_1.read()
        features = input_2.read()
        feature_min = train_df[features].quantile(0.005)
        feature_max = train_df[features].quantile(0.995)
        train_df[features] = train_df[features].clip(feature_min,feature_max,axis=1)
        data_1 = DataSource.write_df(train_df)
        test_df = input_3.read()
        test_df[features] = test_df[features].clip(feature_min,feature_max,axis=1)
        data_2 = DataSource.write_df(test_df)
        return Outputs(data_1=data_1, data_2=data_2, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m6_post_run_bigquant_run(outputs):
        return outputs
    
    # 回测引擎:初始化函数,只执行一次
    def m11_initialize_bigquant_run(context):
        # 加载预测数据
      
        context.indicator_data = context.options['data'].read_df()
    
        # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
        context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
        context.rebalance_days = 1
        context.stock_num = 5
        if 'index' not in context.extension:
            context.extension['index'] = 0
         
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m11_handle_data_bigquant_run(context, data):
        
        context.extension['index'] += 1
        # 不在换仓日就return,相当于后面的代码只会一个月运行一次,买入的股票会持有1个月
        if  context.extension['index'] % context.rebalance_days != 0:
            return 
        
        # 当前的日期
        date = data.current_dt.strftime('%Y-%m-%d')
        
        cur_data = context.indicator_data[context.indicator_data['date'] == date]
        # 根据日期获取调仓需要买入的股票的列表
        #stock_to_buy = list(cur_data.instrument[:context.stock_num])
        cur_data = cur_data[cur_data['pred_label'] == 1.0]
        
        stock_to_buy =  list(cur_data.sort_values('classes_prob_1.0',ascending=False).instrument)[:context.stock_num]
        if date == '2017-02-06':
            print(date, len(stock_to_buy), stock_to_buy)
        # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表
        stock_hold_now = [equity.symbol for equity in context.portfolio.positions]
        # 继续持有的股票:调仓时,如果买入的股票已经存在于目前的持仓里,那么应继续持有
        no_need_to_sell = [i for i in stock_hold_now if i in stock_to_buy]
        # 需要卖出的股票
        stock_to_sell = [i for i in stock_hold_now if i not in no_need_to_sell]
      
        # 卖出
        for stock in stock_to_sell:
            # 如果该股票停牌,则没法成交。因此需要用can_trade方法检查下该股票的状态
            # 如果返回真值,则可以正常下单,否则会出错
            # 因为stock是字符串格式,我们用symbol方法将其转化成平台可以接受的形式:Equity格式
    
            if data.can_trade(context.symbol(stock)):
                # order_target_percent是平台的一个下单接口,表明下单使得该股票的权重为0,
                #   即卖出全部股票,可参考回测文档
                context.order_target_percent(context.symbol(stock), 0)
        
        # 如果当天没有买入的股票,就返回
        if len(stock_to_buy) == 0:
            return
    
        # 等权重买入 
        weight =  1 / len(stock_to_buy)
        
        # 买入
        for stock in stock_to_buy:
            if data.can_trade(context.symbol(stock)):
                # 下单使得某只股票的持仓权重达到weight,因为
                # weight大于0,因此是等权重买入
                context.order_target_percent(context.symbol(stock), weight)
     
    # 回测引擎:准备数据,只执行一次
    def m11_prepare_bigquant_run(context):
        pass
    
    # 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。
    def m11_before_trading_start_bigquant_run(context, data):
        pass
    
    
    m1 = M.instruments.v2(
        start_date='2017-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="""shift(close, -5) / shift(open, -1)-1
    rank(label)
    where(label>=0.75,1,where(label<=0.25, 0, NaN))""",
        start_date='',
        end_date='',
        benchmark='000300.SHA',
        drop_na_label=False,
        cast_label_int=False
    )
    
    m3 = M.input_features.v1(
        features="""(close_0-mean(close_0,12))/mean(close_0,12)*100
    rank(std(amount_0,15))
    rank_avg_amount_0/rank_avg_amount_8
    ts_argmin(low_0,20)
    rank_return_30
    (low_1-close_0)/close_0
    ta_bbands_lowerband_14_0
    mean(mf_net_pct_s_0,4)
    amount_0/avg_amount_3
    return_0/return_5
    return_1/return_5
    rank_avg_amount_7/rank_avg_amount_10
    ta_sma_10_0/close_0
    sqrt(high_0*low_0)-amount_0/volume_0*adjust_factor_0
    avg_turn_15/(turn_0+1e-5)
    return_10
    mf_net_pct_s_0
    (close_0-open_0)/close_1
     """
    )
    
    m15 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m16 = M.derived_feature_extractor.v3(
        input_data=m15.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    m7 = M.join.v3(
        data1=m2.data,
        data2=m16.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m13 = M.dropnan.v1(
        input_data=m7.data
    )
    
    m9 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2019-01-01'),
        end_date=T.live_run_param('trading_date', '2020-02-26'),
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m17 = M.general_feature_extractor.v7(
        instruments=m9.data,
        features=m3.data,
        start_date='',
        end_date='',
        before_start_days=50
    )
    
    m18 = M.derived_feature_extractor.v3(
        input_data=m17.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    m14 = M.dropnan.v1(
        input_data=m18.data
    )
    
    m6 = M.cached.v3(
        input_1=m13.data,
        input_2=m3.data,
        input_3=m14.data,
        run=m6_run_bigquant_run,
        post_run=m6_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m8 = M.RobustScaler.v13(
        train_ds=m6.data_1,
        features=m3.data,
        test_ds=m6.data_2,
        scale_type='standard',
        quantile_range_min=0.01,
        quantile_range_max=0.99,
        global_scale=True
    )
    
    m10 = M.decision_tree_classifier.v1(
        training_ds=m8.train_data,
        features=m3.data,
        predict_ds=m8.test_data,
        criterion='gini',
        feature_fraction=1,
        max_depth=30,
        min_samples_per_leaf=200,
        key_cols='date,instrument',
        other_train_parameters={}
    )
    
    m11 = M.trade.v4(
        instruments=m9.data,
        options_data=m10.predictions,
        start_date='',
        end_date='',
        initialize=m11_initialize_bigquant_run,
        handle_data=m11_handle_data_bigquant_run,
        prepare=m11_prepare_bigquant_run,
        before_trading_start=m11_before_trading_start_bigquant_run,
        volume_limit=0,
        order_price_field_buy='open',
        order_price_field_sell='close',
        capital_base=100000,
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='真实价格',
        product_type='股票',
        plot_charts=True,
        backtest_only=False,
        benchmark=''
    )
    
    • 收益率152.93%
    • 年化收益率131.9%
    • 基准收益率35.29%
    • 阿尔法0.53
    • 贝塔1.4
    • 夏普比率2.07
    • 胜率0.54
    • 盈亏比1.16
    • 收益波动率43.92%
    • 信息比率0.12
    • 最大回撤35.09%
    bigcharts-data-start/{"__type":"tabs","__id":"bigchart-f4114386ce41486ab1d2c28d8ee1168b"}/bigcharts-data-end

    (ghslas) #2

    你好,改成一天一股要改那个地方


    (wcf) #3

    不好意思哈,没看到。

    context.rebalance_days = 1
    context.stock_num = 5
    

    这两行代码是设置调仓天数为1天,每天选择排名靠前的5只股票买入


    (yangziriver) #4

    请教一下,我将交易改为调仓天数为5天,每天买入靠前的30只股票后,回测很正常,可是模拟交易就不出信号,没有股票推荐,请帮忙看一下。不只是调为5天不行,调为2、3、4天都不行,只能是1天。感觉调仓天数为1天时波动太大了。谢谢先!


    (yangziriver) #5
    克隆策略

    策略简介

    因子:样例因子(18个)

    标注:未来5日涨幅分类,涨幅靠前的为1,涨幅靠后的为0

    算法:决策树算法

    类型:分类问题

    训练集:10-15年

    测试集:15-19年

    选股依据:根据上涨概率值排序买入

    持股数:30

    持仓天数:5

      {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-787:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-15: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":"-787:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-794:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-803:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-810:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-8155:input_2","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-8144:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-131:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-126:input_data","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data"},{"DestinationInputPortId":"-803:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-144:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62:data"},{"DestinationInputPortId":"-794:input_data","SourceOutputPortId":"-787:data"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-53:data2","SourceOutputPortId":"-794:data"},{"DestinationInputPortId":"-810:input_data","SourceOutputPortId":"-803:data"},{"DestinationInputPortId":"-130:input_data","SourceOutputPortId":"-810:data"},{"DestinationInputPortId":"-8144:train_ds","SourceOutputPortId":"-8155:data_1"},{"DestinationInputPortId":"-8144:test_ds","SourceOutputPortId":"-8155:data_2"},{"DestinationInputPortId":"-131:training_ds","SourceOutputPortId":"-8144:train_data"},{"DestinationInputPortId":"-131:predict_ds","SourceOutputPortId":"-8144:test_data"},{"DestinationInputPortId":"-144:options_data","SourceOutputPortId":"-131:predictions"},{"DestinationInputPortId":"-8155:input_1","SourceOutputPortId":"-126:data"},{"DestinationInputPortId":"-8155:input_3","SourceOutputPortId":"-130:data"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2017-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":"shift(close, -5) / shift(open, -1)-1\nrank(label)\nwhere(label>=0.75,1,where(label<=0.25, 0, NaN))","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":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"cast_label_int","Value":"False","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":"(close_0-mean(close_0,12))/mean(close_0,12)*100\nrank(std(amount_0,15))\nrank_avg_amount_0/rank_avg_amount_8\nts_argmin(low_0,20)\nrank_return_30\n(low_1-close_0)/close_0\nta_bbands_lowerband_14_0\nmean(mf_net_pct_s_0,4)\namount_0/avg_amount_3\nreturn_0/return_5\nreturn_1/return_5\nrank_avg_amount_7/rank_avg_amount_10\nta_sma_10_0/close_0\nsqrt(high_0*low_0)-amount_0/volume_0*adjust_factor_0\navg_turn_15/(turn_0+1e-5)\nreturn_10\nmf_net_pct_s_0\n(close_0-open_0)/close_1\n ","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"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":7,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2019-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2020-02-26","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":"0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-62","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"IsPartOfPartialRun":null,"Comment":"预测数据,用于回测和模拟","CommentCollapsed":false},{"Id":"-787","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-787"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-787"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-787","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-794","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":"-794"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-794"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-794","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-803","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":"50","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-803"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-803"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-803","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-810","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":"-810"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-810"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-810","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-8155","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 train_df = input_1.read()\n features = input_2.read()\n feature_min = train_df[features].quantile(0.005)\n feature_max = train_df[features].quantile(0.995)\n train_df[features] = train_df[features].clip(feature_min,feature_max,axis=1)\n data_1 = DataSource.write_df(train_df)\n test_df = input_3.read()\n test_df[features] = test_df[features].clip(feature_min,feature_max,axis=1)\n data_2 = DataSource.write_df(test_df)\n return Outputs(data_1=data_1, data_2=data_2, data_3=None)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"input_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"params","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-8155"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-8155"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-8155"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-8155","OutputType":null},{"Name":"data_2","NodeId":"-8155","OutputType":null},{"Name":"data_3","NodeId":"-8155","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-8144","ModuleId":"BigQuantSpace.RobustScaler.RobustScaler-v13","ModuleParameters":[{"Name":"scale_type","Value":"standard","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"quantile_range_min","Value":"0.01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"quantile_range_max","Value":"0.99","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"global_scale","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"train_ds","NodeId":"-8144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-8144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"test_ds","NodeId":"-8144"}],"OutputPortsInternal":[{"Name":"train_data","NodeId":"-8144","OutputType":null},{"Name":"test_data","NodeId":"-8144","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-131","ModuleId":"BigQuantSpace.decision_tree_classifier.decision_tree_classifier-v1","ModuleParameters":[{"Name":"criterion","Value":"gini","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"feature_fraction","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_depth","Value":30,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"min_samples_per_leaf","Value":200,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"key_cols","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"other_train_parameters","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-131"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-131"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"model","NodeId":"-131"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"predict_ds","NodeId":"-131"}],"OutputPortsInternal":[{"Name":"output_model","NodeId":"-131","OutputType":null},{"Name":"predictions","NodeId":"-131","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-144","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 \n context.indicator_data = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n context.rebalance_days = 5\n context.stock_num = 30\n if 'index' not in context.extension:\n context.extension['index'] = 0\n \n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n \n context.extension['index'] += 1\n # 不在换仓日就return,相当于后面的代码只会一个月运行一次,买入的股票会持有1个月\n if context.extension['index'] % context.rebalance_days != 0:\n return \n \n # 当前的日期\n date = data.current_dt.strftime('%Y-%m-%d')\n \n cur_data = context.indicator_data[context.indicator_data['date'] == date]\n # 根据日期获取调仓需要买入的股票的列表\n #stock_to_buy = list(cur_data.instrument[:context.stock_num])\n cur_data = cur_data[cur_data['pred_label'] == 1.0]\n \n stock_to_buy = list(cur_data.sort_values('classes_prob_1.0',ascending=False).instrument)[:context.stock_num]\n if date == '2017-02-06':\n print(date, len(stock_to_buy), stock_to_buy)\n # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表\n stock_hold_now = [equity.symbol for equity in context.portfolio.positions]\n # 继续持有的股票:调仓时,如果买入的股票已经存在于目前的持仓里,那么应继续持有\n no_need_to_sell = [i for i in stock_hold_now if i in stock_to_buy]\n # 需要卖出的股票\n stock_to_sell = [i for i in stock_hold_now if i not in no_need_to_sell]\n \n # 卖出\n for stock in stock_to_sell:\n # 如果该股票停牌,则没法成交。因此需要用can_trade方法检查下该股票的状态\n # 如果返回真值,则可以正常下单,否则会出错\n # 因为stock是字符串格式,我们用symbol方法将其转化成平台可以接受的形式:Equity格式\n\n if data.can_trade(context.symbol(stock)):\n # order_target_percent是平台的一个下单接口,表明下单使得该股票的权重为0,\n # 即卖出全部股票,可参考回测文档\n context.order_target_percent(context.symbol(stock), 0)\n \n # 如果当天没有买入的股票,就返回\n if len(stock_to_buy) == 0:\n return\n\n # 等权重买入 \n weight = 1 / len(stock_to_buy)\n \n # 买入\n for stock in stock_to_buy:\n if data.can_trade(context.symbol(stock)):\n # 下单使得某只股票的持仓权重达到weight,因为\n # weight大于0,因此是等权重买入\n context.order_target_percent(context.symbol(stock), weight)\n ","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_trading_start","Value":"# 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。\ndef bigquant_run(context, data):\n pass\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"volume_limit","Value":"0","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":"100000","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"daily","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"price_type","Value":"真实价格","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"product_type","Value":"股票","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-144"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-144"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-144","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":11,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-126","ModuleId":"BigQuantSpace.dropnan.dropnan-v2","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-126"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-126"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-126","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-130","ModuleId":"BigQuantSpace.dropnan.dropnan-v2","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-130"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-130"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-130","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"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='61,2,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-15' Position='-66,122,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='656,-21,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-53' Position='151,308,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-62' Position='1077,122,200,200'/><NodePosition Node='-787' Position='301,127,200,200'/><NodePosition Node='-794' Position='304,212,200,200'/><NodePosition Node='-803' Position='1078,236,200,200'/><NodePosition Node='-810' Position='1081,327,200,200'/><NodePosition Node='-8155' Position='525,513,200,200'/><NodePosition Node='-8144' Position='538,594,200,200'/><NodePosition Node='-131' Position='533,675,200,200'/><NodePosition Node='-144' Position='422,770,200,200'/><NodePosition Node='-126' Position='149,395,200,200'/><NodePosition Node='-130' Position='1078,418,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月20日 16:01
      # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
      
      
      # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
      def m6_run_bigquant_run(input_1, input_2, input_3):
          train_df = input_1.read()
          features = input_2.read()
          feature_min = train_df[features].quantile(0.005)
          feature_max = train_df[features].quantile(0.995)
          train_df[features] = train_df[features].clip(feature_min,feature_max,axis=1)
          data_1 = DataSource.write_df(train_df)
          test_df = input_3.read()
          test_df[features] = test_df[features].clip(feature_min,feature_max,axis=1)
          data_2 = DataSource.write_df(test_df)
          return Outputs(data_1=data_1, data_2=data_2, data_3=None)
      
      # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
      def m6_post_run_bigquant_run(outputs):
          return outputs
      
      # 回测引擎:初始化函数,只执行一次
      def m11_initialize_bigquant_run(context):
          # 加载预测数据
        
          context.indicator_data = context.options['data'].read_df()
      
          # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数
          context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
          context.rebalance_days = 5
          context.stock_num = 30
          if 'index' not in context.extension:
              context.extension['index'] = 0
           
      
      # 回测引擎:每日数据处理函数,每天执行一次
      def m11_handle_data_bigquant_run(context, data):
          
          context.extension['index'] += 1
          # 不在换仓日就return,相当于后面的代码只会一个月运行一次,买入的股票会持有1个月
          if  context.extension['index'] % context.rebalance_days != 0:
              return 
          
          # 当前的日期
          date = data.current_dt.strftime('%Y-%m-%d')
          
          cur_data = context.indicator_data[context.indicator_data['date'] == date]
          # 根据日期获取调仓需要买入的股票的列表
          #stock_to_buy = list(cur_data.instrument[:context.stock_num])
          cur_data = cur_data[cur_data['pred_label'] == 1.0]
          
          stock_to_buy =  list(cur_data.sort_values('classes_prob_1.0',ascending=False).instrument)[:context.stock_num]
          if date == '2017-02-06':
              print(date, len(stock_to_buy), stock_to_buy)
          # 通过positions对象,使用列表生成式的方法获取目前持仓的股票列表
          stock_hold_now = [equity.symbol for equity in context.portfolio.positions]
          # 继续持有的股票:调仓时,如果买入的股票已经存在于目前的持仓里,那么应继续持有
          no_need_to_sell = [i for i in stock_hold_now if i in stock_to_buy]
          # 需要卖出的股票
          stock_to_sell = [i for i in stock_hold_now if i not in no_need_to_sell]
        
          # 卖出
          for stock in stock_to_sell:
              # 如果该股票停牌,则没法成交。因此需要用can_trade方法检查下该股票的状态
              # 如果返回真值,则可以正常下单,否则会出错
              # 因为stock是字符串格式,我们用symbol方法将其转化成平台可以接受的形式:Equity格式
      
              if data.can_trade(context.symbol(stock)):
                  # order_target_percent是平台的一个下单接口,表明下单使得该股票的权重为0,
                  #   即卖出全部股票,可参考回测文档
                  context.order_target_percent(context.symbol(stock), 0)
          
          # 如果当天没有买入的股票,就返回
          if len(stock_to_buy) == 0:
              return
      
          # 等权重买入 
          weight =  1 / len(stock_to_buy)
          
          # 买入
          for stock in stock_to_buy:
              if data.can_trade(context.symbol(stock)):
                  # 下单使得某只股票的持仓权重达到weight,因为
                  # weight大于0,因此是等权重买入
                  context.order_target_percent(context.symbol(stock), weight)
       
      # 回测引擎:准备数据,只执行一次
      def m11_prepare_bigquant_run(context):
          pass
      
      # 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。
      def m11_before_trading_start_bigquant_run(context, data):
          pass
      
      
      m1 = M.instruments.v2(
          start_date='2017-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="""shift(close, -5) / shift(open, -1)-1
      rank(label)
      where(label>=0.75,1,where(label<=0.25, 0, NaN))""",
          start_date='',
          end_date='',
          benchmark='000300.SHA',
          drop_na_label=False,
          cast_label_int=False
      )
      
      m3 = M.input_features.v1(
          features="""(close_0-mean(close_0,12))/mean(close_0,12)*100
      rank(std(amount_0,15))
      rank_avg_amount_0/rank_avg_amount_8
      ts_argmin(low_0,20)
      rank_return_30
      (low_1-close_0)/close_0
      ta_bbands_lowerband_14_0
      mean(mf_net_pct_s_0,4)
      amount_0/avg_amount_3
      return_0/return_5
      return_1/return_5
      rank_avg_amount_7/rank_avg_amount_10
      ta_sma_10_0/close_0
      sqrt(high_0*low_0)-amount_0/volume_0*adjust_factor_0
      avg_turn_15/(turn_0+1e-5)
      return_10
      mf_net_pct_s_0
      (close_0-open_0)/close_1
       """
      )
      
      m15 = M.general_feature_extractor.v7(
          instruments=m1.data,
          features=m3.data,
          start_date='',
          end_date='',
          before_start_days=0
      )
      
      m16 = M.derived_feature_extractor.v3(
          input_data=m15.data,
          features=m3.data,
          date_col='date',
          instrument_col='instrument',
          drop_na=False,
          remove_extra_columns=False
      )
      
      m7 = M.join.v3(
          data1=m2.data,
          data2=m16.data,
          on='date,instrument',
          how='inner',
          sort=False
      )
      
      m4 = M.dropnan.v2(
          input_data=m7.data
      )
      
      m9 = M.instruments.v2(
          start_date=T.live_run_param('trading_date', '2019-01-01'),
          end_date=T.live_run_param('trading_date', '2020-02-26'),
          market='CN_STOCK_A',
          instrument_list='',
          max_count=0
      )
      
      m17 = M.general_feature_extractor.v7(
          instruments=m9.data,
          features=m3.data,
          start_date='',
          end_date='',
          before_start_days=50
      )
      
      m18 = M.derived_feature_extractor.v3(
          input_data=m17.data,
          features=m3.data,
          date_col='date',
          instrument_col='instrument',
          drop_na=False,
          remove_extra_columns=False
      )
      
      m5 = M.dropnan.v2(
          input_data=m18.data
      )
      
      m6 = M.cached.v3(
          input_1=m4.data,
          input_2=m3.data,
          input_3=m5.data,
          run=m6_run_bigquant_run,
          post_run=m6_post_run_bigquant_run,
          input_ports='',
          params='{}',
          output_ports=''
      )
      
      m8 = M.RobustScaler.v13(
          train_ds=m6.data_1,
          features=m3.data,
          test_ds=m6.data_2,
          scale_type='standard',
          quantile_range_min=0.01,
          quantile_range_max=0.99,
          global_scale=True
      )
      
      m10 = M.decision_tree_classifier.v1(
          training_ds=m8.train_data,
          features=m3.data,
          predict_ds=m8.test_data,
          criterion='gini',
          feature_fraction=1,
          max_depth=30,
          min_samples_per_leaf=200,
          key_cols='date,instrument',
          other_train_parameters={}
      )
      
      m11 = M.trade.v4(
          instruments=m9.data,
          options_data=m10.predictions,
          start_date='',
          end_date='',
          initialize=m11_initialize_bigquant_run,
          handle_data=m11_handle_data_bigquant_run,
          prepare=m11_prepare_bigquant_run,
          before_trading_start=m11_before_trading_start_bigquant_run,
          volume_limit=0,
          order_price_field_buy='open',
          order_price_field_sell='close',
          capital_base=100000,
          auto_cancel_non_tradable_orders=True,
          data_frequency='daily',
          price_type='真实价格',
          product_type='股票',
          plot_charts=True,
          backtest_only=False,
          benchmark=''
      )
      
      • 收益率20.14%
      • 年化收益率18.1%
      • 基准收益率35.29%
      • 阿尔法-0.06
      • 贝塔0.83
      • 夏普比率0.69
      • 胜率0.53
      • 盈亏比1.13
      • 收益波动率23.88%
      • 信息比率-0.04
      • 最大回撤23.03%
      bigcharts-data-start/{"__type":"tabs","__id":"bigchart-f8be2f82848f476ea8bb419c38397978"}/bigcharts-data-end