复制链接
克隆策略

    {"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"-52:input_data","from_node_id":"-62:data"}],"nodes":[{"node_id":"-52","module_id":"BigQuantSpace.auto_labeler_on_datasource.auto_labeler_on_datasource-v1","parameters":[{"name":"label_expr","value":"# #号开始的表示注释\n# 0. 每行一个,顺序执行,从第二个开始,可以使用label字段\n# 1. 可用数据字段见 https://bigquant.com/docs/develop/datasource/deprecated/history_data.html\n# 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/develop/bigexpr/usage.html>`_\n\n# 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\nshift(close, -5) / shift(open, -1)\n\n# 极值处理:用1%和99%分位的值做clip\nclip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 将分数映射到分类,这里使用20个分类\nall_wbins(label, 20)\n\n# 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)\nwhere(shift(high, -1) == shift(low, -1), NaN, label)\n","type":"Literal","bound_global_parameter":null},{"name":"drop_na_label","value":"True","type":"Literal","bound_global_parameter":null},{"name":"cast_label_int","value":"True","type":"Literal","bound_global_parameter":null},{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"{}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-52"}],"output_ports":[{"name":"data","node_id":"-52"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-62","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"bar1d_CN_FUTURE","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"2021-12-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-12-09","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-62"},{"name":"features","node_id":"-62"}],"output_ports":[{"name":"data","node_id":"-62"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-52' Position='211.9209747314453,-203.85848999023438,200,200'/><node_position Node='-62' Position='148.56947326660156,-287.95989990234375,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [1]:
    # 本代码由可视化策略环境自动生成 2021年12月10日 17:39
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m4 = M.use_datasource.v1(
        datasource_id='bar1d_CN_FUTURE',
        start_date='2021-12-01',
        end_date='2021-12-09'
    )
    
    m3 = M.auto_labeler_on_datasource.v1(
        input_data=m4.data,
        label_expr="""# #号开始的表示注释
    # 0. 每行一个,顺序执行,从第二个开始,可以使用label字段
    # 1. 可用数据字段见 https://bigquant.com/docs/develop/datasource/deprecated/history_data.html
    # 2. 可用操作符和函数见 `表达式引擎 <https://bigquant.com/docs/develop/bigexpr/usage.html>`_
    
    # 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
    shift(close, -5) / shift(open, -1)
    
    # 极值处理:用1%和99%分位的值做clip
    clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))
    
    # 将分数映射到分类,这里使用20个分类
    all_wbins(label, 20)
    
    # 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)
    where(shift(high, -1) == shift(low, -1), NaN, label)
    """,
        drop_na_label=True,
        cast_label_int=True,
        date_col='date',
        instrument_col='instrument',
        user_functions={}
    )
    
    In [2]:
    m3.data.read()
    
    Out[2]:
    date instrument m:amount m:close m:high m:low m:open m:open_intl m:settle m:volume m:product_code m:low_limit m:high_limit label
    0 2021-12-01 TS2206.CFX 5.539366e+08 100.720001 100.724998 100.699997 100.724998 392.0 100.714996 275.0 TS 100.235000 101.235000 10
    1 2021-12-01 TS8888.CFX 2.964522e+10 100.775002 100.809998 100.775002 100.809998 31360.0 100.785004 14706.0 TS 100.315000 101.315000 10
    2 2021-12-01 TS2203.CFX 2.964522e+10 100.775002 100.809998 100.775002 100.809998 31360.0 100.785004 14706.0 TS 100.315000 101.315000 10
    3 2021-12-01 TS2112.CFX 5.643910e+07 100.790001 100.800003 100.764999 100.769997 770.0 100.785004 28.0 TS 100.285000 101.285000 10
    4 2021-12-01 TS0000.CFX 3.025559e+10 100.774696 100.808739 100.773857 100.808029 32522.0 100.784157 15009.0 TS 100.313325 101.313325 10
    ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
    1282 2021-12-01 CY8888.CZC 1.325096e+09 27630.000000 28025.000000 26930.000000 27335.000000 3588.0 27395.000000 9674.0 CY 25250.000000 30250.000000 5
    1283 2021-12-02 CY2205.CZC 2.916650e+07 26385.000000 26745.000000 26305.000000 26740.000000 957.0 26515.000000 220.0 CY 23985.000000 28735.000000 11
    1284 2021-12-02 CY2201.CZC 8.969431e+08 27455.000000 27655.000000 27020.000000 27535.000000 3418.0 27325.000000 6565.0 CY 24925.000000 29865.000000 5
    1285 2021-12-02 CY0000.CZC 9.261096e+08 27220.457031 27455.132812 26863.599609 27360.417969 4381.0 27147.429688 6785.0 CY 24718.946588 29617.293997 6
    1286 2021-12-02 CY8888.CZC 8.969431e+08 27455.000000 27655.000000 27020.000000 27535.000000 3418.0 27325.000000 6565.0 CY 24925.000000 29865.000000 5

    1287 rows × 14 columns