复制链接
克隆策略

    {"description":"实验创建于2018/6/27","graph":{"edges":[{"to_node_id":"-353:instruments","from_node_id":"-51:data"},{"to_node_id":"-353:features","from_node_id":"-59:data"},{"to_node_id":"-360:features","from_node_id":"-59:data"},{"to_node_id":"-1372:input_1","from_node_id":"-353:data"},{"to_node_id":"-220:instruments","from_node_id":"-226:data"},{"to_node_id":"-443:features","from_node_id":"-234:data"},{"to_node_id":"-220:features","from_node_id":"-234:data"},{"to_node_id":"-2883:input_1","from_node_id":"-443:data"},{"to_node_id":"-360:input_data","from_node_id":"-1372:data"},{"to_node_id":"-443:input_data","from_node_id":"-220:data"},{"to_node_id":"-2864:instruments","from_node_id":"-2870:data"},{"to_node_id":"-2864:features","from_node_id":"-2878:data"},{"to_node_id":"-2883:input_2","from_node_id":"-2864:data"},{"to_node_id":"-1372:input_2","from_node_id":"-2883:data"}],"nodes":[{"node_id":"-51","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2020-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2020-12-31","type":"Literal","bound_global_parameter":"交易日期"},{"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":"-51"}],"output_ports":[{"name":"data","node_id":"-51"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-59","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"return0=return_0\nreturn1=shift(return_0,1)#return_1\nreturn3=return_3\nmax10=ts_max(close_0,10)\nmax10d=ts_argmax(close_0,10)\nmin10=ts_min(close_0,10)\nmin10d=ts_argmin(close_0,10)\npriceHighBl10=close_0/max10\npriceLowBl10=close_0/min10\nmax30=ts_max(close_0,30)\nmax30d=ts_argmax(close_0,30)\nmin30=ts_min(close_0,30)\nmin30d=ts_argmin(close_0,30)\npriceHighBl30=close_0/max30\npriceLowBl30=close_0/min30\n\nddzb=mf_net_pct_l_0+mf_net_pct_main_0+mf_net_pct_xl_0\ndbzb30=sum(ddzb,30)\ndbzs_return=return0-zs_return_0\n# dbzs_return=return_0 - zs_return_0\n#连续上涨天数\nisShangZ0=where(return_0>1,1,0)\nlxsz_1d=where(sum(isShangZ0,1)==1,1,0)\nlxsz_2d=where(sum(isShangZ0,2)==2,2,0)\nlxsz_3d=where(sum(isShangZ0,3)==3,3,0)\nlxsz_4d=where(sum(isShangZ0,4)==4,4,0)\nlxsz_5d=where(sum(isShangZ0,5)==5,5,0)\nlxsz_6d=where(sum(isShangZ0,6)==6,6,0)\nlxsz_8d=where(sum(isShangZ0,8)==8,8,0)\nlxsz_10d=where(sum(isShangZ0,10)==10,10,0)\nlxsz_days=max(lxsz_1d,lxsz_2d,lxsz_3d,lxsz_4d,lxsz_5d,lxsz_6d,lxsz_8d,lxsz_10d)\n\nmy3=where((abs(return0-1.02)<0.01)&(return0>return1)&(lxsz_days==2)&((return0+return1)<2.04)&(return3<1)&(priceHighBl10<0.93)&(priceLowBl10<1.12)&(priceHighBl30==priceHighBl10)&(priceLowBl30==priceLowBl10)&(dbzs_return>0),1,0)","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-59"}],"output_ports":[{"name":"data","node_id":"-59"}],"cacheable":false,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-353","module_id":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","parameters":[{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"before_start_days","value":"90","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-353"},{"name":"features","node_id":"-353"}],"output_ports":[{"name":"data","node_id":"-353"}],"cacheable":false,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-360","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"drop_na","value":"False","type":"Literal","bound_global_parameter":null},{"name":"remove_extra_columns","value":"True","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"import numpy as np\nimport pandas as pd\ndef maxdrawdown(df, data, period):\n def getMaxDrawdown(x):\n x = x.to_numpy()\n i = np.argmax(x)\n if i == len(x) - 1:\n return 0\n low = np.min(x[i:])\n d = (x[i] - low) / x[i] * 100\n return d\n return data.rolling(period).apply(getMaxDrawdown)\n\nbigquant_run = {\n 'maxdrawdown':maxdrawdown\n}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-360"},{"name":"features","node_id":"-360"}],"output_ports":[{"name":"data","node_id":"-360"}],"cacheable":false,"seq_num":7,"comment":"","comment_collapsed":true},{"node_id":"-226","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2010-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2050-01-01","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"000002.HIX","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-226"}],"output_ports":[{"name":"data","node_id":"-226"}],"cacheable":true,"seq_num":10,"comment":"","comment_collapsed":true},{"node_id":"-234","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nzs_zhangf=(close-open)/open\nzs_open=open/shift(close,1)\nzs_huiluo=(high-close)/close\nzs_huishen=(close-low)/low\nzs_zhenf=(high-low)/shift(close,1)\nzs_volume_zf=volume/shift(volume,1)\nzs_return_0=close/shift(close,1)\nzs_return_1=shift(zs_return_0,1)\nzs_return_2=shift(zs_return_0,2)\nzs_max10=ts_max(close,10)\nzs_max10d=ts_argmax(close,10)\nzs_max30=ts_max(close,30)\n#zs_max30d=ts_argmax(close,30)\nzs_min10=ts_min(close,10)\n#zs_min10d=ts_argmin(close,10)\nzs_min30=ts_min(close,30)\n#zs_min30d=ts_argmin(close,30)\nzs_priceHighBl10=close/zs_max10\nzs_priceLowBl10=close/zs_min10\nzs_priceHighBl30=close/zs_max30\nzs_priceLowBl30=close/zs_min30","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-234"}],"output_ports":[{"name":"data","node_id":"-234"}],"cacheable":true,"seq_num":12,"comment":"","comment_collapsed":true},{"node_id":"-443","module_id":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","parameters":[{"name":"date_col","value":"date","type":"Literal","bound_global_parameter":null},{"name":"instrument_col","value":"instrument","type":"Literal","bound_global_parameter":null},{"name":"drop_na","value":"False","type":"Literal","bound_global_parameter":null},{"name":"remove_extra_columns","value":"True","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"{}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-443"},{"name":"features","node_id":"-443"}],"output_ports":[{"name":"data","node_id":"-443"}],"cacheable":true,"seq_num":13,"comment":"","comment_collapsed":true},{"node_id":"-1372","module_id":"BigQuantSpace.data_join.data_join-v3","parameters":[{"name":"on","value":"date","type":"Literal","bound_global_parameter":null},{"name":"how","value":"left","type":"Literal","bound_global_parameter":null},{"name":"sort","value":"True","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-1372"},{"name":"input_2","node_id":"-1372"}],"output_ports":[{"name":"data","node_id":"-1372"}],"cacheable":true,"seq_num":14,"comment":"","comment_collapsed":true},{"node_id":"-220","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"bar1d_index_CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-220"},{"name":"features","node_id":"-220"}],"output_ports":[{"name":"data","node_id":"-220"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-2870","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2020-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2020-12-30","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"000002.HIX","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-2870"}],"output_ports":[{"name":"data","node_id":"-2870"}],"cacheable":true,"seq_num":15,"comment":"","comment_collapsed":true},{"node_id":"-2878","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nclose\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-2878"}],"output_ports":[{"name":"data","node_id":"-2878"}],"cacheable":true,"seq_num":16,"comment":"","comment_collapsed":true},{"node_id":"-2864","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"bar1d_index_CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"start_date","value":"","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-2864"},{"name":"features","node_id":"-2864"}],"output_ports":[{"name":"data","node_id":"-2864"}],"cacheable":true,"seq_num":17,"comment":"","comment_collapsed":true},{"node_id":"-2883","module_id":"BigQuantSpace.data_join.data_join-v3","parameters":[{"name":"on","value":"date","type":"Literal","bound_global_parameter":null},{"name":"how","value":"left","type":"Literal","bound_global_parameter":null},{"name":"sort","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_1","node_id":"-2883"},{"name":"input_2","node_id":"-2883"}],"output_ports":[{"name":"data","node_id":"-2883"}],"cacheable":true,"seq_num":18,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-51' Position='47,-82,200,200'/><node_position Node='-59' Position='406,-93.08832168579102,200,200'/><node_position Node='-353' Position='269,142,200,200'/><node_position Node='-360' Position='424,314,200,200'/><node_position Node='-226' Position='661,-185,200,200'/><node_position Node='-234' Position='1054,-185,200,200'/><node_position Node='-443' Position='812,82,200,200'/><node_position Node='-1372' Position='736.955810546875,255,200,200'/><node_position Node='-220' Position='730,-42,200,200'/><node_position Node='-2870' Position='1204,-48,200,200'/><node_position Node='-2878' Position='1562,-46,200,200'/><node_position Node='-2864' Position='1388,82,200,200'/><node_position Node='-2883' Position='1053,159.95584106445312,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [36]:
    # 本代码由可视化策略环境自动生成 2022年7月29日 13:56
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    import numpy as np
    import pandas as pd
    def maxdrawdown(df, data, period):
        def getMaxDrawdown(x):
            x = x.to_numpy()
            i = np.argmax(x)
            if i == len(x) - 1:
                return 0
            low = np.min(x[i:])
            d = (x[i] - low) / x[i] * 100
            return d
        return data.rolling(period).apply(getMaxDrawdown)
    
    m7_user_functions_bigquant_run = {
        'maxdrawdown':maxdrawdown
    }
    
    m1 = M.instruments.v2(
        start_date='2020-01-01',
        end_date=T.live_run_param('trading_date', '2020-12-31'),
        market='CN_STOCK_A',
        instrument_list='        ',
        max_count=0
    )
    
    m2 = M.input_features.v1(
        features="""return0=return_0
    return1=shift(return_0,1)#return_1
    return3=return_3
    max10=ts_max(close_0,10)
    max10d=ts_argmax(close_0,10)
    min10=ts_min(close_0,10)
    min10d=ts_argmin(close_0,10)
    priceHighBl10=close_0/max10
    priceLowBl10=close_0/min10
    max30=ts_max(close_0,30)
    max30d=ts_argmax(close_0,30)
    min30=ts_min(close_0,30)
    min30d=ts_argmin(close_0,30)
    priceHighBl30=close_0/max30
    priceLowBl30=close_0/min30
    
    ddzb=mf_net_pct_l_0+mf_net_pct_main_0+mf_net_pct_xl_0
    dbzb30=sum(ddzb,30)
    dbzs_return=return0-zs_return_0
    # dbzs_return=return_0 - zs_return_0
    #连续上涨天数
    isShangZ0=where(return_0>1,1,0)
    lxsz_1d=where(sum(isShangZ0,1)==1,1,0)
    lxsz_2d=where(sum(isShangZ0,2)==2,2,0)
    lxsz_3d=where(sum(isShangZ0,3)==3,3,0)
    lxsz_4d=where(sum(isShangZ0,4)==4,4,0)
    lxsz_5d=where(sum(isShangZ0,5)==5,5,0)
    lxsz_6d=where(sum(isShangZ0,6)==6,6,0)
    lxsz_8d=where(sum(isShangZ0,8)==8,8,0)
    lxsz_10d=where(sum(isShangZ0,10)==10,10,0)
    lxsz_days=max(lxsz_1d,lxsz_2d,lxsz_3d,lxsz_4d,lxsz_5d,lxsz_6d,lxsz_8d,lxsz_10d)
    
    my3=where((abs(return0-1.02)<0.01)&(return0>return1)&(lxsz_days==2)&((return0+return1)<2.04)&(return3<1)&(priceHighBl10<0.93)&(priceLowBl10<1.12)&(priceHighBl30==priceHighBl10)&(priceLowBl30==priceLowBl10)&(dbzs_return>0),1,0)""",
        m_cached=False
    )
    
    m5 = M.general_feature_extractor.v7(
        instruments=m1.data,
        features=m2.data,
        start_date='',
        end_date='',
        before_start_days=90,
        m_cached=False
    )
    
    m10 = M.instruments.v2(
        start_date='2010-01-01',
        end_date='2050-01-01',
        market='CN_STOCK_A',
        instrument_list='000002.HIX',
        max_count=0
    )
    
    m12 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    zs_zhangf=(close-open)/open
    zs_open=open/shift(close,1)
    zs_huiluo=(high-close)/close
    zs_huishen=(close-low)/low
    zs_zhenf=(high-low)/shift(close,1)
    zs_volume_zf=volume/shift(volume,1)
    zs_return_0=close/shift(close,1)
    zs_return_1=shift(zs_return_0,1)
    zs_return_2=shift(zs_return_0,2)
    zs_max10=ts_max(close,10)
    zs_max10d=ts_argmax(close,10)
    zs_max30=ts_max(close,30)
    #zs_max30d=ts_argmax(close,30)
    zs_min10=ts_min(close,10)
    #zs_min10d=ts_argmin(close,10)
    zs_min30=ts_min(close,30)
    #zs_min30d=ts_argmin(close,30)
    zs_priceHighBl10=close/zs_max10
    zs_priceLowBl10=close/zs_min10
    zs_priceHighBl30=close/zs_max30
    zs_priceLowBl30=close/zs_min30"""
    )
    
    m4 = M.use_datasource.v1(
        instruments=m10.data,
        features=m12.data,
        datasource_id='bar1d_index_CN_STOCK_A',
        start_date='',
        end_date=''
    )
    
    m13 = M.derived_feature_extractor.v3(
        input_data=m4.data,
        features=m12.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=True,
        user_functions={}
    )
    
    m15 = M.instruments.v2(
        start_date='2020-01-01',
        end_date='2020-12-30',
        market='CN_STOCK_A',
        instrument_list='000002.HIX',
        max_count=0
    )
    
    m16 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    close
    """
    )
    
    m17 = M.use_datasource.v1(
        instruments=m15.data,
        features=m16.data,
        datasource_id='bar1d_index_CN_STOCK_A',
        start_date='',
        end_date=''
    )
    
    m18 = M.data_join.v3(
        input_1=m13.data,
        input_2=m17.data,
        on='date',
        how='left',
        sort=False
    )
    
    m14 = M.data_join.v3(
        input_1=m5.data,
        input_2=m18.data,
        on='date',
        how='left',
        sort=True
    )
    
    m7 = M.derived_feature_extractor.v3(
        input_data=m14.data,
        features=m2.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=True,
        user_functions=m7_user_functions_bigquant_run,
        m_cached=False
    )
    
    In [37]:
    pd.set_option('display.max_columns', None)
    
    In [39]:
    # my3=where((abs(return0-1.02)<0.01)&(return0>return1)&(lxsz_days==2)&((return0+return1)<2.04)&(return3<1)&(priceHighBl10<0.93)&(priceLowBl10<1.12)&(priceHighBl30==priceHighBl10)&(priceLowBl30==priceLowBl10)&(dbzs_return>0),1,0)
    o = m7.data.read_df()
    o = o[(o['date'] > '2020-01-01')]
    o = o[(o['return0'] > 1.01) & (o['return0'] < 1.03)]
    o = o[o['lxsz_days'] == 2]
    o = o[o['return0'] + o['return1'] < 2.04]
    o = o[o['return3'] < 1]
    o = o[o['priceHighBl10'] < 0.93]
    o = o[o['priceLowBl10'] < 1.12]
    o = o[o['priceHighBl30'] == o['priceHighBl10']]
    o = o[o['priceLowBl30'] == o['priceLowBl10']]
    o = o[o['dbzs_return'] > 0]
    print(o[o['my3']==1].shape[0])
    
    151
    
    In [ ]: