克隆策略
{"Description":"实验创建于2020/4/10","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-526:instruments","SourceOutputPortId":"-513:data"},{"DestinationInputPortId":"-565:instruments","SourceOutputPortId":"-513:data"},{"DestinationInputPortId":"-526:features","SourceOutputPortId":"-521:data"},{"DestinationInputPortId":"-541:features","SourceOutputPortId":"-521:data"},{"DestinationInputPortId":"-548:features","SourceOutputPortId":"-521:data"},{"DestinationInputPortId":"-557:features","SourceOutputPortId":"-521:data"},{"DestinationInputPortId":"-600:features","SourceOutputPortId":"-521:data"},{"DestinationInputPortId":"-548:input_data","SourceOutputPortId":"-526:data"},{"DestinationInputPortId":"-541:instruments","SourceOutputPortId":"-532:data"},{"DestinationInputPortId":"-614:instruments","SourceOutputPortId":"-532:data"},{"DestinationInputPortId":"-557:input_data","SourceOutputPortId":"-541:data"},{"DestinationInputPortId":"-576:data2","SourceOutputPortId":"-548:data"},{"DestinationInputPortId":"-593:input_data","SourceOutputPortId":"-557:data"},{"DestinationInputPortId":"-576:data1","SourceOutputPortId":"-565:data"},{"DestinationInputPortId":"-590:input_data","SourceOutputPortId":"-576:data"},{"DestinationInputPortId":"-600:training_ds","SourceOutputPortId":"-590:data"},{"DestinationInputPortId":"-600:predict_ds","SourceOutputPortId":"-593:data"},{"DestinationInputPortId":"-635:input_ds","SourceOutputPortId":"-600:predictions"},{"DestinationInputPortId":"-614:options_data","SourceOutputPortId":"-635:sorted_data"}],"ModuleNodes":[{"Id":"-513","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2010-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2014-12-31","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":"-513"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-513","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-521","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nreturn_5\nreturn_10\nreturn_20\navg_amount_0/avg_amount_5\navg_amount_5/avg_amount_20\nrank_avg_amount_0/rank_avg_amount_5\nrank_avg_amount_5/rank_avg_amount_10\nrank_return_0\nrank_return_5\nrank_return_10\nrank_return_0/rank_return_5\nrank_return_5/rank_return_10\npe_ttm_0\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-521"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-521","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-526","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":90,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-526"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-526"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-526","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-532","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2017-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":"-532"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-532","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-541","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":90,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-541"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-541"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-541","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-548","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":"-548"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-548"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-548","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-557","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":"-557"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-557"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-557","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-565","ModuleId":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","ModuleParameters":[{"Name":"label_expr","Value":"# #号开始的表示注释\n# 0. 每行一个,顺序执行,从第二个开始,可以使用label字段\n# 1. 可用数据字段见 https://bigquant.com/docs/develop/datasource/deprecated/history_data.html\n# 添加benchmark_前缀,可使用对应的benchmark数据\n# 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/develop/bigexpr/usage.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个分类\n#all_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":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-565"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-565","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":8,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-576","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":"-576"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-576"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-576","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-590","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-590"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-590","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-593","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-593"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-593","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-600","ModuleId":"BigQuantSpace.random_forest_regressor.random_forest_regressor-v1","ModuleParameters":[{"Name":"iterations","Value":10,"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":"workers","Value":1,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"other_train_parameters","Value":"{\"random_state\":0}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"training_ds","NodeId":"-600"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-600"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"model","NodeId":"-600"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"predict_ds","NodeId":"-600"}],"OutputPortsInternal":[{"Name":"output_model","NodeId":"-600","OutputType":null},{"Name":"predictions","NodeId":"-600","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":12,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-614","ModuleId":"BigQuantSpace.trade.trade-v4","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"initialize","Value":"# 回测引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n # 加载预测数据\n context.ranker_prediction = context.options['data'].read_df()\n\n # 系统已经设置了默认的交易手续费和滑点,要修改手续费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n # 预测数据,通过options传入进来,使用 read_df 函数,加载到内存 (DataFrame)\n # 设置买入的股票数量,这里买入预测股票列表排名靠前的5只\n stock_count = 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.hold_days = 5\n","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.hold_days # 是否在建仓期间(前 hold_days 天)\n cash_avg = context.portfolio.portfolio_value / context.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天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰\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. 生成买入订单:按StockRanker预测的排序,买入前面的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":"before_trading_start","Value":"# 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。\ndef bigquant_run(context, data):\n pass\n","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":"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":"-614"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-614"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-614"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-614"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-614"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-614","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":13,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-635","ModuleId":"BigQuantSpace.sort.sort-v4","ModuleParameters":[{"Name":"sort_by","Value":"pred_label","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"group_by","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"keep_columns","Value":"--","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"ascending","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_ds","NodeId":"-635"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"sort_by_ds","NodeId":"-635"}],"OutputPortsInternal":[{"Name":"sorted_data","NodeId":"-635","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":14,"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='-513' Position='12,23,200,200'/><NodePosition Node='-521' Position='337,26,200,200'/><NodePosition Node='-526' Position='131,157,200,200'/><NodePosition Node='-532' Position='641,25,200,200'/><NodePosition Node='-541' Position='579,153,200,200'/><NodePosition Node='-548' Position='134,243,200,200'/><NodePosition Node='-557' Position='581,264,200,200'/><NodePosition Node='-565' Position='-160,159,200,200'/><NodePosition Node='-576' Position='-5,330,200,200'/><NodePosition Node='-590' Position='2,408,200,200'/><NodePosition Node='-593' Position='590,354,200,200'/><NodePosition Node='-600' Position='258,475,200,200'/><NodePosition Node='-614' Position='655,644,200,200'/><NodePosition Node='-635' Position='516,552,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 [7]:
# 本代码由可视化策略环境自动生成 2020年4月13日 09:51
# 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
# 回测引擎:初始化函数,只执行一次
def m13_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.hold_days = 5
# 回测引擎:每日数据处理函数,每天执行一次
def m13_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.hold_days # 是否在建仓期间(前 hold_days 天)
cash_avg = context.portfolio.portfolio_value / context.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天之后才开始卖出;对持仓的股票,按StockRanker预测的排序末位淘汰
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. 生成买入订单:按StockRanker预测的排序,买入前面的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 m13_prepare_bigquant_run(context):
pass
# 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。
def m13_before_trading_start_bigquant_run(context, data):
pass
m1 = M.instruments.v2(
start_date='2010-01-01',
end_date='2014-12-31',
market='CN_STOCK_A',
instrument_list='',
max_count=0
)
m8 = M.advanced_auto_labeler.v2(
instruments=m1.data,
label_expr="""# #号开始的表示注释
# 0. 每行一个,顺序执行,从第二个开始,可以使用label字段
# 1. 可用数据字段见 https://bigquant.com/docs/develop/datasource/deprecated/history_data.html
# 添加benchmark_前缀,可使用对应的benchmark数据
# 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/develop/bigexpr/usage.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=False,
user_functions={},
m_cached=False
)
m2 = M.input_features.v1(
features="""
# #号开始的表示注释,注释需单独一行
# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
return_5
return_10
return_20
avg_amount_0/avg_amount_5
avg_amount_5/avg_amount_20
rank_avg_amount_0/rank_avg_amount_5
rank_avg_amount_5/rank_avg_amount_10
rank_return_0
rank_return_5
rank_return_10
rank_return_0/rank_return_5
rank_return_5/rank_return_10
pe_ttm_0
"""
)
m3 = M.general_feature_extractor.v7(
instruments=m1.data,
features=m2.data,
start_date='',
end_date='',
before_start_days=90
)
m6 = M.derived_feature_extractor.v3(
input_data=m3.data,
features=m2.data,
date_col='date',
instrument_col='instrument',
drop_na=False,
remove_extra_columns=False,
user_functions={}
)
m9 = M.join.v3(
data1=m8.data,
data2=m6.data,
on='date,instrument',
how='inner',
sort=False
)
m11 = M.dropnan.v1(
input_data=m9.data
)
m4 = M.instruments.v2(
start_date='2015-01-01',
end_date='2017-01-01',
market='CN_STOCK_A',
instrument_list='',
max_count=0
)
m5 = M.general_feature_extractor.v7(
instruments=m4.data,
features=m2.data,
start_date='',
end_date='',
before_start_days=90
)
m7 = M.derived_feature_extractor.v3(
input_data=m5.data,
features=m2.data,
date_col='date',
instrument_col='instrument',
drop_na=False,
remove_extra_columns=False,
user_functions={}
)
m10 = M.dropnan.v1(
input_data=m7.data
)
m12 = M.random_forest_regressor.v1(
training_ds=m11.data,
features=m2.data,
predict_ds=m10.data,
iterations=10,
feature_fraction=1,
max_depth=30,
min_samples_per_leaf=200,
key_cols='date,instrument',
workers=1,
other_train_parameters={"random_state":0}
)
m14 = M.sort.v4(
input_ds=m12.predictions,
sort_by='pred_label',
group_by='date',
keep_columns='--',
ascending=False
)
m13 = M.trade.v4(
instruments=m4.data,
options_data=m14.sorted_data,
start_date='',
end_date='',
initialize=m13_initialize_bigquant_run,
handle_data=m13_handle_data_bigquant_run,
prepare=m13_prepare_bigquant_run,
before_trading_start=m13_before_trading_start_bigquant_run,
volume_limit=0.025,
order_price_field_buy='open',
order_price_field_sell='close',
capital_base=1000000,
auto_cancel_non_tradable_orders=True,
data_frequency='daily',
price_type='真实价格',
product_type='股票',
plot_charts=True,
backtest_only=False,
benchmark=''
)
日志 159 条,错误日志
0 条
[2020-04-11 18:19:40.978805] INFO: bigquant: instruments.v2 开始运行..
[2020-04-11 18:19:41.102277] INFO: bigquant: instruments.v2 运行完成[0.123442s].
[2020-04-11 18:19:41.109764] INFO: bigquant: advanced_auto_labeler.v2 开始运行..
[2020-04-11 18:19:43.595941] INFO: 自动标注(股票): 加载历史数据: 2642813 行
[2020-04-11 18:19:43.597710] INFO: 自动标注(股票): 开始标注 ..
[2020-04-11 18:19:47.345151] INFO: bigquant: advanced_auto_labeler.v2 运行完成[6.235362s].
[2020-04-11 18:19:47.348321] INFO: bigquant: input_features.v1 开始运行..
[2020-04-11 18:19:47.376364] INFO: bigquant: 命中缓存
[2020-04-11 18:19:47.377408] INFO: bigquant: input_features.v1 运行完成[0.029088s].
[2020-04-11 18:19:47.401994] INFO: bigquant: general_feature_extractor.v7 开始运行..
[2020-04-11 18:19:49.652083] INFO: 基础特征抽取: 年份 2009, 特征行数=95020
[2020-04-11 18:19:52.575865] INFO: 基础特征抽取: 年份 2010, 特征行数=431567
[2020-04-11 18:19:55.321343] INFO: 基础特征抽取: 年份 2011, 特征行数=511455
[2020-04-11 18:19:58.579002] INFO: 基础特征抽取: 年份 2012, 特征行数=565675
[2020-04-11 18:20:01.738328] INFO: 基础特征抽取: 年份 2013, 特征行数=564168
[2020-04-11 18:20:03.283742] INFO: 基础特征抽取: 年份 2014, 特征行数=569948
[2020-04-11 18:20:03.968561] INFO: 基础特征抽取: 总行数: 2737833
[2020-04-11 18:20:03.990888] INFO: bigquant: general_feature_extractor.v7 运行完成[16.588882s].
[2020-04-11 18:20:03.997820] INFO: bigquant: derived_feature_extractor.v3 开始运行..
[2020-04-11 18:20:05.120896] INFO: derived_feature_extractor: 提取完成 avg_amount_0/avg_amount_5, 0.014s
[2020-04-11 18:20:05.128520] INFO: derived_feature_extractor: 提取完成 avg_amount_5/avg_amount_20, 0.006s
[2020-04-11 18:20:05.134053] INFO: derived_feature_extractor: 提取完成 rank_avg_amount_0/rank_avg_amount_5, 0.005s
[2020-04-11 18:20:05.139505] INFO: derived_feature_extractor: 提取完成 rank_avg_amount_5/rank_avg_amount_10, 0.005s
[2020-04-11 18:20:05.144603] INFO: derived_feature_extractor: 提取完成 rank_return_0/rank_return_5, 0.004s
[2020-04-11 18:20:05.153154] INFO: derived_feature_extractor: 提取完成 rank_return_5/rank_return_10, 0.008s
[2020-04-11 18:20:05.846659] INFO: derived_feature_extractor: /y_2009, 95020
[2020-04-11 18:20:05.981892] INFO: derived_feature_extractor: /y_2010, 431567
[2020-04-11 18:20:06.426659] INFO: derived_feature_extractor: /y_2011, 511455
[2020-04-11 18:20:06.791934] INFO: derived_feature_extractor: /y_2012, 565675
[2020-04-11 18:20:07.180785] INFO: derived_feature_extractor: /y_2013, 564168
[2020-04-11 18:20:07.587379] INFO: derived_feature_extractor: /y_2014, 569948
[2020-04-11 18:20:09.679414] INFO: bigquant: derived_feature_extractor.v3 运行完成[5.681573s].
[2020-04-11 18:20:09.687464] INFO: bigquant: join.v3 开始运行..
[2020-04-11 18:20:11.299205] INFO: join: /y_2009, 行数=0/95020, 耗时=0.888358s
[2020-04-11 18:20:12.574365] INFO: join: /y_2010, 行数=431028/431567, 耗时=1.272406s
[2020-04-11 18:20:14.090445] INFO: join: /y_2011, 行数=510922/511455, 耗时=1.498508s
[2020-04-11 18:20:15.486742] INFO: join: /y_2012, 行数=564582/565675, 耗时=1.383319s
[2020-04-11 18:20:16.983499] INFO: join: /y_2013, 行数=563132/564168, 耗时=1.474996s
[2020-04-11 18:20:18.612129] INFO: join: /y_2014, 行数=555191/569948, 耗时=1.607865s
[2020-04-11 18:20:19.964604] INFO: join: 最终行数: 2624855
[2020-04-11 18:20:19.983768] INFO: bigquant: join.v3 运行完成[10.296295s].
[2020-04-11 18:20:19.989638] INFO: bigquant: dropnan.v1 开始运行..
[2020-04-11 18:20:20.096282] INFO: dropnan: /y_2009, 0/0
[2020-04-11 18:20:20.611804] INFO: dropnan: /y_2010, 423739/431028
[2020-04-11 18:20:21.311372] INFO: dropnan: /y_2011, 504726/510922
[2020-04-11 18:20:21.983790] INFO: dropnan: /y_2012, 561109/564582
[2020-04-11 18:20:22.668366] INFO: dropnan: /y_2013, 563102/563132
[2020-04-11 18:20:23.458601] INFO: dropnan: /y_2014, 553408/555191
[2020-04-11 18:20:25.355673] INFO: dropnan: 行数: 2606084/2624855
[2020-04-11 18:20:25.382988] INFO: bigquant: dropnan.v1 运行完成[5.393342s].
[2020-04-11 18:20:25.384651] INFO: bigquant: instruments.v2 开始运行..
[2020-04-11 18:20:25.403942] INFO: bigquant: 命中缓存
[2020-04-11 18:20:25.404838] INFO: bigquant: instruments.v2 运行完成[0.020181s].
[2020-04-11 18:20:25.424032] INFO: bigquant: general_feature_extractor.v7 开始运行..
[2020-04-11 18:20:25.449279] INFO: bigquant: 命中缓存
[2020-04-11 18:20:25.450180] INFO: bigquant: general_feature_extractor.v7 运行完成[0.026146s].
[2020-04-11 18:20:25.451668] INFO: bigquant: derived_feature_extractor.v3 开始运行..
[2020-04-11 18:20:26.012120] INFO: derived_feature_extractor: 提取完成 avg_amount_0/avg_amount_5, 0.003s
[2020-04-11 18:20:26.016941] INFO: derived_feature_extractor: 提取完成 avg_amount_5/avg_amount_20, 0.004s
[2020-04-11 18:20:26.020793] INFO: derived_feature_extractor: 提取完成 rank_avg_amount_0/rank_avg_amount_5, 0.003s
[2020-04-11 18:20:26.025651] INFO: derived_feature_extractor: 提取完成 rank_avg_amount_5/rank_avg_amount_10, 0.004s
[2020-04-11 18:20:26.029124] INFO: derived_feature_extractor: 提取完成 rank_return_0/rank_return_5, 0.003s
[2020-04-11 18:20:26.032562] INFO: derived_feature_extractor: 提取完成 rank_return_5/rank_return_10, 0.003s
[2020-04-11 18:20:26.417293] INFO: derived_feature_extractor: /y_2014, 141569
[2020-04-11 18:20:26.676388] INFO: derived_feature_extractor: /y_2015, 569698
[2020-04-11 18:20:27.175637] INFO: derived_feature_extractor: /y_2016, 641546
[2020-04-11 18:20:28.458474] INFO: bigquant: derived_feature_extractor.v3 运行完成[3.00676s].
[2020-04-11 18:20:28.461406] INFO: bigquant: dropnan.v1 开始运行..
[2020-04-11 18:20:28.773460] INFO: dropnan: /y_2014, 140747/141569
[2020-04-11 18:20:29.316179] INFO: dropnan: /y_2015, 565146/569698
[2020-04-11 18:20:29.973489] INFO: dropnan: /y_2016, 636912/641546
[2020-04-11 18:20:30.782470] INFO: dropnan: 行数: 1342805/1352813
[2020-04-11 18:20:30.812085] INFO: bigquant: dropnan.v1 运行完成[2.350663s].
[2020-04-11 18:20:31.067957] INFO: bigquant: random_forest_regressor.v1 开始运行..
[2020-04-11 18:21:40.103727] INFO: bigquant: random_forest_regressor.v1 运行完成[69.035765s].
[2020-04-11 18:21:40.109027] INFO: bigquant: sort.v4 开始运行..
[2020-04-11 18:21:42.465071] INFO: bigquant: sort.v4 运行完成[2.356029s].
[2020-04-11 18:21:43.480990] INFO: bigquant: backtest.v8 开始运行..
[2020-04-11 18:21:43.505695] INFO: backtest: biglearning backtest:V8.3.3
[2020-04-11 18:21:43.506841] INFO: backtest: product_type:stock by specified
[2020-04-11 18:21:43.687772] INFO: bigquant: cached.v2 开始运行..
[2020-04-11 18:21:43.710185] INFO: bigquant: 命中缓存
[2020-04-11 18:21:43.711518] INFO: bigquant: cached.v2 运行完成[0.023745s].
[2020-04-11 18:21:44.858188] INFO: algo: TradingAlgorithm V1.6.7
[2020-04-11 18:21:45.983963] INFO: algo: trading transform...
[2020-04-11 18:21:47.972808] INFO: algo: handle_splits get splits [dt:2015-04-23 00:00:00+00:00] [asset:Equity(2674 [600184.SHA]), ratio:0.5000951886177063]
[2020-04-11 18:21:48.099390] INFO: algo: handle_splits get splits [dt:2015-04-30 00:00:00+00:00] [asset:Equity(627 [603399.SHA]), ratio:0.9986504912376404]
[2020-04-11 18:21:48.100507] INFO: Position: position stock handle split[sid:627, orig_amount:7300, new_amount:7309.0, orig_cost:14.900000792630854, new_cost:14.88, ratio:0.9986504912376404, last_sale_price:14.800000190734863]
[2020-04-11 18:21:48.101449] INFO: Position: after split: PositionStock(asset:Equity(627 [603399.SHA]), amount:7309.0, cost_basis:14.88, last_sale_price:14.819999694824219)
[2020-04-11 18:21:48.102177] INFO: Position: returning cash: 12.8
[2020-04-11 18:21:48.311974] INFO: algo: handle_splits get splits [dt:2015-05-14 00:00:00+00:00] [asset:Equity(1129 [300150.SZA]), ratio:0.4970097243785858]
[2020-04-11 18:21:48.587414] INFO: algo: handle_splits get splits [dt:2015-06-01 00:00:00+00:00] [asset:Equity(1233 [002534.SZA]), ratio:0.9940923452377319]
[2020-04-11 18:21:48.588539] INFO: Position: position stock handle split[sid:1233, orig_amount:2700, new_amount:2716.0, orig_cost:27.410001896052133, new_cost:27.25, ratio:0.9940923452377319, last_sale_price:25.240005493164062]
[2020-04-11 18:21:48.589413] INFO: Position: after split: PositionStock(asset:Equity(1233 [002534.SZA]), amount:2716.0, cost_basis:27.25, last_sale_price:25.39000129699707)
[2020-04-11 18:21:48.590150] INFO: Position: returning cash: 1.15
[2020-04-11 18:21:48.673954] INFO: algo: handle_splits get splits [dt:2015-06-04 00:00:00+00:00] [asset:Equity(1216 [300262.SZA]), ratio:0.7135816216468811]
[2020-04-11 18:21:48.675165] INFO: Position: position stock handle split[sid:1216, orig_amount:1700, new_amount:2382.0, orig_cost:33.93999868629467, new_cost:24.22, ratio:0.7135816216468811, last_sale_price:26.060001373291016]
[2020-04-11 18:21:48.676226] INFO: Position: after split: PositionStock(asset:Equity(1216 [300262.SZA]), amount:2382.0, cost_basis:24.22, last_sale_price:36.52000045776367)
[2020-04-11 18:21:48.677067] INFO: Position: returning cash: 9.08
[2020-04-11 18:21:48.750156] INFO: algo: handle_splits get splits [dt:2015-06-09 00:00:00+00:00] [asset:Equity(919 [603019.SHA]), ratio:0.9993464350700378]
[2020-04-11 18:21:48.751297] INFO: Position: position stock handle split[sid:919, orig_amount:1600, new_amount:1601.0, orig_cost:132.43750028779937, new_cost:132.35, ratio:0.9993464350700378, last_sale_price:122.33000183105469]
[2020-04-11 18:21:48.752179] INFO: Position: after split: PositionStock(asset:Equity(919 [603019.SHA]), amount:1601.0, cost_basis:132.35, last_sale_price:122.41000366210938)
[2020-04-11 18:21:48.752921] INFO: Position: returning cash: 5.67
[2020-04-11 18:21:48.777967] INFO: algo: handle_splits get splits [dt:2015-06-10 00:00:00+00:00] [asset:Equity(4 [300159.SZA]), ratio:0.499615341424942]
[2020-04-11 18:21:48.778914] INFO: algo: handle_splits get splits [dt:2015-06-10 00:00:00+00:00] [asset:Equity(67 [002429.SZA]), ratio:0.9978799223899841]
[2020-04-11 18:21:48.779757] INFO: Position: position stock handle split[sid:67, orig_amount:14100, new_amount:14129.0, orig_cost:12.980000621163741, new_cost:12.95, ratio:0.9978799223899841, last_sale_price:14.120000839233398]
[2020-04-11 18:21:48.780529] INFO: Position: after split: PositionStock(asset:Equity(67 [002429.SZA]), amount:14129.0, cost_basis:12.95, last_sale_price:14.149999618530273)
[2020-04-11 18:21:48.781262] INFO: Position: returning cash: 13.51
[2020-04-11 18:21:49.227038] INFO: algo: handle_splits get splits [dt:2015-07-09 00:00:00+00:00] [asset:Equity(477 [600270.SHA]), ratio:0.9768115878105164]
[2020-04-11 18:21:49.228183] INFO: Position: position stock handle split[sid:477, orig_amount:2100, new_amount:2149.0, orig_cost:16.419998170402266, new_cost:16.04, ratio:0.9768115878105164, last_sale_price:16.850000381469727]
[2020-04-11 18:21:49.229035] INFO: Position: after split: PositionStock(asset:Equity(477 [600270.SHA]), amount:2149.0, cost_basis:16.04, last_sale_price:17.25)
[2020-04-11 18:21:49.229876] INFO: Position: returning cash: 14.35
[2020-04-11 18:21:49.379650] INFO: algo: handle_splits get splits [dt:2015-07-17 00:00:00+00:00] [asset:Equity(2199 [600240.SHA]), ratio:0.9919679164886475]
[2020-04-11 18:21:49.380750] INFO: algo: handle_splits get splits [dt:2015-07-17 00:00:00+00:00] [asset:Equity(1112 [002504.SZA]), ratio:0.994036853313446]
[2020-04-11 18:21:49.381675] INFO: Position: position stock handle split[sid:2199, orig_amount:5000, new_amount:5040.0, orig_cost:12.199999813307345, new_cost:12.1, ratio:0.9919679164886475, last_sale_price:12.350000381469727]
[2020-04-11 18:21:49.382466] INFO: Position: after split: PositionStock(asset:Equity(2199 [600240.SHA]), amount:5040.0, cost_basis:12.1, last_sale_price:12.449999809265137)
[2020-04-11 18:21:49.383216] INFO: Position: returning cash: 6.0
[2020-04-11 18:21:49.383974] INFO: Position: position stock handle split[sid:1112, orig_amount:8100, new_amount:8148.0, orig_cost:31.800002379117792, new_cost:31.61, ratio:0.994036853313446, last_sale_price:16.669998168945312]
[2020-04-11 18:21:49.384726] INFO: Position: after split: PositionStock(asset:Equity(1112 [002504.SZA]), amount:8148.0, cost_basis:31.61, last_sale_price:16.770000457763672)
[2020-04-11 18:21:49.385452] INFO: Position: returning cash: 9.86
[2020-04-11 18:21:49.461595] INFO: algo: handle_splits get splits [dt:2015-07-22 00:00:00+00:00] [asset:Equity(2350 [300422.SZA]), ratio:0.9993225336074829]
[2020-04-11 18:21:49.462731] INFO: Position: position stock handle split[sid:2350, orig_amount:1100, new_amount:1100.0, orig_cost:79.50000251835098, new_cost:79.45, ratio:0.9993225336074829, last_sale_price:88.51998901367188]
[2020-04-11 18:21:49.463605] INFO: Position: after split: PositionStock(asset:Equity(2350 [300422.SZA]), amount:1100.0, cost_basis:79.45, last_sale_price:88.58000183105469)
[2020-04-11 18:21:49.464461] INFO: Position: returning cash: 66.01
[2020-04-11 18:21:51.305428] INFO: algo: handle_splits get splits [dt:2015-11-20 00:00:00+00:00] [asset:Equity(1559 [600617.SHA]), ratio:0.994547426700592]
[2020-04-11 18:21:51.306538] INFO: Position: position stock handle split[sid:1559, orig_amount:6500, new_amount:6535.0, orig_cost:17.230000999625133, new_cost:17.14, ratio:0.994547426700592, last_sale_price:18.23999786376953]
[2020-04-11 18:21:51.307396] INFO: Position: after split: PositionStock(asset:Equity(1559 [600617.SHA]), amount:6535.0, cost_basis:17.14, last_sale_price:18.339998245239258)
[2020-04-11 18:21:51.308111] INFO: Position: returning cash: 11.6
[2020-04-11 18:21:53.340368] INFO: algo: handle_splits get splits [dt:2016-04-18 00:00:00+00:00] [asset:Equity(1211 [600116.SHA]), ratio:0.3316228687763214]
[2020-04-11 18:21:53.597869] INFO: algo: handle_splits get splits [dt:2016-05-06 00:00:00+00:00] [asset:Equity(1630 [600654.SHA]), ratio:0.9957947731018066]
[2020-04-11 18:21:53.598982] INFO: Position: position stock handle split[sid:1630, orig_amount:27300, new_amount:27415.0, orig_cost:24.135164995636863, new_cost:24.03, ratio:0.9957947731018066, last_sale_price:23.68000030517578]
[2020-04-11 18:21:53.599848] INFO: Position: after split: PositionStock(asset:Equity(1630 [600654.SHA]), amount:27415.0, cost_basis:24.03, last_sale_price:23.780000686645508)
[2020-04-11 18:21:53.600598] INFO: Position: returning cash: 6.81
[2020-04-11 18:21:53.734313] INFO: algo: handle_splits get splits [dt:2016-05-16 00:00:00+00:00] [asset:Equity(944 [002671.SZA]), ratio:0.9990801215171814]
[2020-04-11 18:21:53.735445] INFO: Position: position stock handle split[sid:944, orig_amount:27800, new_amount:27825.0, orig_cost:10.957932482751426, new_cost:10.95, ratio:0.9990801215171814, last_sale_price:10.860001564025879]
[2020-04-11 18:21:53.736297] INFO: Position: after split: PositionStock(asset:Equity(944 [002671.SZA]), amount:27825.0, cost_basis:10.95, last_sale_price:10.870000839233398)
[2020-04-11 18:21:53.737020] INFO: Position: returning cash: 6.47
[2020-04-11 18:21:54.032814] INFO: algo: handle_splits get splits [dt:2016-06-03 00:00:00+00:00] [asset:Equity(889 [600687.SHA]), ratio:0.9981751441955566]
[2020-04-11 18:21:54.033977] INFO: Position: position stock handle split[sid:889, orig_amount:18400, new_amount:18433.0, orig_cost:16.600002306748827, new_cost:16.57, ratio:0.9981751441955566, last_sale_price:16.40999984741211]
[2020-04-11 18:21:54.034878] INFO: Position: after split: PositionStock(asset:Equity(889 [600687.SHA]), amount:18433.0, cost_basis:16.57, last_sale_price:16.440000534057617)
[2020-04-11 18:21:54.035657] INFO: Position: returning cash: 10.48
[2020-04-11 18:21:54.134104] INFO: algo: handle_splits get splits [dt:2016-06-13 00:00:00+00:00] [asset:Equity(83 [600477.SHA]), ratio:0.7642706632614136]
[2020-04-11 18:21:54.135236] INFO: Position: position stock handle split[sid:83, orig_amount:12700, new_amount:16617.0, orig_cost:9.530002000703572, new_cost:7.28, ratio:0.7642706632614136, last_sale_price:7.229999542236328]
[2020-04-11 18:21:54.136093] INFO: Position: after split: PositionStock(asset:Equity(83 [600477.SHA]), amount:16617.0, cost_basis:7.28, last_sale_price:9.459999084472656)
[2020-04-11 18:21:54.136851] INFO: Position: returning cash: 1.08
[2020-04-11 18:21:54.287635] INFO: algo: handle_splits get splits [dt:2016-06-22 00:00:00+00:00] [asset:Equity(2710 [300192.SZA]), ratio:0.9957805871963501]
[2020-04-11 18:21:54.288739] INFO: Position: position stock handle split[sid:2710, orig_amount:9200, new_amount:9238.0, orig_cost:11.800002975366494, new_cost:11.75, ratio:0.9957805871963501, last_sale_price:11.800000190734863]
[2020-04-11 18:21:54.289589] INFO: Position: after split: PositionStock(asset:Equity(2710 [300192.SZA]), amount:9238.0, cost_basis:11.75, last_sale_price:11.850000381469727)
[2020-04-11 18:21:54.290318] INFO: Position: returning cash: 11.6
[2020-04-11 18:21:54.580341] INFO: algo: handle_splits get splits [dt:2016-07-07 00:00:00+00:00] [asset:Equity(2213 [600039.SHA]), ratio:0.9874686002731323]
[2020-04-11 18:21:54.581704] INFO: algo: handle_splits get splits [dt:2016-07-07 00:00:00+00:00] [asset:Equity(715 [600804.SHA]), ratio:0.9913420081138611]
[2020-04-11 18:21:54.583079] INFO: Position: position stock handle split[sid:2213, orig_amount:27100, new_amount:27443.0, orig_cost:3.9600009209720777, new_cost:3.91, ratio:0.9874686002731323, last_sale_price:3.93999981880188]
[2020-04-11 18:21:54.584398] INFO: Position: after split: PositionStock(asset:Equity(2213 [600039.SHA]), amount:27443.0, cost_basis:3.91, last_sale_price:3.990000009536743)
[2020-04-11 18:21:54.585594] INFO: Position: returning cash: 3.59
[2020-04-11 18:21:57.124683] INFO: Performance: Simulated 488 trading days out of 488.
[2020-04-11 18:21:57.125763] INFO: Performance: first open: 2015-01-05 09:30:00+00:00
[2020-04-11 18:21:57.126565] INFO: Performance: last close: 2016-12-30 15:00:00+00:00
[2020-04-11 18:22:03.223486] INFO: bigquant: backtest.v8 运行完成[19.742499s].
[2020-04-11 18:22:03.225100] INFO: bigquant: trade.v4 运行完成[20.756333s].