克隆策略

案例

  • 设置时间范围 2021-01-01 到 2021-03-01,股票范围为000001.SZA 和 300023.SZA
  • 获取bar1d_CN_STOCK_A表中的close、open、high、low、adjust_factor、amount列,并利用表达式计算真实价格close_actual=close/adjust_factor
  • 将每日的数据按close_actual列大小升序排列
  • 条件过滤close_actual列得到真实价格小于10元的数据行
  • 条件过滤日期列得到2021年2月的数据行
  • 从DataFrame中筛选date,instrument,close_actual三列数据
  • 结果查看

    {"description":"实验创建于2020/2/23","graph":{"edges":[{"to_node_id":"-24:input_data","from_node_id":"-5:data"},{"to_node_id":"-5:instruments","from_node_id":"-11:data"},{"to_node_id":"-5:features","from_node_id":"-19:data"},{"to_node_id":"-24:features","from_node_id":"-19:data"},{"to_node_id":"-33:input_ds","from_node_id":"-24:data"},{"to_node_id":"-49:input_data","from_node_id":"-33:sorted_data"},{"to_node_id":"-55:input_data","from_node_id":"-49:data"},{"to_node_id":"-61:input_ds","from_node_id":"-55:data"}],"nodes":[{"node_id":"-5","module_id":"BigQuantSpace.use_datasource.use_datasource-v1","parameters":[{"name":"datasource_id","value":"bar1d_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":"-5"},{"name":"features","node_id":"-5"}],"output_ports":[{"name":"data","node_id":"-5"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-11","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2021-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2021-03-01","type":"Literal","bound_global_parameter":null},{"name":"market","value":"CN_STOCK_A","type":"Literal","bound_global_parameter":null},{"name":"instrument_list","value":"000001.SZA\n300023.SZA","type":"Literal","bound_global_parameter":null},{"name":"max_count","value":0,"type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"rolling_conf","node_id":"-11"}],"output_ports":[{"name":"data","node_id":"-11"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-19","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nclose\nopen\nhigh\nlow\nadjust_factor\namount\nclose_actual=close/adjust_factor","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-19"}],"output_ports":[{"name":"data","node_id":"-19"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-24","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":"False","type":"Literal","bound_global_parameter":null},{"name":"user_functions","value":"{}","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-24"},{"name":"features","node_id":"-24"}],"output_ports":[{"name":"data","node_id":"-24"}],"cacheable":true,"seq_num":4,"comment":"","comment_collapsed":true},{"node_id":"-33","module_id":"BigQuantSpace.sort.sort-v4","parameters":[{"name":"sort_by","value":"close_actual","type":"Literal","bound_global_parameter":null},{"name":"group_by","value":"date","type":"Literal","bound_global_parameter":null},{"name":"keep_columns","value":"--","type":"Literal","bound_global_parameter":null},{"name":"ascending","value":"True","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_ds","node_id":"-33"},{"name":"sort_by_ds","node_id":"-33"}],"output_ports":[{"name":"sorted_data","node_id":"-33"}],"cacheable":false,"seq_num":5,"comment":"","comment_collapsed":true},{"node_id":"-49","module_id":"BigQuantSpace.filter.filter-v3","parameters":[{"name":"expr","value":"close_actual<10","type":"Literal","bound_global_parameter":null},{"name":"output_left_data","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-49"}],"output_ports":[{"name":"data","node_id":"-49"},{"name":"left_data","node_id":"-49"}],"cacheable":true,"seq_num":6,"comment":"","comment_collapsed":true},{"node_id":"-55","module_id":"BigQuantSpace.filter.filter-v3","parameters":[{"name":"expr","value":"date>='2021-02-01' and date<'2021-03-01'","type":"Literal","bound_global_parameter":null},{"name":"output_left_data","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_data","node_id":"-55"}],"output_ports":[{"name":"data","node_id":"-55"},{"name":"left_data","node_id":"-55"}],"cacheable":true,"seq_num":7,"comment":"","comment_collapsed":true},{"node_id":"-61","module_id":"BigQuantSpace.select_columns.select_columns-v3","parameters":[{"name":"columns","value":"date,instrument,close_actual","type":"Literal","bound_global_parameter":null},{"name":"reverse_select","value":"False","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_ds","node_id":"-61"},{"name":"columns_ds","node_id":"-61"}],"output_ports":[{"name":"data","node_id":"-61"}],"cacheable":true,"seq_num":8,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-5' Position='388,269,200,200'/><node_position Node='-11' Position='280,167,200,200'/><node_position Node='-19' Position='579,169,200,200'/><node_position Node='-24' Position='405,361,200,200'/><node_position Node='-33' Position='457,459,200,200'/><node_position Node='-49' Position='479,547,200,200'/><node_position Node='-55' Position='509,652,200,200'/><node_position Node='-61' Position='519,745,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [26]:
    # 本代码由可视化策略环境自动生成 2021年10月15日07:15
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m2 = M.instruments.v2(
        start_date='2021-01-01',
        end_date='2021-03-01',
        market='CN_STOCK_A',
        instrument_list="""000001.SZA
    300023.SZA""",
        max_count=0
    )
    
    m3 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    close
    open
    high
    low
    adjust_factor
    amount
    close_actual=close/adjust_factor"""
    )
    
    m1 = M.use_datasource.v1(
        instruments=m2.data,
        features=m3.data,
        datasource_id='bar1d_CN_STOCK_A',
        start_date='',
        end_date=''
    )
    
    m4 = M.derived_feature_extractor.v3(
        input_data=m1.data,
        features=m3.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m5 = M.sort.v4(
        input_ds=m4.data,
        sort_by='close_actual',
        group_by='date',
        keep_columns='--',
        ascending=True,
        m_cached=False
    )
    
    m6 = M.filter.v3(
        input_data=m5.sorted_data,
        expr='close_actual<10',
        output_left_data=False
    )
    
    m7 = M.filter.v3(
        input_data=m6.data,
        expr='date>=\'2021-02-01\' and date<\'2021-03-01\'',
        output_left_data=False
    )
    
    m8 = M.select_columns.v3(
        input_ds=m7.data,
        columns='date,instrument,close_actual',
        reverse_select=False
    )
    
    列: ['date', 'instrument', 'close_actual']
    /data: 15