复制链接
克隆策略

    {"description":"实验创建于2022/12/16","graph":{"edges":[{"to_node_id":"-1064:input_1","from_node_id":"-678:data"}],"nodes":[{"node_id":"-678","module_id":"BigQuantSpace.use_datasource.use_datasource-v2","parameters":[{"name":"datasource_id","value":"stock_status_CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"2022-10-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2022-12-01","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":"10","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-678"},{"name":"features","node_id":"-678"}],"output_ports":[{"name":"data","node_id":"-678"}],"cacheable":true,"seq_num":1,"comment":"涨停数量","comment_collapsed":true},{"node_id":"-1064","module_id":"BigQuantSpace.cached.cached-v3","parameters":[{"name":"run","value":"# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端\ndef bigquant_run(input_1, input_2, input_3):\n input_df=input_1.read_df() \n #张跌停数量\n zdtsl_df=input_df.groupby(['date','price_limit_status'],as_index=False).agg({'instrument':'count'})\n zdtsl_df.set_index(keys=['date','price_limit_status'], inplace=True)\n df1=zdtsl_df.unstack()\n df1['date'] = df1.index\n df1.reset_index(drop=True, inplace=True)\n df1.columns = ['1','2','3','date']\n output_df = df1[['date','1','2','3']]\n output_df.rename(columns = {\"1\": \"decline_limit_nums\", \"2\":\"normal_status_nums\", \"3\":\"surged_limit_nums\"},inplace=True)\n return Outputs(data_1=DataSource.write_df(output_df), data_2=None, data_3=None)\n","type":"Literal","bound_global_parameter":null},{"name":"post_run","value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","type":"Literal","bound_global_parameter":null},{"name":"input_ports","value":"","type":"Literal","bound_global_parameter":null},{"name":"params","value":"{}","type":"Literal","bound_global_parameter":null},{"name":"output_ports","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-1064"},{"name":"input_2","node_id":"-1064"},{"name":"input_3","node_id":"-1064"}],"output_ports":[{"name":"data_1","node_id":"-1064"},{"name":"data_2","node_id":"-1064"},{"name":"data_3","node_id":"-1064"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-415","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-415"}],"output_ports":[{"name":"data","node_id":"-415"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-678' Position='555.2349853515625,552.565549850464,200,200'/><node_position Node='-1064' Position='578.2349853515625,667.565549850464,200,200'/><node_position Node='-415' Position='556.421142578125,420.78961181640625,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [2]:
    # 本代码由可视化策略环境自动生成 2022年12月16日 10:49
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    # Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
    def m2_run_bigquant_run(input_1, input_2, input_3):
        input_df=input_1.read_df() 
        #张跌停数量
        zdtsl_df=input_df.groupby(['date','price_limit_status'],as_index=False).agg({'instrument':'count'})
        zdtsl_df.set_index(keys=['date','price_limit_status'], inplace=True)
        df1=zdtsl_df.unstack()
        df1['date'] = df1.index
        df1.reset_index(drop=True, inplace=True)
        df1.columns = ['1','2','3','date']
        output_df = df1[['date','1','2','3']]
        output_df.rename(columns = {"1": "decline_limit_nums", "2":"normal_status_nums", "3":"surged_limit_nums"},inplace=True)
        return Outputs(data_1=DataSource.write_df(output_df), data_2=None, data_3=None)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m2_post_run_bigquant_run(outputs):
        return outputs
    
    
    m1 = M.use_datasource.v2(
        datasource_id='stock_status_CN_STOCK_A',
        start_date='2022-10-01',
        end_date='2022-12-01',
        before_start_days=10
    )
    
    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=''
    )
    
    m3 = M.instruments.v2(
        start_date='',
        end_date='',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )