强烈建议单因子分析模块增加调仓天数的更多选择


(netsophier) #1

目前本平台提供的单因子分析功能都是默认月度调仓。但是现在策略天梯上的策略几乎都是高频轮仓,采用的因子也一般是短周期价量因子,而这些因子的IC在月度方面基本上衰减到可以忽略不计了。所以平台上面的单因子分析对于这类短周期因子而言就很鸡肋。目前做策略为了分析这些短周期单因子,都不得不迁移到其他平台上自己编写因子,借用他们的单因子分析来测试。而其他平台又没有大宽很方便的因子表达式可供选择。
所以建议单因子分析模块可以做出改进,例如可以提供5天轮仓、月度轮仓等多种轮仓条件下的因子分析。这样可以极大方便因子开发,提升平台用户体验。


(iQuant) #2

您好,收到您的反馈,我们会将此条建议进行提交,感谢反馈。


(达达) #3

你可以自己尝试调节resample的周期,这里给一个周线级别的例子。

克隆策略

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-215:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-160:instruments","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-8:data"},{"DestinationInputPortId":"-190:features_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-121:input_2","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-220:features","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-245:columns_ds","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-277:input_2","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-151:input_2","SourceOutputPortId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24:data"},{"DestinationInputPortId":"-222:input_data","SourceOutputPortId":"-215:data"},{"DestinationInputPortId":"-165:input_1","SourceOutputPortId":"-222:data"},{"DestinationInputPortId":"-220:input_data","SourceOutputPortId":"-121:data"},{"DestinationInputPortId":"-145:input_1","SourceOutputPortId":"-165:data"},{"DestinationInputPortId":"-215:features","SourceOutputPortId":"-190:data"},{"DestinationInputPortId":"-222:features","SourceOutputPortId":"-190:data"},{"DestinationInputPortId":"-165:input_2","SourceOutputPortId":"-190:data"},{"DestinationInputPortId":"-245:input_ds","SourceOutputPortId":"-220:data"},{"DestinationInputPortId":"-277:input_1","SourceOutputPortId":"-225:data"},{"DestinationInputPortId":"-225:data1","SourceOutputPortId":"-232:data"},{"DestinationInputPortId":"-232:features","SourceOutputPortId":"-240:data"},{"DestinationInputPortId":"-225:data2","SourceOutputPortId":"-245:data"},{"DestinationInputPortId":"-111:input_1","SourceOutputPortId":"-277:data_1"},{"DestinationInputPortId":"-154:input_data","SourceOutputPortId":"-160:data"},{"DestinationInputPortId":"-160:features","SourceOutputPortId":"-166:data"},{"DestinationInputPortId":"-232:input_data","SourceOutputPortId":"-137:data"},{"DestinationInputPortId":"-151:input_1","SourceOutputPortId":"-137:data"},{"DestinationInputPortId":"-137:data1","SourceOutputPortId":"-133:data_1"},{"DestinationInputPortId":"-137:data2","SourceOutputPortId":"-145:data_1"},{"DestinationInputPortId":"-133:input_1","SourceOutputPortId":"-154:data"},{"DestinationInputPortId":"-121:input_1","SourceOutputPortId":"-151:data"}],"ModuleNodes":[{"Id":"287d2cb0-f53c-4101-bdf8-104b137c8601-8","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"Name":"end_date","Value":"2019-03-09","ValueType":"Literal","LinkedGlobalParameter":"交易日期"},{"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":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nmarket_cap_float_0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24"}],"OutputPortsInternal":[{"Name":"data","NodeId":"287d2cb0-f53c-4101-bdf8-104b137c8601-24","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-215","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":"-215"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-215"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-215","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":15,"Comment":"","CommentCollapsed":true},{"Id":"-222","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":"-222"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-222"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-222","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":16,"Comment":"","CommentCollapsed":true},{"Id":"-121","ModuleId":"BigQuantSpace.standardlize.standardlize-v8","ModuleParameters":[{"Name":"columns_input","Value":"[]","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-121"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-121"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-121","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"-165","ModuleId":"BigQuantSpace.fill_nan.fill_nan-v1","ModuleParameters":[{"Name":"columns_input","Value":"[]","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"group_key","Value":"['instrument']","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"method","Value":"向下向上填充","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-165"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-165"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-165","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"Comment":"","CommentCollapsed":true},{"Id":"-190","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nclose_0\nmarket_cap_0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-190"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-190","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":10,"Comment":"","CommentCollapsed":true},{"Id":"-220","ModuleId":"BigQuantSpace.fillnan.fillnan-v1","ModuleParameters":[{"Name":"fill_value","Value":"0.0","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-220"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-220"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-220","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":14,"Comment":"","CommentCollapsed":true},{"Id":"-225","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":"-225"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-225"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-225","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":17,"Comment":"","CommentCollapsed":true},{"Id":"-232","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":"-232"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-232"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-232","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":18,"Comment":"计算收益率","CommentCollapsed":false},{"Id":"-240","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nret0=shift(close_0,-1)/close_0-1","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-240"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-240","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":19,"Comment":"","CommentCollapsed":true},{"Id":"-245","ModuleId":"BigQuantSpace.select_columns.select_columns-v3","ModuleParameters":[{"Name":"columns","Value":"date,instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"reverse_select","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_ds","NodeId":"-245"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"columns_ds","NodeId":"-245"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-245","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":20,"Comment":"清洗因子完成","CommentCollapsed":true},{"Id":"-277","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 df = input_1.read_df()\n factor = input_2.read_pickle()[0]\n def get_group_label(df_input):\n listBins = list(df_input[factor].quantile([i/10.0 for i in range(6)]).values)\n listLabels = [0, 1, 2, 3, 4]\n df_input['group'] = pd.cut(df_input[factor], bins=listBins, labels=listLabels, include_lowest=True).astype(float)\n return df_input\n result = df.groupby('date').apply(get_group_label).reset_index()\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":"-277"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-277"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-277"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-277","OutputType":null},{"Name":"data_2","NodeId":"-277","OutputType":null},{"Name":"data_3","NodeId":"-277","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":22,"Comment":"因子分组","CommentCollapsed":false},{"Id":"-111","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 df = input_1.read_df()\n grouped_processed_df = df.groupby(['date','group'])['ret0'].agg(np.mean).reset_index()\n plot_df = grouped_processed_df.groupby('group').apply(lambda df: np.cumprod(1+df.set_index('date')['ret0'])).T\n T.plot(plot_df, \n options={\n 'legend':{'enabled': True},\n 'chart': {'type': 'line'},\n 'title': {'text': '因子分组收益'}})\n \n \n plot_df = grouped_processed_df.pivot(index='date', columns='group', values='ret0')\n plot_df = np.cumprod(1+plot_df[0] - plot_df[4])\n T.plot(plot_df, \n options={\n 'legend':{'enabled': False},\n 'chart': {'type': 'line'},\n 'title': {'text': '多空组合收益'}})\n data_1 = DataSource.write_df(df)\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":"-111"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-111"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-111"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-111","OutputType":null},{"Name":"data_2","NodeId":"-111","OutputType":null},{"Name":"data_3","NodeId":"-111","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"分组收益","CommentCollapsed":false},{"Id":"-160","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"industry_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-160"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-160"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-160","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-166","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"# #号开始的表示注释\n# 多个特征,每行一个,可以包含基础特征和衍生特征\nindustry_sw_level1","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-166"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-166","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":21,"Comment":"","CommentCollapsed":true},{"Id":"-137","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":"-137"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"data2","NodeId":"-137"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-137","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":11,"Comment":"","CommentCollapsed":true},{"Id":"-133","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, resample_period,how_key):\n # 示例代码如下。在这里编写您的代码\n df = input_1.read_df().set_index('date')\n resample_df = df.groupby('instrument',group_keys=False).apply(lambda x:x.resample(resample_period,how=how_key)).reset_index()\n data_1 = DataSource.write_df(resample_df.dropna())\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":"{\n 'resample_period':'W',\n 'how_key':'last'\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-133"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-133"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-133"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-133","OutputType":null},{"Name":"data_2","NodeId":"-133","OutputType":null},{"Name":"data_3","NodeId":"-133","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":23,"Comment":"周期转换","CommentCollapsed":false},{"Id":"-145","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, resample_period,how_key):\n # 示例代码如下。在这里编写您的代码\n df = input_1.read_df().set_index('date')\n resample_df = df.groupby('instrument',group_keys=False).apply(lambda x:x.resample(resample_period,how=how_key)).reset_index()\n data_1 = DataSource.write_df(resample_df.dropna())\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":"{\n 'resample_period':'W',\n 'how_key':'last'\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-145"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-145"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-145"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-145","OutputType":null},{"Name":"data_2","NodeId":"-145","OutputType":null},{"Name":"data_3","NodeId":"-145","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"Comment":"周期转换","CommentCollapsed":false},{"Id":"-154","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"industry_sw_level1>0","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":"-154"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-154","OutputType":null},{"Name":"left_data","NodeId":"-154","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":9,"Comment":"","CommentCollapsed":true},{"Id":"-151","ModuleId":"BigQuantSpace.neutralize.neutralize-v7","ModuleParameters":[{"Name":"columns_input","Value":"[]","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market_value_key","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market_col_name","Value":"market_cap_0","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"industry_sw_col_name","Value":"industry_sw_level1","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-151"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-151"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-151","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='246,90,200,200'/><NodePosition Node='287d2cb0-f53c-4101-bdf8-104b137c8601-24' Position='742,-5,200,200'/><NodePosition Node='-215' Position='245,190,200,200'/><NodePosition Node='-222' Position='295.03302001953125,273.1983642578125,200,200'/><NodePosition Node='-121' Position='537.66943359375,716.65283203125,200,200'/><NodePosition Node='-165' Position='339.6942138671875,357.8264465332031,200,200'/><NodePosition Node='-190' Position='548,93,200,200'/><NodePosition Node='-220' Position='573.5867919921875,795.6528930664062,200,200'/><NodePosition Node='-225' Position='330.5289001464844,940.5371704101562,200,200'/><NodePosition Node='-232' Position='17.983489990234375,791.8594970703125,200,200'/><NodePosition Node='-240' Position='173.20659387111664,712.11572265625,200,200'/><NodePosition Node='-245' Position='646.165283203125,862.9090576171875,200,200'/><NodePosition Node='-277' Position='394.6363220214844,1035.9090576171875,200,200'/><NodePosition Node='-111' Position='393.51239013671875,1157.281005859375,200,200'/><NodePosition Node='-160' Position='-71.65289306640625,213.48760986328125,200,200'/><NodePosition Node='-166' Position='-120,95,200,200'/><NodePosition Node='-137' Position='107,553.5123901367188,200,200'/><NodePosition Node='-133' Position='-33.59503173828125,433.2066345214844,200,200'/><NodePosition Node='-145' Position='312.7190246582031,445.1983642578125,200,200'/><NodePosition Node='-154' Position='-74.19834899902344,339.0909118652344,200,200'/><NodePosition Node='-151' Position='405.48553466796875,643.01318359375,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 [62]:
    # 本代码由可视化策略环境自动生成 2019年3月11日 18:02
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m6_run_bigquant_run(input_1, resample_period,how_key):
        # 示例代码如下。在这里编写您的代码
        df = input_1.read_df().set_index('date')
        resample_df = df.groupby('instrument',group_keys=False).apply(lambda x:x.resample(resample_period,how=how_key)).reset_index()
        data_1 = DataSource.write_df(resample_df.dropna())
        return Outputs(data_1=data_1)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m6_post_run_bigquant_run(outputs):
        return outputs
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m23_run_bigquant_run(input_1, resample_period,how_key):
        # 示例代码如下。在这里编写您的代码
        df = input_1.read_df().set_index('date')
        resample_df = df.groupby('instrument',group_keys=False).apply(lambda x:x.resample(resample_period,how=how_key)).reset_index()
        data_1 = DataSource.write_df(resample_df.dropna())
        return Outputs(data_1=data_1)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m23_post_run_bigquant_run(outputs):
        return outputs
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m22_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        df = input_1.read_df()
        factor = input_2.read_pickle()[0]
        def get_group_label(df_input):
            listBins = list(df_input[factor].quantile([i/10.0 for i in range(6)]).values)
            listLabels = [0, 1, 2, 3, 4]
            df_input['group'] = pd.cut(df_input[factor], bins=listBins, labels=listLabels, include_lowest=True).astype(float)
            return df_input
        result = df.groupby('date').apply(get_group_label).reset_index()
        data_1 = DataSource.write_df(result)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m22_post_run_bigquant_run(outputs):
        return outputs
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m4_run_bigquant_run(input_1, input_2, input_3):
        # 示例代码如下。在这里编写您的代码
        df = input_1.read_df()
        grouped_processed_df = df.groupby(['date','group'])['ret0'].agg(np.mean).reset_index()
        plot_df = grouped_processed_df.groupby('group').apply(lambda df: np.cumprod(1+df.set_index('date')['ret0'])).T
        T.plot(plot_df, 
                options={
                        'legend':{'enabled': True},
                        'chart': {'type': 'line'},
                        'title': {'text': '因子分组收益'}})
        
        
        plot_df = grouped_processed_df.pivot(index='date', columns='group', values='ret0')
        plot_df = np.cumprod(1+plot_df[0] - plot_df[4])
        T.plot(plot_df, 
                   options={
                        'legend':{'enabled': False},
                        'chart': {'type': 'line'},
                        'title': {'text': '多空组合收益'}})
        data_1 = DataSource.write_df(df)
        return Outputs(data_1=data_1, data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m4_post_run_bigquant_run(outputs):
        return outputs
    
    
    m1 = M.instruments.v2(
        start_date=T.live_run_param('trading_date', '2018-01-01'),
        end_date=T.live_run_param('trading_date', '2019-03-09'),
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m3 = M.input_features.v1(
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    market_cap_float_0"""
    )
    
    m10 = M.input_features.v1(
        features_ds=m3.data,
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    close_0
    market_cap_0"""
    )
    
    m15 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m10.data,
        start_date='',
        end_date='',
        before_start_days=0
    )
    
    m16 = M.derived_feature_extractor.v3(
        input_data=m15.data,
        features=m10.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False
    )
    
    m8 = M.fill_nan.v1(
        input_1=m16.data,
        input_2=m10.data,
        columns_input=[],
        group_key=['instrument'],
        method='向下向上填充'
    )
    
    m6 = M.cached.v3(
        input_1=m8.data,
        run=m6_run_bigquant_run,
        post_run=m6_post_run_bigquant_run,
        input_ports='',
        params="""{
        'resample_period':'W',
        'how_key':'last'
    }""",
        output_ports=''
    )
    
    m19 = M.input_features.v1(
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    ret0=shift(close_0,-1)/close_0-1"""
    )
    
    m21 = M.input_features.v1(
        features="""# #号开始的表示注释
    # 多个特征,每行一个,可以包含基础特征和衍生特征
    industry_sw_level1"""
    )
    
    m5 = M.use_datasource.v1(
        instruments=m1.data,
        features=m21.data,
        datasource_id='industry_CN_STOCK_A',
        start_date='',
        end_date=''
    )
    
    m9 = M.filter.v3(
        input_data=m5.data,
        expr='industry_sw_level1>0',
        output_left_data=False
    )
    
    m23 = M.cached.v3(
        input_1=m9.data,
        run=m23_run_bigquant_run,
        post_run=m23_post_run_bigquant_run,
        input_ports='',
        params="""{
        'resample_period':'W',
        'how_key':'last'
    }""",
        output_ports=''
    )
    
    m11 = M.join.v3(
        data1=m23.data_1,
        data2=m6.data_1,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m18 = M.derived_feature_extractor.v3(
        input_data=m11.data,
        features=m19.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=True,
        remove_extra_columns=True,
        user_functions={}
    )
    
    m13 = M.neutralize.v7(
        input_1=m11.data,
        input_2=m3.data,
        columns_input=[],
        market_value_key=True,
        market_col_name='market_cap_0',
        industry_sw_col_name='industry_sw_level1'
    )
    
    m2 = M.standardlize.v8(
        input_1=m13.data,
        input_2=m3.data,
        columns_input=[]
    )
    
    m14 = M.fillnan.v1(
        input_data=m2.data,
        features=m3.data,
        fill_value='0.0'
    )
    
    m20 = M.select_columns.v3(
        input_ds=m14.data,
        columns_ds=m3.data,
        columns='date,instrument',
        reverse_select=False
    )
    
    m17 = M.join.v3(
        data1=m18.data,
        data2=m20.data,
        on='date,instrument',
        how='inner',
        sort=False
    )
    
    m22 = M.cached.v3(
        input_1=m17.data,
        input_2=m3.data,
        run=m22_run_bigquant_run,
        post_run=m22_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m4 = M.cached.v3(
        input_1=m22.data_1,
        run=m4_run_bigquant_run,
        post_run=m4_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )