克隆策略

平台默认支持很多表达式进行数据标注,若用户想自定义表达式进行数据标注,可以参考本例。

    {"Description":"实验创建于2019/2/15","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-705:instruments","SourceOutputPortId":"-697:data"}],"ModuleNodes":[{"Id":"-697","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2016-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2017-01-01","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":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-697"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-697","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-705","ModuleId":"BigQuantSpace.advanced_auto_labeler.advanced_auto_labeler-v2","ModuleParameters":[{"Name":"label_expr","Value":" \n# 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)\nshift(close, -5) / shift(open, -1) - 1\n\n# 极值处理:用1%和99%分位的值做clip\nclip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))\n\n# 通过自定义函数将分数映射到分类,这里使用20个分类\nmy_wbins(rets=label, bins=20) \n\n# 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)\n#where(shift(high, -1) == shift(low, -1), NaN, label)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"benchmark","Value":"000300.SHA","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na_label","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"cast_label_int","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"def my_wbins(self,rets,bins):\n result = pd.cut(rets, bins=bins,labels=range(bins))\n print(result)\n return result\n\nbigquant_run = {\n 'my_wbins': my_wbins\n}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-705"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-705","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"IsPartOfPartialRun":null,"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='-697' Position='57.2181396484375,79.67953491210938,200,200'/><NodePosition Node='-705' Position='123.52702331542969,198.2258758544922,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 [6]:
    # 本代码由可视化策略环境自动生成 2021年6月21日11:08
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    def my_wbins(self,rets,bins):
        result = pd.cut(rets, bins=bins,labels=range(bins))
        print(result)
        return result
    
    m2_user_functions_bigquant_run = {
        'my_wbins':  my_wbins
    }
    
    m1 = M.instruments.v2(
        start_date='2016-01-01',
        end_date='2017-01-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m2 = M.advanced_auto_labeler.v2(
        instruments=m1.data,
        label_expr=""" 
    # 计算收益:5日收盘价(作为卖出价格)除以明日开盘价(作为买入价格)
    shift(close, -5) / shift(open, -1) - 1
    
    # 极值处理:用1%和99%分位的值做clip
    clip(label, all_quantile(label, 0.01), all_quantile(label, 0.99))
    
    # 通过自定义函数将分数映射到分类,这里使用20个分类
    my_wbins(rets=label, bins=20) 
    
    # 过滤掉一字涨停的情况 (设置label为NaN,在后续处理和训练中会忽略NaN的label)
    #where(shift(high, -1) == shift(low, -1), NaN, label)
    """,
        start_date='',
        end_date='',
        benchmark='000300.SHA',
        drop_na_label=True,
        cast_label_int=True,
        user_functions=m2_user_functions_bigquant_run
    )
    
    In [7]:
    # 查看标注数据
    m2.data.read()
    
    Out[7]:
    date instrument m:open m:amount m:close label
    0 2016-01-04 000001.SZA 1031.928955 660376153.1 974.312988 6
    1 2016-01-04 000004.SZA 186.531265 97674865.8 167.878143 1
    2 2016-01-04 000005.SZA 92.676003 302240974.4 83.779106 4
    3 2016-01-04 000006.SZA 366.743439 254639754.8 332.181213 2
    4 2016-01-04 000008.SZA 261.608582 157014603.3 233.642014 9
    ... ... ... ... ... ... ...
    626404 2016-12-23 603993.SHA 12.376604 120877639.0 12.376604 7
    626405 2016-12-23 603996.SHA 34.277599 117174561.0 33.291740 5
    626406 2016-12-23 603997.SHA 19.679829 30235876.0 19.507996 9
    626407 2016-12-23 603998.SHA 70.277962 57589943.0 70.788361 7
    626408 2016-12-23 603999.SHA 38.867962 185104460.0 37.350811 6

    626409 rows × 6 columns