复制链接
克隆策略
In [3]:
def m4_func_bigquant_run(df, ret):
    return np.power(ret, 2).sum()

# Python 代码入口函数,input_1/2/3 对应三个输入端,data_1/2/3 对应三个输出端
def m10_run_bigquant_run(input_1, input_2, input_3):
    # 示例代码如下。在这里编写您的代码
    df = input_1.read()
    data_1 = DataSource.write_df(df.sort_values(by=['instrument','date'], ascending=[True,True]).reset_index(drop=True))
    
    return Outputs(data_1=data_1, data_2=None, data_3=None)

# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
def m10_post_run_bigquant_run(outputs):
    return outputs


m1 = M.input_features.v1(
    features="""
_ret = close.pct_change().fillna(close.iloc[0]/open.iloc[0])
ret= close.pct_change().fillna(close.iloc[0]/open.iloc[0])
AmtPerTrd_0=amount.sum()/volume.sum()
limit_ret=where(_ret.sum()==1,1,0)
AmtperTrd_inflow_0=(amount*where(_ret>0, 1, 0)).sum()/(volume*where(_ret>0, 1, 0)).sum()
AmtperTrd_outflow_0=(amount*where(_ret<0, 1, 0)).sum()/(volume*where(_ret<0, 1, 0)).sum()

Apt_inflow_ratio_0=AmtperTrd_inflow_0/AmtPerTrd_0
Apt_outflow_ratio_0=AmtperTrd_outflow_0/AmtPerTrd_0
Apt_netflow_ratio_0=Apt_inflow_ratio_0/Apt_outflow_ratio_0


_amt_Per_Trd = amount/volume
_Idxset=_amt_Per_Trd.nlargest(24)[-2:-1].values

_amt_inflow_bigorder=where(_ret>0 ,amount, 0)
amt_inflow_bigorder_0=where(_amt_Per_Trd>_Idxset,_amt_inflow_bigorder,0).sum()


_amt_outflow_bigorder=where(_ret<0 , amount,0)
amt_outflow_bigorder_0=where(_amt_Per_Trd>_Idxset,_amt_outflow_bigorder,0).sum()


amt_netinflow_bigorder_0=amt_inflow_bigorder_0-amt_outflow_bigorder_0


amt_netinflow_bigorder_ratio_0=amt_netinflow_bigorder_0/amount.sum()


"""
)

m2 = M.instruments.v2(
    start_date='2020-01-01',
    end_date='2022-05-25',
    market='CN_STOCK_A',
    instrument_list=instruments_list,
    max_count=0
)

m4 = M.feature_extractor_user_function.v1(
    name='RVar',
    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=90,
    workers=2,
    parallel_mode='集群',
    table_1m='bar1m_CN_STOCK_A'
)

m11 = M.dropnan.v2(
    input_data=m3.data
)

m10 = M.cached.v3(
    input_1=m11.data,
    run=m10_run_bigquant_run,
    post_run=m10_post_run_bigquant_run,
    input_ports='',
    params='{}',
    output_ports=''
)

m6 = M.input_features.v1(
    features="""#特征列表



# fanzhuan_20=sum(fanzhuan, 20)
Apt_inflow_ratio_20=mean(Apt_inflow_ratio_0,20)
Apt_outflow_ratio_20=mean(Apt_outflow_ratio_0,20)
Apt_netflow_ratio_20=mean(Apt_netflow_ratio_0,20)
amt_netinflow_bigorder_20=mean(amt_netinflow_bigorder_0,20)
amt_netinflow_bigorder_ratio_20=mean(amt_netinflow_bigorder_ratio_0,20)
"""
)

m5 = M.derived_feature_extractor.v3(
    input_data=m10.data_1,
    features=m6.data,
    date_col='date',
    instrument_col='instrument',
    drop_na=False,
    remove_extra_columns=False,
    user_functions={}
)

m7 = M.dropnan.v2(
    input_data=m5.data
)
In [4]:
feature_list=['Apt_inflow_ratio_20',
'Apt_outflow_ratio_20',
'Apt_netflow_ratio_20',
'amt_netinflow_bigorder_20',
'amt_netinflow_bigorder_ratio_20']




