克隆策略

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-580:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-587:input_data","SourceOutputPortId":"-580:data"},{"DestinationInputPortId":"-643:input_1","SourceOutputPortId":"-580:data"},{"DestinationInputPortId":"-659:data2","SourceOutputPortId":"-587:data"},{"DestinationInputPortId":"-580:features","SourceOutputPortId":"-635:data"},{"DestinationInputPortId":"-587:features","SourceOutputPortId":"-635:data"},{"DestinationInputPortId":"-659:data1","SourceOutputPortId":"-643:data_1"},{"DestinationInputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-84:input_data","SourceOutputPortId":"-659:data"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2010-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2015-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,"Comment":"","CommentCollapsed":true},{"Id":"-580","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":"-580"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-580"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-580","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"Comment":"","CommentCollapsed":true},{"Id":"-587","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":"-587"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-587"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-587","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"Comment":"","CommentCollapsed":true},{"Id":"-635","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nclose_0\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-635"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-635","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":20,"Comment":"","CommentCollapsed":true},{"Id":"-643","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 input_df = input_1.read_df().reset_index(drop='True')\n import talib\n def cal_macd(df):\n # 取出close_0列的数据转化为float\n close = [float(x) for x in df['close_0']]\n # 调用talib计算MACD指标\n df['MACD'],df['MACDsignal'],df['MACDhist'] = talib.MACD(np.array(close),\n fastperiod=6, slowperiod=12, signalperiod=9)\n return df[['date','instrument','MACD','MACDsignal','MACDhist']]\n \n result = input_df.groupby('instrument').apply(cal_macd)\n \n data_1 = DataSource.write_df(result)\n return Outputs(data_1=data_1, data_2=None, 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":"-643"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-643"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-643"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-643","OutputType":null},{"Name":"data_2","NodeId":"-643","OutputType":null},{"Name":"data_3","NodeId":"-643","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":21,"Comment":"使用TALIB计算MACD","CommentCollapsed":false},{"Id":"-659","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":"-659"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-659"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-659","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":22,"Comment":"","CommentCollapsed":true},{"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,"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='226.37481689453125,52.261558532714844,200,200'/><NodePosition Node='-580' Position='377.7903747558594,151.25201416015625,200,200'/><NodePosition Node='-587' Position='540.322509765625,270.78599548339844,200,200'/><NodePosition Node='-635' Position='571.5236206054688,55.174461364746094,200,200'/><NodePosition Node='-643' Position='218.75726318359375,247.35305786132812,200,200'/><NodePosition Node='-659' Position='386.6422424316406,368.4423828125,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-84' Position='399.6933288574219,447.2556457519531,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 [41]:
    # 本代码由可视化策略环境自动生成 2019年1月31日 17:49
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m21_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        input_df = input_1.read_df().reset_index(drop='True')
        import talib
        def cal_macd(df):
            # 取出close_0列的数据转化为float
            close = [float(x) for x in df['close_0']]
             # 调用talib计算MACD指标
            df['MACD'],df['MACDsignal'],df['MACDhist'] = talib.MACD(np.array(close),
                                        fastperiod=6, slowperiod=12, signalperiod=9)
            return df[['date','instrument','MACD','MACDsignal','MACDhist']]
        
        result = input_df.groupby('instrument').apply(cal_macd)
        
        data_1 = DataSource.write_df(result)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m21_post_run_bigquant_run(outputs):
        return outputs
    
    
    m1 = M.instruments.v2(
        start_date='2010-01-01',
        end_date='2015-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m20 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    close_0
    """
    )
    
    m15 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m20.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m21 = M.cached.v3(
        input_1=m15.data,
        run=m21_run_bigquant_run,
        post_run=m21_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m16 = M.derived_feature_extractor.v3(
        input_data=m15.data,
        features=m20.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    m22 = M.join.v3(
        data1=m21.data_1,
        data2=m16.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m13 = M.dropnan.v1(
        input_data=m22.data
    )
    
    [2019-01-31 17:45:07.663917] INFO: bigquant: instruments.v2 开始运行..
    [2019-01-31 17:45:07.669900] INFO: bigquant: 命中缓存
    [2019-01-31 17:45:07.670841] INFO: bigquant: instruments.v2 运行完成[0.006965s].
    [2019-01-31 17:45:07.673695] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-31 17:45:07.681969] INFO: bigquant: 命中缓存
    [2019-01-31 17:45:07.683245] INFO: bigquant: input_features.v1 运行完成[0.009545s].
    [2019-01-31 17:45:07.689325] INFO: bigquant: general_feature_extractor.v7 开始运行..
    [2019-01-31 17:45:07.696939] INFO: bigquant: 命中缓存
    [2019-01-31 17:45:07.697871] INFO: bigquant: general_feature_extractor.v7 运行完成[0.008527s].
    [2019-01-31 17:45:07.704312] INFO: bigquant: cached.v3 开始运行..
    [2019-01-31 17:45:18.872392] INFO: bigquant: cached.v3 运行完成[11.168057s].
    [2019-01-31 17:45:18.875762] INFO: bigquant: derived_feature_extractor.v3 开始运行..
    [2019-01-31 17:45:20.465143] INFO: derived_feature_extractor: /y_2010, 431567
    [2019-01-31 17:45:20.768943] INFO: derived_feature_extractor: /y_2011, 511455
    [2019-01-31 17:45:21.135752] INFO: derived_feature_extractor: /y_2012, 565675
    [2019-01-31 17:45:21.655776] INFO: derived_feature_extractor: /y_2013, 564168
    [2019-01-31 17:45:22.072901] INFO: derived_feature_extractor: /y_2014, 569948
    [2019-01-31 17:45:22.378375] INFO: bigquant: derived_feature_extractor.v3 运行完成[3.502607s].
    [2019-01-31 17:45:22.381415] INFO: bigquant: join.v3 开始运行..
    [2019-01-31 17:45:24.299289] INFO: join: /y_2010, 行数=431567/431567, 耗时=1.122331s
    [2019-01-31 17:45:25.419830] INFO: join: /y_2011, 行数=511455/511455, 耗时=1.10641s
    [2019-01-31 17:45:26.594084] INFO: join: /y_2012, 行数=565675/565675, 耗时=1.158063s
    [2019-01-31 17:45:27.796419] INFO: join: /y_2013, 行数=564168/564168, 耗时=1.184346s
    [2019-01-31 17:45:29.170091] INFO: join: /y_2014, 行数=569948/569948, 耗时=1.355755s
    [2019-01-31 17:45:29.293802] INFO: join: 最终行数: 2642813
    [2019-01-31 17:45:29.295900] INFO: bigquant: join.v3 运行完成[6.914494s].
    [2019-01-31 17:45:29.298477] INFO: bigquant: dropnan.v1 开始运行..
    [2019-01-31 17:45:29.713939] INFO: dropnan: /y_2010, 393502/431567
    [2019-01-31 17:45:30.162625] INFO: dropnan: /y_2011, 505840/511455
    [2019-01-31 17:45:30.659738] INFO: dropnan: /y_2012, 562476/565675
    [2019-01-31 17:45:31.145791] INFO: dropnan: /y_2013, 563950/564168
    [2019-01-31 17:45:31.652441] INFO: dropnan: /y_2014, 567723/569948
    [2019-01-31 17:45:31.674068] INFO: dropnan: 行数: 2593491/2642813
    [2019-01-31 17:45:31.693321] INFO: bigquant: dropnan.v1 运行完成[2.394807s].
    
    In [40]:
    m13.data.read_df().tail()
    
    Out[40]:
    avg_amount_0 avg_amount_20 avg_amount_5 close_0 date high_0 instrument low_0 open_0 pe_ttm_0 ... return_5 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_5/rank_return_10 MACD MACDsignal MACDhist
    569924 115845848.0 278431424.0 260763808.0 9.194961 2014-12-25 9.216002 603993.SHA 8.995070 9.047673 25.542309 ... 0.963616 0.444256 0.936546 0.829335 1.089074 1.224373 1.043712 -0.069211 0.074874 -0.144085
    569925 158212880.0 268589568.0 242966320.0 9.500056 2014-12-26 9.521098 603993.SHA 9.163399 9.226522 26.389822 ... 0.975162 0.651172 0.904601 0.907938 1.060199 1.471127 0.874923 -0.050436 0.049812 -0.100248
    569926 161283680.0 260739424.0 227736240.0 9.331728 2014-12-29 9.636824 603993.SHA 9.205482 9.531618 25.922228 ... 0.943617 0.708204 0.873425 0.861498 1.049152 1.394681 0.647383 -0.059068 0.028036 -0.087104
    569927 135136800.0 247709840.0 177105072.0 9.216002 2014-12-30 9.573701 603993.SHA 8.995070 9.363290 25.600758 ... 0.885743 0.763032 0.714970 0.899249 0.979263 10.509239 0.080352 -0.076949 0.007039 -0.083988
    569928 96034368.0 239076464.0 146462048.0 9.205482 2014-12-31 9.363290 603993.SHA 8.952988 9.216002 25.571533 ... 0.983146 0.655695 0.612616 0.861966 0.922409 0.890834 0.442120 -0.085761 -0.011521 -0.074240

    5 rows × 28 columns