A股每日当跌停股票报表

策略分享
数据分析
标签: #<Tag:0x00007f61decbbe60> #<Tag:0x00007f61decbbbe0>

(ingeno) #1

我们来分析一下每日涨跌停的股票数量。

从下面的分析结果可以看到,2018年A股经历了10次超过百股跌停,其中2次是超过千股跌停。你今年股票收益如何?

在数据数据文档里搜索 涨停 我们找到数据表 stock_status_CN_STOCK_A 和 字段 price_limit_status。有这个数据就可以做出我们要的分析图标了。

  1. 新建策略,选择 可视化空白策略

  2. 在模块列表里搜索 数据源,并加入画布,配置 ID开始日期结束日期,这个看2018年的数据

  3. 添加一个自定义python模块,来做数据分析,并配置如下分析代码

def bigquant_run(input_1, input_2, input_3):
    df = input_1.read()
    df = df[['date', 'price_limit_status']]
    df['price_limit_status'] = df['price_limit_status'].astype(int)

    def count_price_limit_status(x):
        return x.groupby('price_limit_status').size()

    df = df[['date', 'price_limit_status']].groupby('date').apply(count_price_limit_status)
    df = df.reset_index()
    df = df.pivot('date', 'price_limit_status', 0)
    df.columns = ['收盘跌停', '收盘未涨跌停', '收盘涨停']
    ds = DataSource.write_df(df)
    return Outputs(data_1=ds)
  1. 最后加入绘制图表模块

完整代码

克隆策略

    {"Description":"实验创建于2017/8/26","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-175:input_1","SourceOutputPortId":"-161:data"},{"DestinationInputPortId":"-33:input_data","SourceOutputPortId":"-175:data_1"}],"ModuleNodes":[{"Id":"-161","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"stock_status_CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"2015-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2018-12-25","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-161"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-161"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-161","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"Comment":"获取涨跌停状态数据","CommentCollapsed":false},{"Id":"-175","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"def bigquant_run(input_1, input_2, input_3):\n df = input_1.read()\n df = df[['date', 'price_limit_status']]\n df['price_limit_status'] = df['price_limit_status'].astype(int)\n\n def count_price_limit_status(x):\n return x.groupby('price_limit_status').size()\n\n df = df[['date', 'price_limit_status']].groupby('date').apply(count_price_limit_status)\n df = df.reset_index()\n df = df.pivot('date', 'price_limit_status', 0)\n df.columns = ['收盘跌停', '收盘未涨跌停', '收盘涨停']\n ds = DataSource.write_df(df)\n return Outputs(data_1=ds)\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":"-175"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-175"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-175"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-175","OutputType":null},{"Name":"data_2","NodeId":"-175","OutputType":null},{"Name":"data_3","NodeId":"-175","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"计算涨跌停数据","CommentCollapsed":false},{"Id":"-33","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"line","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 400\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-33"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":4,"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='-161' Position='478,152,200,200'/><NodePosition Node='-175' Position='478,281,200,200'/><NodePosition Node='-33' Position='476.9798583984375,409.8955078125,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]:
    # 本代码由可视化策略环境自动生成 2018年12月27日 17:39
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    def m2_run_bigquant_run(input_1, input_2, input_3):
        df = input_1.read()
        df = df[['date', 'price_limit_status']]
        df['price_limit_status'] = df['price_limit_status'].astype(int)
    
        def count_price_limit_status(x):
            return x.groupby('price_limit_status').size()
    
        df = df[['date', 'price_limit_status']].groupby('date').apply(count_price_limit_status)
        df = df.reset_index()
        df = df.pivot('date', 'price_limit_status', 0)
        df.columns = ['收盘跌停', '收盘未涨跌停', '收盘涨停']
        ds = DataSource.write_df(df)
        return Outputs(data_1=ds)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m2_post_run_bigquant_run(outputs):
        return outputs
    
    
    m1 = M.use_datasource.v1(
        datasource_id='stock_status_CN_STOCK_A',
        start_date='2015-01-01',
        end_date='2018-12-25'
    )
    
    m2 = M.cached.v3(
        input_1=m1.data,
        run=m2_run_bigquant_run,
        post_run=m2_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports=''
    )
    
    m4 = M.plot_dataframe.v1(
        input_data=m2.data_1,
        title='',
        chart_type='line',
        x='',
        y='',
        options={
        'chart': {
            'height': 400
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    [2018-12-27 17:35:33.456866] INFO: bigquant: use_datasource.v1 开始运行..
    [2018-12-27 17:35:33.462418] INFO: bigquant: 命中缓存
    [2018-12-27 17:35:33.463794] INFO: bigquant: use_datasource.v1 运行完成[0.006929s].
    [2018-12-27 17:35:33.467730] INFO: bigquant: cached.v3 开始运行..
    [2018-12-27 17:35:33.473306] INFO: bigquant: 命中缓存
    [2018-12-27 17:35:33.474351] INFO: bigquant: cached.v3 运行完成[0.006605s].
    

    2018年A股全景复盘,散户人均亏损10万