def factor_analyse(feature):
    m9 = M.input_features.v1(
        features=feature
    )

    m8 = M.factorlens_custom.v2(
    features=m9.data,
    factor_data=m7.data,
    start_date='2020-01-01',
    end_date='2022-05-25',
    instrument_list=instruments_list,
    expr='',
    rebalance_period=20,
    quantile_num=5,
    buy_commission_rate=0.0005,
    sell_commission_rate=0.0005,
    ic_method='Rank_IC',
    is_winsorize=True,
    is_standardlize=True
    )

for i in feature_list:
    factor_analyse(i)

Apt_inflow_ratio_20: IC分析

  • IC均值-0.0276
  • IC标准差0.1272
  • ICIR-0.217
  • IC正值次数10次
  • IC负值次数18次
  • IC偏度0.437
  • IC峰度-0.7919

Apt_inflow_ratio_20: 因子收益率分析

  • 因子收益均值-0.0016
  • 因子收益标准差0.013
  • 因子收益为正比率39.290000000000006%
  • t值绝对值的均值1.5824
  • t值绝对值大于2的比率0.3214
  • 因子收益t检验p值小于0.05的比率0.3571

Apt_inflow_ratio_20: 因子绩效分析

  •   top0_ret top4_ret LS_ret
  • 收益率 0.4711 0.1769 0.1065
  • 近1日收益率 0.0054 0.0178 -0.0062
  • 近1周收益率 -0.0061 0.0159 -0.0113
  • 近1月收益率 -0.0432 0.0052 -0.0261
  • 年化收益率 0.1836 0.0737 0.0452
  • 夏普比率 0.72 0.2716 0.172
  • 收益波动率 0.2191 0.2392 0.0663
  • 最大回撤 -0.2317 -0.2869 -0.0827

Apt_outflow_ratio_20: IC分析

  • IC均值0.0286
  • IC标准差0.0957
  • ICIR0.2989
  • IC正值次数16次
  • IC负值次数12次
  • IC偏度-0.0172
  • IC峰度-0.1851

Apt_outflow_ratio_20: 因子收益率分析

  • 因子收益均值0.0009
  • 因子收益标准差0.0112
  • 因子收益为正比率50.0%
  • t值绝对值的均值1.4654
  • t值绝对值大于2的比率0.3571
  • 因子收益t检验p值小于0.05的比率0.3571

Apt_outflow_ratio_20: 因子绩效分析

  •   top0_ret top4_ret LS_ret
  • 收益率 0.1058 0.4297 -0.1142
  • 近1日收益率 0.0158 0.0091 0.0034
  • 近1周收益率 0.0091 0.0028 0.0032
  • 近1月收益率 0.0018 -0.0163 0.0094
  • 年化收益率 0.0449 0.169 -0.0516
  • 夏普比率 0.162 0.6843 -1.467
  • 收益波动率 0.2512 0.2092 0.0588
  • 最大回撤 -0.3388 -0.2176 -0.1608

Apt_netflow_ratio_20: IC分析

  • IC均值-0.0325
  • IC标准差0.1084
  • ICIR-0.2998
  • IC正值次数10次
  • IC负值次数18次
  • IC偏度0.283
  • IC峰度-0.8626

Apt_netflow_ratio_20: 因子收益率分析

  • 因子收益均值-0.0013
  • 因子收益标准差0.0109
  • 因子收益为正比率35.709999999999994%
  • t值绝对值的均值1.3719
  • t值绝对值大于2的比率0.25
  • 因子收益t检验p值小于0.05的比率0.2857

Apt_netflow_ratio_20: 因子绩效分析

  •   top0_ret top4_ret LS_ret
  • 收益率 0.4258 0.1438 0.1009
  • 近1日收益率 0.0056 0.0181 -0.0063
  • 近1周收益率 -0.0 0.0187 -0.0095
  • 近1月收益率 -0.0342 0.0204 -0.0283
  • 年化收益率 0.1676 0.0604 0.0429
  • 夏普比率 0.6737 0.2203 0.1452
  • 收益波动率 0.2114 0.2484 0.0609
  • 最大回撤 -0.2226 -0.3392 -0.056

amt_netinflow_bigorder_20: IC分析

  • IC均值-0.0298
  • IC标准差0.1052
  • ICIR-0.2833
  • IC正值次数11次
  • IC负值次数17次
  • IC偏度0.0056
  • IC峰度-0.7583

