复制链接
克隆策略

    {"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"-3231:features","from_node_id":"-331:data"},{"to_node_id":"-3231:instruments","from_node_id":"-312:data"},{"to_node_id":"-3345:factors_info","from_node_id":"-3231:data"}],"nodes":[{"node_id":"-331","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"_amt = amount\n_amt_buy = initiative_bid_amount.fillna(0)\n_amt_sell = initiative_ask_amount.fillna(0)\n\n# 连续竞价成交占比\n# cont_amt_ratio = _amt.loc[93100:145600].sum() / (_amt.sum())\n\n# 特大单成交占比(大于均值+3倍标准差)\n_amt_great = beyond_13_bid_amount.add(beyond_13_ask_amount).fillna(0)\namt_great_ratio = _amt_great.sum() / (_amt.sum()*2)\n\n# 大单成交占比(大于均值+2倍标准差)\n_amt_big = beyond_11_bid_amount.add(beyond_11_ask_amount).fillna(0)\namt_big_ratio = _amt_great.sub(_amt_big).sum() / (_amt.sum()*2)\n\n# 中单成交占比(大于均值+0.5倍标准差)\n_amt_median = beyond_8_bid_amount.add(beyond_8_ask_amount).fillna(0)\namt_median_ratio = _amt_big.sub(_amt_median).sum() / (_amt.sum()*2)\n\n# 小单成交占比(大于均值-2倍标准差)\n_amt_small = beyond_3_bid_amount.add(beyond_3_ask_amount).fillna(0)\namt_small_ratio = _amt_median.sub(_amt_small).sum() / (_amt.sum()*2)\n\n# 净买入比率\nnet_buy_ratio = (_amt_buy.sum() - _amt_sell.sum()) / (_amt.sum())\n\n# 早盘净买入比率\nearly_net_buy_ratio = (_amt_buy.iloc[:30].sum() - _amt_sell.iloc[:30].sum()) / (_amt.sum())\n\n# 尾盘净买入比率\nlate_net_buy_ratio = (_amt_buy.iloc[-30:].sum() - _amt_sell.iloc[-30:].sum()) / (_amt.sum())\n","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"features_ds","node_id":"-331"}],"output_ports":[{"name":"data","node_id":"-331"}],"cacheable":true,"seq_num":1,"comment":"","comment_collapsed":true},{"node_id":"-312","module_id":"BigQuantSpace.instruments.instruments-v2","parameters":[{"name":"start_date","value":"2018-01-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2018-12-31","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":"-312"}],"output_ports":[{"name":"data","node_id":"-312"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-3231","module_id":"BigQuantSpace.feature_extractor_1m.feature_extractor_1m-v2","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":"0","type":"Literal","bound_global_parameter":null},{"name":"workers","value":"10","type":"Literal","bound_global_parameter":null},{"name":"parallel_mode","value":"集群","type":"Literal","bound_global_parameter":null},{"name":"table_1m","value":"level2_bar1m_CN_STOCK_A","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"instruments","node_id":"-3231"},{"name":"features","node_id":"-3231"},{"name":"user_functions","node_id":"-3231"}],"output_ports":[{"name":"data","node_id":"-3231"}],"cacheable":true,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-3345","module_id":"BigQuantSpace.factorlens_preservation.factorlens_preservation-v2","parameters":[{"name":"factor_fields","value":"{\n 'amt_great_ratio':{'name':'deal_ratio_3x', 'desc':'大于均值+3倍标准差的成交金额占当日总成交金额比例'},\n 'amt_big_ratio':{'name':'deal_ratio_2x', 'desc':'大于均值+2倍标准差的成交金额占当日总成交金额比例'},\n 'amt_median_ratio':{'name':'deal_ratio_05x', 'desc':'大于均值+0.5倍标准差的成交金额占当日总成交金额比例'},\n 'amt_small_ratio':{'name':'deal_ratio_n2x', 'desc':'大于均值-2倍标准差的成交金额占当日总成交金额比例'},\n 'net_buy_ratio':{'name':'net_buy_ratio', 'desc':'净主动买入金额占当日总成交金额比例'},\n 'early_net_buy_ratio':{'name':'early_net_buy_ratio_30m', 'desc':'早盘30分钟净主动买入金额占当日总成交金额比例'},\n 'late_net_buy_ratio':{'name':'late_net_buy_ratio_30m', 'desc':'尾盘30分钟净主动买入金额占当日总成交金额比例'}\n}\n","type":"Literal","bound_global_parameter":null},{"name":"table","value":"hf_factors_cn_stock_a","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"factors_info","node_id":"-3345"}],"output_ports":[{"name":"data","node_id":"-3345"}],"cacheable":false,"seq_num":4,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-331' Position='-7.0756072998046875,-46,200,200'/><node_position Node='-312' Position='-338,-40,200,200'/><node_position Node='-3231' Position='5,59,200,200'/><node_position Node='-3345' Position='40,203,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [1]:
    # 本代码由可视化策略环境自动生成 2023年2月21日 14:20
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m1 = M.input_features.v1(
        features="""_amt = amount
    _amt_buy = initiative_bid_amount.fillna(0)
    _amt_sell = initiative_ask_amount.fillna(0)
    
    # 连续竞价成交占比
    # cont_amt_ratio = _amt.loc[93100:145600].sum() / (_amt.sum())
    
    # 特大单成交占比(大于均值+3倍标准差)
    _amt_great = beyond_13_bid_amount.add(beyond_13_ask_amount).fillna(0)
    amt_great_ratio = _amt_great.sum() / (_amt.sum()*2)
    
    # 大单成交占比(大于均值+2倍标准差)
    _amt_big = beyond_11_bid_amount.add(beyond_11_ask_amount).fillna(0)
    amt_big_ratio = _amt_great.sub(_amt_big).sum() / (_amt.sum()*2)
    
    # 中单成交占比(大于均值+0.5倍标准差)
    _amt_median = beyond_8_bid_amount.add(beyond_8_ask_amount).fillna(0)
    amt_median_ratio = _amt_big.sub(_amt_median).sum() / (_amt.sum()*2)
    
    # 小单成交占比(大于均值-2倍标准差)
    _amt_small = beyond_3_bid_amount.add(beyond_3_ask_amount).fillna(0)
    amt_small_ratio = _amt_median.sub(_amt_small).sum() / (_amt.sum()*2)
    
    # 净买入比率
    net_buy_ratio = (_amt_buy.sum() - _amt_sell.sum()) / (_amt.sum())
    
    # 早盘净买入比率
    early_net_buy_ratio = (_amt_buy.iloc[:30].sum() - _amt_sell.iloc[:30].sum()) / (_amt.sum())
    
    # 尾盘净买入比率
    late_net_buy_ratio = (_amt_buy.iloc[-30:].sum() - _amt_sell.iloc[-30:].sum()) / (_amt.sum())
    """
    )
    
    m2 = M.instruments.v2(
        start_date='2018-01-01',
        end_date='2018-12-31',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m3 = M.feature_extractor_1m.v2(
        instruments=m2.data,
        features=m1.data,
        start_date='',
        end_date='',
        before_start_days=0,
        workers=10,
        parallel_mode='集群',
        table_1m='level2_bar1m_CN_STOCK_A'
    )
    
    m4 = M.factorlens_preservation.v2(
        factors_info=m3.data,
        factor_fields={
        'amt_great_ratio':{'name':'deal_ratio_3x', 'desc':'大于均值+3倍标准差的成交金额占当日总成交金额比例'},
        'amt_big_ratio':{'name':'deal_ratio_2x', 'desc':'大于均值+2倍标准差的成交金额占当日总成交金额比例'},
        'amt_median_ratio':{'name':'deal_ratio_05x', 'desc':'大于均值+0.5倍标准差的成交金额占当日总成交金额比例'},
        'amt_small_ratio':{'name':'deal_ratio_n2x', 'desc':'大于均值-2倍标准差的成交金额占当日总成交金额比例'},
        'net_buy_ratio':{'name':'net_buy_ratio', 'desc':'净主动买入金额占当日总成交金额比例'},
        'early_net_buy_ratio':{'name':'early_net_buy_ratio_30m', 'desc':'早盘30分钟净主动买入金额占当日总成交金额比例'},
        'late_net_buy_ratio':{'name':'late_net_buy_ratio_30m', 'desc':'尾盘30分钟净主动买入金额占当日总成交金额比例'}
    }
    ,
        table='hf_factors_cn_stock_a'
    )
    
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-1-2e4394eb98da> in <module>
         57 )
         58 
    ---> 59 m4 = M.factorlens_preservation.v2(
         60     factors_info=m3.data,
         61     factor_fields={
    
    AttributeError: 'NoneType' object has no attribute 'read'
    In [ ]:
    dt = m3.data.read()
    dt.shape, dt.date.min(), dt.date.max()
    
    In [ ]:
    dt.head().T
    
    In [ ]:
    dt.isna().sum()
    
    In [ ]:
    dt.describe().T
    
    In [ ]:
    dt2 = dt.set_index(['date','instrument'])
    dt2.head()
    
    In [ ]:
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    In [ ]:
    # %%time
    n=4#行数
    m=dt2.shape[1]
    x=m%n
    fig,axes=plt.subplots(n,int((m - x + (n if x else x))/n),figsize=(20, 10))
    axes=axes.reshape((-1,))
    for i in range(dt2.shape[1]):    
        sns.distplot(dt2[dt2.columns[i]],ax=axes[i])
    plt.subplots_adjust(wspace =0.3, hspace =0.3)
    
    In [ ]:
    # for i in dt2.columns[:]:
    #     dt2[i].to_hdf(f'XX券商-XXXX研报-{i}.h5', 'fac', mode='w')
    
    In [ ]:
     
    
    In [ ]:
     
    
    In [ ]:
     
    
    In [ ]:
     
    
    In [ ]: