test232323232323

新手专区
标签: #<Tag:0x00007f48f8a23990>

(desperate1) #1
克隆策略

    {"Description":"实验创建于2019/7/10","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-213:options_data","SourceOutputPortId":"-3071:data"},{"DestinationInputPortId":"-213:instruments","SourceOutputPortId":"-2172:data"},{"DestinationInputPortId":"-66:input_2","SourceOutputPortId":"-2172:data"},{"DestinationInputPortId":"-66:input_1","SourceOutputPortId":"-49:data"},{"DestinationInputPortId":"-3071:input_data","SourceOutputPortId":"-66:data_1"}],"ModuleNodes":[{"Id":"-3071","ModuleId":"BigQuantSpace.dropnan.dropnan-v1","ModuleParameters":[],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-3071"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-3071","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-213","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.pre_act = context.options['data'].read_df()\n # 系统已经设置了默认的交易手续费和滑点,要修改手续()费可使用如下函数\n context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))\n \n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"handle_data","Value":"# 回测引擎:每日数据处理函数,每天执行一次\ndef bigquant_run(context, data):\n sid = context.symbol(context.instruments[0])\n \n action = context.pre_act[context.pre_act['date'] == data.current_dt.strftime('%Y-%m-%d')]\n \n # 持仓\n cur_position = context.portfolio.positions[sid].amount \n \n if len(action['pre_action'])>0:\n\n if int(action['pre_action'])==0 and cur_position ==0:\n #cur_position=cur_position+1\n context.order_target_percent(sid, 1)\n elif int(action['pre_action'])==1 and cur_position > 0:\n context.order_target_percent(sid, 0)\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":"open","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":"000300.SHA","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-213"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"options_data","NodeId":"-213"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"history_ds","NodeId":"-213"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"benchmark_ds","NodeId":"-213"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"trading_calendar","NodeId":"-213"}],"OutputPortsInternal":[{"Name":"raw_perf","NodeId":"-213","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":3,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-2172","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2016-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":"000004.SZA","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-2172"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-2172","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-49","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2010-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2016-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"000004.SZA","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-49"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-49","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-66","ModuleId":"BigQuantSpace.DQN_tf2.DQN_tf2-v1","ModuleParameters":[{"Name":"batch_size","Value":32,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"window_size","Value":5,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"total_episode","Value":5,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"epsilon_decay","Value":"0.995","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"learning_rate","Value":"0.1","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"gamma","Value":0.95,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-66"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-66"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-66","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"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='-3071' Position='-201,427,200,200'/><NodePosition Node='-213' Position='-96,525,200,200'/><NodePosition Node='-2172' Position='-30,205,200,200'/><NodePosition Node='-49' Position='-369,212,200,200'/><NodePosition Node='-66' Position='-253,315,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 [ ]:
    # 本代码由可视化策略环境自动生成 2020年6月10日 10:57
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # 回测引擎:初始化函数,只执行一次
    def m3_initialize_bigquant_run(context):
        # 加载预测数据
        context.pre_act = context.options['data'].read_df()
        # 系统已经设置了默认的交易手续费和滑点,要修改手续()费可使用如下函数
        context.set_commission(PerOrder(buy_cost=0.0003, sell_cost=0.0013, min_cost=5))
         
    
    # 回测引擎:每日数据处理函数,每天执行一次
    def m3_handle_data_bigquant_run(context, data):
        sid = context.symbol(context.instruments[0])
        
        action = context.pre_act[context.pre_act['date'] == data.current_dt.strftime('%Y-%m-%d')]
        
        # 持仓
        cur_position = context.portfolio.positions[sid].amount 
        
        if len(action['pre_action'])>0:
    
            if int(action['pre_action'])==0 and cur_position ==0:
                #cur_position=cur_position+1
                context.order_target_percent(sid, 1)
            elif int(action['pre_action'])==1 and cur_position > 0:
                context.order_target_percent(sid, 0)
    
    # 回测引擎:准备数据,只执行一次
    def m3_prepare_bigquant_run(context):
        pass
    
    # 回测引擎:每个单位时间开始前调用一次,即每日开盘前调用一次。
    def m3_before_trading_start_bigquant_run(context, data):
        pass
    
    
    m4 = M.instruments.v2(
        start_date='2016-01-01',
        end_date='2017-01-01',
        market='CN_STOCK_A',
        instrument_list='000004.SZA',
        max_count=0
    )
    
    m1 = M.instruments.v2(
        start_date='2010-01-01',
        end_date='2016-01-01',
        market='CN_STOCK_A',
        instrument_list='000004.SZA',
        max_count=0
    )
    
    m7 = M.DQN_tf2.v1(
        input_1=m1.data,
        input_2=m4.data,
        batch_size=32,
        window_size=5,
        total_episode=5,
        epsilon_decay=0.995,
        learning_rate=0.1,
        gamma=0.95
    )
    
    m2 = M.dropnan.v1(
        input_data=m7.data_1
    )
    
    m3 = M.trade.v4(
        instruments=m4.data,
        options_data=m2.data,
        start_date='',
        end_date='',
        initialize=m3_initialize_bigquant_run,
        handle_data=m3_handle_data_bigquant_run,
        prepare=m3_prepare_bigquant_run,
        before_trading_start=m3_before_trading_start_bigquant_run,
        volume_limit=0.025,
        order_price_field_buy='open',
        order_price_field_sell='open',
        capital_base=100000,
        auto_cancel_non_tradable_orders=True,
        data_frequency='daily',
        price_type='真实价格',
        product_type='股票',
        plot_charts=True,
        backtest_only=False,
        benchmark='000300.SHA'
    )
    
    本次验证的股票标的为: 000004.SZA
    episode: 0