克隆策略

    {"description":"实验创建于2017/8/26","graph":{"edges":[{"to_node_id":"-322:features","from_node_id":"-331:data"},{"to_node_id":"-322:instruments","from_node_id":"-312:data"},{"to_node_id":"-322:user_functions","from_node_id":"-9065:functions"}],"nodes":[{"node_id":"-331","module_id":"BigQuantSpace.input_features.input_features-v1","parameters":[{"name":"features","value":"_Fx = pd.Series(np.log(1 - np.arange(1/8, 1, 1/8)).tolist())\n\n_tbv = total_bid_volume\n_tav = total_ask_volume\n\n# 帕累托系数因子\n_entrust_volume = _tbv.add(_tav)\n_entrust_volume_quantile = (_entrust_volume.quantile(np.arange(1/8, 1, 1/8).tolist()).sort_values(ascending=False)).apply(np.log)\nPareto = get_coef(_Fx, _entrust_volume_quantile)\n\n\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":"2020-03-01","type":"Literal","bound_global_parameter":null},{"name":"end_date","value":"2020-05-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\n000002.SZA\n000005.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":"-312"}],"output_ports":[{"name":"data","node_id":"-312"}],"cacheable":true,"seq_num":2,"comment":"","comment_collapsed":true},{"node_id":"-322","module_id":"BigQuantSpace.feature_extractor_1m.feature_extractor_1m-v1","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":"20","type":"Literal","bound_global_parameter":null},{"name":"workers","value":2,"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":"-322"},{"name":"features","node_id":"-322"},{"name":"user_functions","node_id":"-322"}],"output_ports":[{"name":"data","node_id":"-322"}],"cacheable":false,"seq_num":3,"comment":"","comment_collapsed":true},{"node_id":"-9065","module_id":"BigQuantSpace.feature_extractor_user_function.feature_extractor_user_function-v1","parameters":[{"name":"name","value":"get_coef","type":"Literal","bound_global_parameter":null},{"name":"func","value":"def bigquant_run(df, x, y):\n from sklearn import linear_model\n\n X = np.array(x.fillna(0))\n Y = np.array(y.fillna(0)).reshape(-1,1)\n \n model = linear_model.LinearRegression().fit(Y, X)\n res = 1 - model.coef_.flatten()[0]\n return res","type":"Literal","bound_global_parameter":null}],"input_ports":[{"name":"input_functions","node_id":"-9065"}],"output_ports":[{"name":"functions","node_id":"-9065"}],"cacheable":false,"seq_num":4,"comment":"","comment_collapsed":true}],"node_layout":"<node_postions><node_position Node='-331' Position='-134,-239.43505859375,200,200'/><node_position Node='-312' Position='-440,-239,200,200'/><node_position Node='-322' Position='-130,-132,200,200'/><node_position Node='-9065' Position='209,-240,200,200'/></node_postions>"},"nodes_readonly":false,"studio_version":"v2"}
    In [23]:
    # 本代码由可视化策略环境自动生成 2021年7月9日15:29
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    def m4_func_bigquant_run(df, x, y):
        from sklearn import linear_model
    
        X = np.array(x.fillna(0))
        Y = np.array(y.fillna(0)).reshape(-1,1)
        
        model = linear_model.LinearRegression().fit(Y, X)
        res = 1 - model.coef_.flatten()[0]
        return res
    
    m1 = M.input_features.v1(
        features="""_Fx = pd.Series(np.log(1 - np.arange(1/8, 1, 1/8)).tolist())
    
    _tbv = total_bid_volume
    _tav = total_ask_volume
    
    # 帕累托系数因子
    _entrust_volume = _tbv.add(_tav)
    _entrust_volume_quantile = (_entrust_volume.quantile(np.arange(1/8, 1, 1/8).tolist()).sort_values(ascending=False)).apply(np.log)
    Pareto = get_coef(_Fx, _entrust_volume_quantile)
    
    
    """
    )
    
    m2 = M.instruments.v2(
        start_date='2020-03-01',
        end_date='2020-05-01',
        market='CN_STOCK_A',
        instrument_list="""000001.SZA
    000002.SZA
    000005.SZA""",
        max_count=0
    )
    
    m4 = M.feature_extractor_user_function.v1(
        name='get_coef',
        func=m4_func_bigquant_run
    )
    
    m3 = M.feature_extractor_1m.v1(
        instruments=m2.data,
        features=m1.data,
        user_functions=m4.functions,
        start_date='',
        end_date='',
        before_start_days=20,
        workers=2,
        parallel_mode='测试',
        table_1m='level2_bar1m_CN_STOCK_A',
        m_cached=False
    )
    
    In [24]:
    dt = m3.data.read()
    dt.shape, dt.date.min(), dt.date.max()
    
    Out[24]:
    ((174, 3), Timestamp('2020-02-10 00:00:00'), Timestamp('2020-04-30 00:00:00'))
    In [25]:
    dt.head().T
    
    Out[25]:
    0 1 2 3 4
    Pareto -4.12425 -3.940178 -3.722134 -3.779374 -6.699087
    date 2020-02-10 00:00:00 2020-02-10 00:00:00 2020-02-10 00:00:00 2020-02-11 00:00:00 2020-02-11 00:00:00
    instrument 000001.SZA 000002.SZA 000005.SZA 000001.SZA 000002.SZA
    In [26]:
    dt.isna().sum()
    
    Out[26]:
    Pareto        0
    date          0
    instrument    0
    dtype: int64
    In [27]:
    dt.describe().T
    
    Out[27]:
    count mean std min 25% 50% 75% max
    Pareto 174.0 -5.604539 2.977703 -19.037901 -6.874175 -4.897162 -3.684896 -0.545282
    In [28]:
    dt2 = dt.set_index(['date','instrument'])
    dt2.head()
    
    Out[28]:
    Pareto
    date instrument
    2020-02-10 000001.SZA -4.124250
    000002.SZA -3.940178
    000005.SZA -3.722134
    2020-02-11 000001.SZA -3.779374
    000002.SZA -6.699087
    In [29]:
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    In [30]:
    # %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 [31]:
    # for i in dt2.columns[:]:
    #     dt2[i].to_hdf(f'XX券商-XXXX研报-{i}.h5', 'fac', mode='w')
    
    In [ ]:
     
    
    In [ ]:
     
    
    In [ ]:
     
    
    In [ ]:
     
    
    In [ ]: