克隆策略

    {"Description":"实验创建于2020/2/14","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-64:input_2","SourceOutputPortId":"-666:data"},{"DestinationInputPortId":"-51:input_1","SourceOutputPortId":"-269:data"},{"DestinationInputPortId":"-77:input_data","SourceOutputPortId":"-51:data_1"},{"DestinationInputPortId":"-64:input_1","SourceOutputPortId":"-77:data"}],"ModuleNodes":[{"Id":"-666","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nf12 = close/shift(close, 44) - 1\n# f13 = close/open\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-666"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-666","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-269","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"bar1d_CN_FUTURE","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2020-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2021-04-30","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-269"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-269"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-269","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"Comment":"","CommentCollapsed":true},{"Id":"-51","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, start_date, end_date, filter_contract, table_name):\n # 示例代码如下。在这里编写您的代码\n import re\n import time\n import bigexpr\n from bigshared.common.biglogger import BigLogger\n \n log = BigLogger('DataProcess')\n\n class DataProcess:\n def __init__(\n self, \n log, \n start_date=None,\n end_date=None,\n filter_contract=['IF', 'IC', 'IH', 'FB', 'JR', 'BB', 'AL', 'PM'],\n table_name='bar1d_CN_FUTURE'\n ):\n self.log = log\n self.start_date = start_date\n self.end_date = end_date\n self.filter_contract = filter_contract\n self.table_name = table_name\n\n def data_preprocessing(self, df):\n # 读取期货日线数据\n self.log.info(\"load_continus_instrument start ...\")\n # 向前提取120天的数据\n _start_date = (pd.Timestamp(self.start_date) - datetime.timedelta(120)).strftime('%Y-%m-%d')\n df = df[(df.date >= _start_date) & (df.date <= self.end_date)].reset_index()\n is_live_run = T.live_run_param(\"trading_date\", None) is not None\n if is_live_run:\n self.end_date = T.live_run_param(\"trading_date\", \"trading_date\")\n df = DataSource(self.table_name).read(start_date=_start_date, end_date=self.end_date)\n\n df[\"exchange\"] = df[\"instrument\"].apply(lambda x: x.split(\".\")[-1]) # 交易所\n df[\"contract\"] = df[\"instrument\"].apply(lambda x: x.split(\".\")[0]) # 合约代码\n df[\"future_name\"] = df[\"contract\"].apply(lambda x: re.sub(\"[^a-zA-Z]\", \"\", x)) # 期货品种\n df[\"contract_info\"] = df[\"contract\"].apply(lambda x: x[-4:])\n continus_contract_df = df[df[\"contract_info\"] == \"0000\"] # 将主力合约数据过滤出来\n continus_contract_df = continus_contract_df[~continus_contract_df.future_name.isin(self.filter_contract)] # 过滤对应的品种\n self.log.info(\"load_continus_instrument done\")\n return continus_contract_df\n\n def process(self, df):\n # 判断数据处理是否有传入起止日期,有则更新\n if self.start_date is None:\n self.start_date = df.date.min().strftime('%Y-%m-%d')\n if self.end_date is None:\n self.end_date = df.date.max().strftime('%Y-%m-%d')\n # 对进行因子分析的数据进行预处理\n continus_contract_df = self.data_preprocessing(df)\n return continus_contract_df\n \n df = input_1.read()\n dp = DataProcess(log, start_date, end_date, filter_contract, table_name)\n continus_contract_df = dp.process(df)\n data_1 = DataSource.write_df(continus_contract_df[['date','instrument','close','amount']])\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":"{\n \"start_date\": None,\n \"end_date\": None,\n \"filter_contract\": ['IF', 'IC', 'IH', 'FB', 'JR', 'BB', 'AL', 'PM'],\n \"table_name\": \"bar1d_CN_FUTURE\"\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-51"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-51"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-51"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-51","OutputType":null},{"Name":"data_2","NodeId":"-51","OutputType":null},{"Name":"data_3","NodeId":"-51","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-64","ModuleId":"BigQuantSpace.FactorA.FactorA-v1","ModuleParameters":[{"Name":"start_date","Value":"2016-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2021-04-30","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"rabalance_period","Value":22,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"buy_commission_rate","Value":0.0005,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"sell_commission_rate","Value":0.0005,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"ic_method","Value":"Rank_IC","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"quantile_num","Value":5,"ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"is_standardlize","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"is_winsorize","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-64"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-64"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-64","OutputType":null},{"Name":"data_2","NodeId":"-64","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-77","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"amount>3000000","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":"-77"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-77","OutputType":null},{"Name":"left_data","NodeId":"-77","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='-666' Position='-117.81468963623047,114.22203063964844,200,200'/><NodePosition Node='-269' Position='-630.1485900878906,105.55594635009766,200,200'/><NodePosition Node='-51' Position='-548.1853332519531,224.40736389160156,200,200'/><NodePosition Node='-64' Position='-324.73777770996094,441.07342529296875,200,200'/><NodePosition Node='-77' Position='-445.81468200683594,326.0367126464844,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 [28]:
    # 本代码由可视化策略环境自动生成 2021年5月11日17:53
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m3_run_bigquant_run(input_1, input_2, input_3, start_date, end_date, filter_contract, table_name):
        # 示例代码如下。在这里编写您的代码
        import re
        import time
        import bigexpr
        from bigshared.common.biglogger import BigLogger
        
        log = BigLogger('DataProcess')
    
        class DataProcess:
            def __init__(
                self, 
                log, 
                start_date=None,
                end_date=None,
                filter_contract=['IF', 'IC', 'IH', 'FB', 'JR', 'BB', 'AL', 'PM'],
                table_name='bar1d_CN_FUTURE'
                ):
                self.log = log
                self.start_date = start_date
                self.end_date = end_date
                self.filter_contract = filter_contract
                self.table_name = table_name
    
            def data_preprocessing(self, df):
                # 读取期货日线数据
                self.log.info("load_continus_instrument start ...")
                # 向前提取120天的数据
                _start_date = (pd.Timestamp(self.start_date) - datetime.timedelta(120)).strftime('%Y-%m-%d')
                df = df[(df.date >= _start_date) & (df.date <= self.end_date)].reset_index()
                is_live_run = T.live_run_param("trading_date", None) is not None
                if is_live_run:
                    self.end_date = T.live_run_param("trading_date", "trading_date")
                    df = DataSource(self.table_name).read(start_date=_start_date, end_date=self.end_date)
    
                df["exchange"] = df["instrument"].apply(lambda x: x.split(".")[-1])  # 交易所
                df["contract"] = df["instrument"].apply(lambda x: x.split(".")[0])  # 合约代码
                df["future_name"] = df["contract"].apply(lambda x: re.sub("[^a-zA-Z]", "", x))  # 期货品种
                df["contract_info"] = df["contract"].apply(lambda x: x[-4:])
                continus_contract_df = df[df["contract_info"] == "0000"]  # 将主力合约数据过滤出来
                continus_contract_df = continus_contract_df[~continus_contract_df.future_name.isin(self.filter_contract)]  # 过滤对应的品种
                self.log.info("load_continus_instrument done")
                return continus_contract_df
    
            def process(self, df):
                # 判断数据处理是否有传入起止日期,有则更新
                if self.start_date is None:
                    self.start_date = df.date.min().strftime('%Y-%m-%d')
                if self.end_date is None:
                    self.end_date = df.date.max().strftime('%Y-%m-%d')
                # 对进行因子分析的数据进行预处理
                continus_contract_df = self.data_preprocessing(df)
                return continus_contract_df
        
        df = input_1.read()
        dp = DataProcess(log, start_date, end_date, filter_contract, table_name)
        continus_contract_df = dp.process(df)
        data_1 = DataSource.write_df(continus_contract_df[['date','instrument','close','amount']])
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m3_post_run_bigquant_run(outputs):
        return outputs
    
    
    m5 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    f12 = close/shift(close, 44) - 1
    # f13 = close/open
    """,
        m_cached=False
    )
    
    m7 = M.use_datasource.v1(
        datasource_id='bar1d_CN_FUTURE',
        start_date='2020-01-01',
        end_date='2021-04-30'
    )
    
    m3 = M.cached.v3(
        input_1=m7.data,
        run=m3_run_bigquant_run,
        post_run=m3_post_run_bigquant_run,
        input_ports='',
        params="""{
        "start_date": None,
        "end_date": None,
        "filter_contract": ['IF', 'IC', 'IH', 'FB', 'JR', 'BB', 'AL', 'PM'],
        "table_name": "bar1d_CN_FUTURE"
    }""",
        output_ports=''
    )
    
    m1 = M.filter.v3(
        input_data=m3.data_1,
        expr='amount>3000000',
        output_left_data=False
    )
    
    m4 = M.FactorA.v1(
        input_1=m1.data,
        input_2=m5.data,
        start_date='2016-01-01',
        end_date='2021-04-30',
        rabalance_period=22,
        buy_commission_rate=0.0005,
        sell_commission_rate=0.0005,
        ic_method='Rank_IC',
        quantile_num=5,
        is_standardlize=True,
        is_winsorize=True
    )
    

    f12: IC分析

    • IC均值-0.0964
    • IC标准差0.2175
    • ICIR-0.4432
    • IC正值次数4次
    • IC负值次数8次
    • IC偏度-0.9562
    • IC峰度1.8658

    f12: 因子收益率分析

    • 因子收益均值-0.0079
    • 因子收益标准差0.0128
    • 因子收益为正比率33.33%
    • t值绝对值的均值1.5907
    • t值绝对值大于2的比率0.25
    • 因子收益t检验p值小于0.05的比率0.25

    f12: 因子绩效分析

    •   top0_ret top4_ret
    • 收益率 0.3814 0.2872
    • 近1日收益率 -0.0068 -0.0029
    • 近1周收益率 0.0034 0.0272
    • 近1月收益率 0.0452 0.0712
    • 年化收益率 0.3417 0.2582
    • 夏普比率 1.6342 1.2626
    • 收益波动率 0.167 0.165
    • 最大回撤 -0.1228 -0.107