amt_netinflow_bigorder_20: 因子收益率分析

  • 因子收益均值-0.0011
  • 因子收益标准差0.0126
  • 因子收益为正比率39.290000000000006%
  • t值绝对值的均值1.5635
  • t值绝对值大于2的比率0.3571
  • 因子收益t检验p值小于0.05的比率0.3571

amt_netinflow_bigorder_20: 因子绩效分析

  •   top0_ret top4_ret LS_ret
  • 收益率 0.2525 0.0928 0.0445
  • 近1日收益率 0.0107 0.0063 0.0022
  • 近1周收益率 0.0014 -0.0023 0.0019
  • 近1月收益率 -0.0155 -0.0324 0.0088
  • 年化收益率 0.1033 0.0395 0.0192
  • 夏普比率 0.4186 0.147 -0.1624
  • 收益波动率 0.1986 0.2642 0.0792
  • 最大回撤 -0.2947 -0.3474 -0.1587

amt_netinflow_bigorder_ratio_20: IC分析

  • IC均值-0.0124
  • IC标准差0.1261
  • ICIR-0.0983
  • IC正值次数15次
  • IC负值次数13次
  • IC偏度-0.3445
  • IC峰度-0.317

amt_netinflow_bigorder_ratio_20: 因子收益率分析

  • 因子收益均值-0.0007
  • 因子收益标准差0.0139
  • 因子收益为正比率50.0%
  • t值绝对值的均值1.6503
  • t值绝对值大于2的比率0.2143
  • 因子收益t检验p值小于0.05的比率0.2857

amt_netinflow_bigorder_ratio_20: 因子绩效分析

  •   top0_ret top4_ret LS_ret
  • 收益率 0.2711 0.1706 0.045
  • 近1日收益率 0.0078 0.0133 -0.0027
  • 近1周收益率 -0.001 0.0081 -0.0044
  • 近1月收益率 -0.009 -0.0037 -0.0018
  • 年化收益率 0.1105 0.0712 0.0194
  • 夏普比率 0.416 0.2677 -0.2326
  • 收益波动率 0.2336 0.206 0.0601
  • 最大回撤 -0.2988 -0.2819 -0.1213
