克隆策略

    {"Description":"实验创建于2020/7/30","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-24:features","SourceOutputPortId":"-11:data"},{"DestinationInputPortId":"-5:instruments","SourceOutputPortId":"-15:data"},{"DestinationInputPortId":"-24:input_data","SourceOutputPortId":"-36:data_1"},{"DestinationInputPortId":"-36:input_1","SourceOutputPortId":"-5:data"}],"ModuleNodes":[{"Id":"-11","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nta_bbands_l(close, 2)","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-11"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-11","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"-15","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2018-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":"000001.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":"-15"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-15","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-24","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":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-24"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-24"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-24","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-36","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n \n # 先获取股票的日线数据\n daily_data = input_1.read()[[\"close\", \"open\", \"high\", \"low\", \"date\", \"instrument\"]]\n# daily_data = DataSource(\"bar1d_CN_STOCK_A\").read(\"000001.SZA\", start_date=\"2018-01-01\", end_date=\"2019-01-01\", fields=[\"close\", \"open\", \"high\", \"low\", \"date\", \"instrument\"])\n\n # 获取交易日周索引\n index_ = daily_data.resample(\"W\", how=\"first\", on=\"date\").set_index(\"date\").index\n\n # 进行resample,注意高开低收的各个resample规则不同,需要分开处理\n daily_data.set_index(\"date\", inplace=True)\n daily_data_close = daily_data.resample(\"W\", label=\"left\", how=\"last\")[\"close\"]\n daily_data_open = daily_data.resample(\"W\", label=\"left\", how=\"first\")[\"open\"]\n daily_data_high = daily_data.resample(\"W\", label=\"left\", how=\"max\")[\"high\"]\n daily_data_low = daily_data.resample(\"W\", label=\"left\", how=\"min\")['low']\n daily_data_instrument = daily_data.resample(\"W\", label=\"left\", how=\"first\")['instrument']\n\n week_data = pd.DataFrame({\"instrument\": daily_data_instrument.values, \"close\": daily_data_close.values, \"open\": daily_data_open.values, \"high\": daily_data_high.values, \"low\":daily_data_low.values, \"date\": index_}, index=index_)\n\n # 删除nan\n week_data.dropna(how=\"any\", inplace=True, axis=0)\n\n data_1 = DataSource.write_df(week_data)\n return Outputs(data_1=data_1)\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":"-36"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-36"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-36"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-36","OutputType":null},{"Name":"data_2","NodeId":"-36","OutputType":null},{"Name":"data_3","NodeId":"-36","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-5","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"bar1d_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2019-01-01","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-5"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-5"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-5","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"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='-11' Position='989.6666259765625,290,200,200'/><NodePosition Node='-15' Position='571.6666259765625,297,200,200'/><NodePosition Node='-24' Position='781.6666259765625,679,200,200'/><NodePosition Node='-36' Position='774.6666259765625,548,200,200'/><NodePosition Node='-5' Position='784.6666259765625,425,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 [49]:
    # 本代码由可视化策略环境自动生成 2020年7月30日 10:56
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m5_run_bigquant_run(input_1, input_2, input_3):
        
        # 先获取股票的日线数据
        daily_data = input_1.read()[["close", "open", "high", "low", "date", "instrument"]]
    #     daily_data = DataSource("bar1d_CN_STOCK_A").read("000001.SZA", start_date="2018-01-01", end_date="2019-01-01", fields=["close", "open", "high", "low", "date", "instrument"])
    
        # 获取交易日周索引
        index_ = daily_data.resample("W", how="first", on="date").set_index("date").index
    
        # 进行resample,注意高开低收的各个resample规则不同,需要分开处理
        daily_data.set_index("date", inplace=True)
        daily_data_close = daily_data.resample("W", label="left", how="last")["close"]
        daily_data_open = daily_data.resample("W", label="left", how="first")["open"]
        daily_data_high = daily_data.resample("W", label="left", how="max")["high"]
        daily_data_low = daily_data.resample("W", label="left", how="min")['low']
        daily_data_instrument = daily_data.resample("W", label="left", how="first")['instrument']
    
        week_data = pd.DataFrame({"instrument": daily_data_instrument.values, "close": daily_data_close.values, "open": daily_data_open.values, "high": daily_data_high.values, "low":daily_data_low.values, "date": index_}, index=index_)
    
        # 删除nan
        week_data.dropna(how="any", inplace=True, axis=0)
    
        data_1 = DataSource.write_df(week_data)
        return Outputs(data_1=data_1)
        
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m5_post_run_bigquant_run(outputs):
        return outputs
    
    
    m2 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    ta_bbands_l(close, 2)"""
    )
    
    m3 = M.instruments.v2(
        start_date='2018-01-01',
        end_date='2019-01-01',
        market='CN_STOCK_A',
        instrument_list='000001.SZA',
        max_count=0
    )
    
    m1 = M.use_datasource.v1(
        instruments=m3.data,
        datasource_id='bar1d_CN_STOCK_A',
        start_date='2018-01-01',
        end_date='2019-01-01'
    )
    
    m5 = M.cached.v3(
        input_1=m1.data,
        run=m5_run_bigquant_run,
        post_run=m5_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m4 = M.derived_feature_extractor.v3(
        input_data=m5.data_1,
        features=m2.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=True,
        user_functions={}
    )