市场成交情况统计

策略分享
标签: #<Tag:0x00007f20bcdc5fd0>

(大胡子) #1

本文思想

统计全市场(沪深A股)的成交情况,主要包含每日的总成交金额/总股票数,总成交额近5日平均值/总股票数这两个指标,指标可以帮助择时。

克隆策略

市场成交情况统计

本文思想

统计全市场(沪深A股)的成交情况,主要包含每日的总成交金额/总股票数,总成交额近5日平均值/总股票数这两个指标,指标可以帮助择时。

    {"Description":"实验创建于2019/1/8","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-33:features","SourceOutputPortId":"-16:data"},{"DestinationInputPortId":"-40:features","SourceOutputPortId":"-16:data"},{"DestinationInputPortId":"-33:instruments","SourceOutputPortId":"-20:data"},{"DestinationInputPortId":"-40:input_data","SourceOutputPortId":"-33:data"},{"DestinationInputPortId":"-52:input_1","SourceOutputPortId":"-40:data"}],"ModuleNodes":[{"Id":"-16","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\namount_0\nma5=mean(amount_0,5)\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-16"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-16","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"-20","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2018-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2019-01-07","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":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-20"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-20","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-33","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":"5","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-33"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-33"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-33","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"Comment":"","CommentCollapsed":true},{"Id":"-40","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":"-40"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-40"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-40","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-52","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 df = input_1.read_df() \n \n def fun(df):\n df['factor1'] = df['amount_0'].sum()/df['amount_0'].count() \n df['factor2'] = df['ma5'].sum()/df['amount_0'].count() \n return df \n result = df.groupby('date').apply(fun)\n result.rename(columns={'factor1':'总成交额/总股数','factor2':'总成交额5日平均/总股数'}, inplace=True)\n ds = DataSource.write_df(result)\n return Outputs(data=ds)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n result = outputs.data.read_df() \n # 因为每个交易日这俩因子值都一样,所以随便选择哪只股票索引数据都可以,这里以000002为例\n T.plot(result[result['instrument'] == '000002.SZA'][['总成交额/总股数','总成交额5日平均/总股数','date']].set_index('date'), title='市场成交统计')\n \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":"-52"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-52"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-52"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-52","OutputType":null},{"Name":"data_2","NodeId":"-52","OutputType":null},{"Name":"data_3","NodeId":"-52","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"市场成交统计","CommentCollapsed":false}],"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='-16' Position='557,110,200,200'/><NodePosition Node='-20' Position='192,125,200,200'/><NodePosition Node='-33' Position='392,218,200,200'/><NodePosition Node='-40' Position='397,316,200,200'/><NodePosition Node='-52' Position='401,433,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 [35]:
    # 本代码由可视化策略环境自动生成 2019年1月8日 19:03
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m5_run_bigquant_run(input_1, input_2, input_3):
         
            
        df  = input_1.read_df()    
         
        def fun(df):
            df['factor1'] = df['amount_0'].sum()/df['amount_0'].count() 
            df['factor2'] = df['ma5'].sum()/df['amount_0'].count() 
            return df 
        result = df.groupby('date').apply(fun)
        result.rename(columns={'factor1':'总成交额/总股数','factor2':'总成交额5日平均/总股数'}, inplace=True)
        ds = DataSource.write_df(result)
        return Outputs(data=ds)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m5_post_run_bigquant_run(outputs):
        result = outputs.data.read_df() 
        # 因为每个交易日这俩因子值都一样,所以随便选择哪只股票索引数据都可以,这里以000002为例
        T.plot(result[result['instrument'] == '000002.SZA'][['总成交额/总股数','总成交额5日平均/总股数','date']].set_index('date'), title='市场成交统计')
        
        return outputs
    
    
    m2 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    amount_0
    ma5=mean(amount_0,5)
    """
    )
    
    m3 = M.instruments.v2(
        start_date='2018-01-01',
        end_date='2019-01-07',
        market='CN_STOCK_A',
        instrument_list=''
    )
    
    m1 = M.general_feature_extractor.v7(
        instruments=m3.data,
        features=m2.data,
        start_date='',
        end_date='',
        before_start_days=5
    )
    
    m4 = M.derived_feature_extractor.v3(
        input_data=m1.data,
        features=m2.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m5 = M.cached.v3(
        input_1=m4.data,
        run=m5_run_bigquant_run,
        post_run=m5_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    [2019-01-08 19:01:08.088780] INFO: bigquant: input_features.v1 开始运行..
    [2019-01-08 19:01:08.094342] INFO: bigquant: 命中缓存
    [2019-01-08 19:01:08.095500] INFO: bigquant: input_features.v1 运行完成[0.006736s].
    [2019-01-08 19:01:08.097786] INFO: bigquant: instruments.v2 开始运行..
    [2019-01-08 19:01:08.101834] INFO: bigquant: 命中缓存
    [2019-01-08 19:01:08.102585] INFO: bigquant: instruments.v2 运行完成[0.004809s].
    [2019-01-08 19:01:08.108675] INFO: bigquant: general_feature_extractor.v7 开始运行..
    [2019-01-08 19:01:12.667987] INFO: 基础特征抽取: 年份 2017, 特征行数=9738
    [2019-01-08 19:01:15.145260] INFO: 基础特征抽取: 年份 2018, 特征行数=816987
    [2019-01-08 19:01:15.726781] INFO: 基础特征抽取: 年份 2019, 特征行数=14214
    [2019-01-08 19:01:15.753787] INFO: 基础特征抽取: 总行数: 840939
    [2019-01-08 19:01:15.756415] INFO: bigquant: general_feature_extractor.v7 运行完成[7.647712s].
    [2019-01-08 19:01:15.759124] INFO: bigquant: derived_feature_extractor.v3 开始运行..
    [2019-01-08 19:01:18.341786] INFO: derived_feature_extractor: 提取完成 ma5=mean(amount_0,5), 2.317s
    [2019-01-08 19:01:18.367243] INFO: derived_feature_extractor: /y_2017, 9738
    [2019-01-08 19:01:18.585697] INFO: derived_feature_extractor: /y_2018, 816987
    [2019-01-08 19:01:19.039101] INFO: derived_feature_extractor: /y_2019, 14214
    [2019-01-08 19:01:19.107079] INFO: bigquant: derived_feature_extractor.v3 运行完成[3.347919s].
    [2019-01-08 19:01:19.111624] INFO: bigquant: cached.v3 开始运行..
    
    [2019-01-08 19:01:21.162981] INFO: bigquant: cached.v3 运行完成[2.051161s].