In [2]:
#定义沪深300列表
instruments_list="""
    688009.SHA
601668.SHA
600383.SHA
600111.SHA
600570.SHA
600637.SHA
600900.SHA
600763.SHA
600886.SHA
600795.SHA
601288.SHA
600606.SHA
600109.SHA
600655.SHA
601077.SHA
600438.SHA
601328.SHA
600809.SHA
601872.SHA
601808.SHA
603501.SHA
601377.SHA
603259.SHA
601989.SHA
601555.SHA
600600.SHA
601601.SHA
603899.SHA
603156.SHA
601577.SHA
601888.SHA
002007.SZA
601688.SHA
601138.SHA
601111.SHA
600150.SHA
601857.SHA
601818.SHA
600118.SHA
600177.SHA
601360.SHA
603833.SHA
600018.SHA
002153.SZA
000100.SZA
000725.SZA
002311.SZA
000338.SZA
002120.SZA
300498.SZA
000895.SZA
000876.SZA
600000.SHA
002916.SZA
002146.SZA
300059.SZA
600741.SHA
600019.SHA
002142.SZA
300003.SZA
002371.SZA
002230.SZA
000166.SZA
300529.SZA
600010.SHA
000961.SZA
002773.SZA
002414.SZA
300142.SZA
002422.SZA
002607.SZA
300347.SZA
300014.SZA
600011.SHA
600050.SHA
000800.SZA
300450.SZA
600079.SHA
600521.SHA
688363.SHA
601799.SHA
603939.SHA
603486.SHA
601728.SHA
002064.SZA
300750.SZA
300782.SZA
300896.SZA
002791.SZA
600352.SHA
601766.SHA
600893.SHA
600271.SHA
600872.SHA
600588.SHA
600309.SHA
600196.SHA
600837.SHA
600848.SHA
600369.SHA
601186.SHA
688036.SHA
600487.SHA
601390.SHA
600660.SHA
600519.SHA
601236.SHA
600340.SHA
603369.SHA
603993.SHA
603392.SHA
601198.SHA
600104.SHA
600760.SHA
601238.SHA
688008.SHA
603160.SHA
603195.SHA
603658.SHA
600926.SHA
600332.SHA
601216.SHA
600919.SHA
601166.SHA
601988.SHA
601901.SHA
601155.SHA
601618.SHA
601021.SHA
603087.SHA
000069.SZA
000001.SZA
002252.SZA
002410.SZA
000596.SZA
600066.SHA
002236.SZA
000858.SZA
002001.SZA
000425.SZA
000625.SZA
000333.SZA
002157.SZA
000860.SZA
002241.SZA
000157.SZA
000728.SZA
600004.SHA
300033.SZA
600016.SHA
000627.SZA
002714.SZA
300408.SZA
002938.SZA
002945.SZA
300433.SZA
002475.SZA
300601.SZA
002008.SZA
000066.SZA
002673.SZA
002602.SZA
002939.SZA
600036.SHA
300558.SZA
300595.SZA
603517.SHA
603806.SHA
603233.SHA
603882.SHA
600905.SHA
601966.SHA
601868.SHA
688599.SHA
300759.SZA
300999.SZA
002466.SZA
601696.SHA
601800.SHA
600690.SHA
600705.SHA
601990.SHA
601916.SHA
601336.SHA
603799.SHA
600498.SHA
600208.SHA
600176.SHA
600161.SHA
601211.SHA
600276.SHA
600362.SHA
600547.SHA
600406.SHA
600297.SHA
600390.SHA
601066.SHA
601838.SHA
601088.SHA
601229.SHA
601318.SHA
600845.SHA
601919.SHA
601985.SHA
601816.SHA
601899.SHA
603288.SHA
601012.SHA
601998.SHA
603986.SHA
601009.SHA
600584.SHA
601100.SHA
601117.SHA
601877.SHA
600233.SHA
601169.SHA
002271.SZA
600030.SHA
002812.SZA
000656.SZA
000063.SZA
002027.SZA
000568.SZA
002352.SZA
002050.SZA
001979.SZA
002958.SZA
000671.SZA
300676.SZA
002202.SZA
002304.SZA
300413.SZA
002129.SZA
002558.SZA
002508.SZA
000768.SZA
600015.SHA
300122.SZA
300628.SZA
002415.SZA
002555.SZA
600061.SHA
002460.SZA
000783.SZA
002601.SZA
002384.SZA
002739.SZA
000938.SZA
600132.SHA
300274.SZA
600143.SHA
688169.SHA
603338.SHA
601995.SHA
688561.SHA
603260.SHA
601898.SHA
000301.SZA
300760.SZA
300888.SZA
002459.SZA
600522.SHA
600989.SHA
600745.SHA
600585.SHA
600085.SHA
601600.SHA
601788.SHA
601231.SHA
600703.SHA
601319.SHA
600115.SHA
601162.SHA
600299.SHA
600482.SHA
600887.SHA
600489.SHA
000661.SZA
601006.SHA
601878.SHA
601607.SHA
601939.SHA
600346.SHA
600999.SHA
688012.SHA
601398.SHA
601881.SHA
601933.SHA
600918.SHA
601669.SHA
601698.SHA
601727.SHA
600183.SHA
002044.SZA
601628.SHA
600998.SHA
601225.SHA
600436.SHA
603019.SHA
601633.SHA
601658.SHA
600029.SHA
000538.SZA
002594.SZA
002493.SZA
000776.SZA
000708.SZA
002179.SZA
600025.SHA
002821.SZA
002032.SZA
000703.SZA
300144.SZA
000963.SZA
002624.SZA
000002.SZA
000786.SZA
300124.SZA
002841.SZA
300015.SZA
002049.SZA
600027.SHA
000723.SZA
600028.SHA
000977.SZA
600048.SHA
300136.SZA
002463.SZA
002600.SZA
002456.SZA
003816.SZA
000651.SZA
002736.SZA
600031.SHA
688396.SHA
300677.SZA
688126.SHA
603659.SHA
600426.SHA
688111.SHA
605499.SHA
601865.SHA
688981.SHA
002568.SZA
300316.SZA
300866.SZA
002709.SZA  
    """