克隆策略

    {"Description":"实验创建于2017/11/27","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-17:instruments","SourceOutputPortId":"-4:data"},{"DestinationInputPortId":"-30:instruments","SourceOutputPortId":"-4:data"},{"DestinationInputPortId":"-17:features","SourceOutputPortId":"-12:data"},{"DestinationInputPortId":"-24:input_data","SourceOutputPortId":"-17:data"},{"DestinationInputPortId":"-30:options_data","SourceOutputPortId":"-24:data"}],"ModuleNodes":[{"Id":"-4","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2013-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2017-11-27","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":"-4"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-4","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"Comment":"","CommentCollapsed":true},{"Id":"-12","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"rank_pb_lf_0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-12"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-12","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"-17","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v6","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-17"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-17"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-17","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-24","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"rank_pb_lf_0<=0.1","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_left_data","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-24"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-24","OutputType":null},{"Name":"left_data","NodeId":"-24","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-30","ModuleId":"BigQuantSpace.trade.trade-v3","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n\t\n\tif context.trading_day_index % 22 !=0:\n\t\treturn\n\t# 按日期过滤得到当日的数据\n\tcur_data = context.data[context.data.date==data.current_dt.strftime('%Y-%m-%d')]\n\tbuy_stock = list(cur_data['instrument']) # 选出市净率最小的10%股票列表\n\t\n\t# 持仓股票列表,为字符串\n\tequities = {e.symbol :p for e,p in context.portfolio.positions.items() if p.amount>0}\n\tfor instrument in equities:\n\t\tif data.can_trade(context.symbol(instrument)):\n\t\t\tcontext.order_target_percent(context.symbol(instrument),0)\n\t# 买入股票\n\tfor i in buy_stock:\n\t\tif data.can_trade(context.symbol(i)):\n\t\t\tcontext.order_target_percent(context.symbol(i), 1/len(buy_stock)) # 等权重买入\n\t\n\t\t\t\n\t ","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"prepare","Value":"# 回测引擎:准备数据,只执行一次\ndef bigquant_run(context):\n pass\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"initialize","Value":"# 回测引擎:初始化函数,只执行一次\ndef bigquant_run(context):\n # 加载预测数据\n context.data = context.options['data'].read_df()\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 = 30\n \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":"open","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"capital_base","Value":"1000000","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"000300.SHA","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"auto_cancel_non_tradable_orders","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"data_frequency","Value":"daily","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"plot_charts","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"backtest_only","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-30"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-30"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-30","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":5,"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='-4' Position='84,110.44477844238281,200,200'/><NodePosition Node='-12' Position='385.97657775878906,117.28346252441406,200,200'/><NodePosition Node='-17' Position='254.0958251953125,224.250732421875,200,200'/><NodePosition Node='-24' Position='242.70773315429688,342.6867370605469,200,200'/><NodePosition Node='-30' Position='74.16421508789062,477.0660095214844,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 [17]:
    # 本代码由可视化策略环境自动生成 2017年11月28日 09:18
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m1 = M.instruments.v2(
        start_date='2013-01-01',
        end_date='2017-11-27',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m2 = M.input_features.v1(
        features='rank_pb_lf_0'
    )
    
    m3 = M.general_feature_extractor.v6(
        instruments=m1.data,
        features=m2.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m4 = M.filter.v3(
        input_data=m3.data,
        expr='rank_pb_lf_0<=0.1',
        output_left_data=False
    )
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m5_handle_data_bigquant_run(context, data):
    	
    	if context.trading_day_index % 22 !=0:
    		return
    	# 按日期过滤得到当日的数据
    	cur_data = context.data[context.data.date==data.current_dt.strftime('%Y-%m-%d')]
    	buy_stock = list(cur_data['instrument']) # 选出市净率最小的10%股票列表
    	
    	# 持仓股票列表,为字符串
    	equities = {e.symbol :p for e,p in context.portfolio.positions.items() if p.amount>0}
    	for instrument in equities:
    		if data.can_trade(context.symbol(instrument)):
    			context.order_target_percent(context.symbol(instrument),0)
    	# 买入股票
    	for i  in buy_stock:
    		if data.can_trade(context.symbol(i)):
    			context.order_target_percent(context.symbol(i), 1/len(buy_stock)) # 等权重买入
    	
    			
    	 
    # 回测引擎:准备数据,只执行一次
    def m5_prepare_bigquant_run(context):
        pass
    
    # 回测引擎:初始化函数,只执行一次
    def m5_initialize_bigquant_run(context):
        # 加载预测数据
        context.data = 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 = 30
         
    
    # 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。
    def m5_before_trading_start_bigquant_run(context, data):
        pass
    
    m5 = M.trade.v3(
        instruments=m1.data,
        options_data=m4.data,
        start_date='',
        end_date='',
        handle_data=m5_handle_data_bigquant_run,
        prepare=m5_prepare_bigquant_run,
        initialize=m5_initialize_bigquant_run,
        before_trading_start=m5_before_trading_start_bigquant_run,
        volume_limit=0,
        order_price_field_buy='open',
        order_price_field_sell='open',
        capital_base=1000000,
        benchmark='000300.SHA',
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        plot_charts=True,
        backtest_only=False
    )
    
    [2017-11-28 09:13:00.085405] INFO: bigquant: instruments.v2 开始运行..
    [2017-11-28 09:13:00.088732] INFO: bigquant: 命中缓存
    [2017-11-28 09:13:00.090226] INFO: bigquant: instruments.v2 运行完成[0.00485s].
    [2017-11-28 09:13:00.094569] INFO: bigquant: input_features.v1 开始运行..
    [2017-11-28 09:13:00.097016] INFO: bigquant: 命中缓存
    [2017-11-28 09:13:00.098065] INFO: bigquant: input_features.v1 运行完成[0.003494s].
    [2017-11-28 09:13:00.104386] INFO: bigquant: general_feature_extractor.v6 开始运行..
    [2017-11-28 09:13:00.106497] INFO: bigquant: 命中缓存
    [2017-11-28 09:13:00.107487] INFO: bigquant: general_feature_extractor.v6 运行完成[0.003161s].
    [2017-11-28 09:13:00.113516] INFO: bigquant: filter.v3 开始运行..
    [2017-11-28 09:13:00.115629] INFO: bigquant: 命中缓存
    [2017-11-28 09:13:00.116673] INFO: bigquant: filter.v3 运行完成[0.003135s].
    [2017-11-28 09:13:00.138185] INFO: bigquant: backtest.v7 开始运行..
    [2017-11-28 09:14:58.308032] INFO: Performance: Simulated 1191 trading days out of 1191.
    [2017-11-28 09:14:58.309222] INFO: Performance: first open: 2013-01-04 14:30:00+00:00
    [2017-11-28 09:14:58.310044] INFO: Performance: last close: 2017-11-27 20:00:00+00:00
    
    • 收益率77.38%
    • 年化收益率12.89%
    • 基准收益率62.67%
    • 阿尔法0.05
    • 贝塔0.53
    • 夏普比率0.56
    • 收益波动率15.2%
    • 信息比率0.15
    • 最大回撤21.68%
    [2017-11-28 09:15:07.277174] INFO: bigquant: backtest.v7 运行完成[127.138946s].