复制链接
克隆策略
In [3]:
# 量化专题报告“量价淘金”选股因子系列研究(一)如何将隔夜涨跌变为有效的选股因子? ——基于对知情交易者信息优势的刻画
# 更新时间:2022.5.21


def cal_bm_open(df):
    bm_df = DataSource('bar1d_index_CN_STOCK_A').read(instruments=['000008.HIX'])
    bm_df.rename(columns={'open':'benchmark_open_0'}, inplace=True)
    merge_df = pd.merge(df, bm_df[['date','benchmark_open_0']], on='date', how='left')
    return merge_df['benchmark_open_0']

def cal_bm_close(df):
    bm_df = DataSource('bar1d_index_CN_STOCK_A').read(instruments=['000008.HIX'])
    bm_df.rename(columns={'close':'benchmark_close_1'}, inplace=True)
    bm_df['benchmark_close_1']=bm_df['benchmark_close_1'].shift(1)
    merge_df = pd.merge(df, bm_df[['date','benchmark_close_1']], on='date', how='left')
    return merge_df['benchmark_close_1']

def cal_bm_turn(df):
    bm_df = DataSource('bar1d_index_CN_STOCK_A').read(instruments=['000008.HIX'])
    bm_df.rename(columns={'turn':'benchmark_turn_1'}, inplace=True)
    bm_df['benchmark_turn_1']=bm_df['benchmark_turn_1'].shift(1)
    merge_df = pd.merge(df, bm_df[['date','benchmark_turn_1']], on='date', how='left')
    return merge_df['benchmark_turn_1']

m16_user_functions_bigquant_run = {
    'cal_bm_open': cal_bm_open,
    'cal_bm_close': cal_bm_close,
    'cal_bm_turn':cal_bm_turn
}


m1 = M.instruments.v2(
    start_date='2012-01-01',
    end_date='2022-05-18',
    market='CN_STOCK_A',
    instrument_list='',
    max_count=0,
    m_cached=False
)

m3 = M.input_features.v1(
    features="""# #号开始的表示注释

close=close_1
open= open_0
turn=turn_1
benchmark_open_0 = cal_bm_open() # 基准指数开盘价
benchmark_close_1 = cal_bm_close() # 基准指数收盘价
benchmark_turn_1 = cal_bm_turn() # 基准指数换手率
"""
)

m15 = M.general_feature_extractor.v7(
    instruments=m1.data,
    features=m3.data,
    start_date='2012-01-01',
    end_date='2022-05-18',
    before_start_days=90
)

m16 = M.derived_feature_extractor.v3(
    input_data=m15.data,
    features=m3.data,
    date_col='date',
    instrument_col='instrument',
    drop_na=True,
    remove_extra_columns=False,
    user_functions=m16_user_functions_bigquant_run
)

m5 = M.input_features.v1(
    features="""overnight"""
)

m4 = M.input_features.v1(
    features="""overnight=correlation(abs((open/close-1)-(benchmark_open_0/benchmark_close_1-1)), turn-benchmark_turn_1, 20)"""
)

m7 = M.derived_feature_extractor.v3(
    input_data=m16.data,
    features=m4.data,
    date_col='date',
    instrument_col='instrument',
    drop_na=True,
    remove_extra_columns=True,
    user_functions={}
)

m2 = M.factorlens.v2(
    features=m5.data,
    user_factor_data=m7.data,
    title='因子分析: {factor_name}',
    start_date='2012-01-01',
    end_date='2022-05-18',
    rebalance_period=20,
    delay_rebalance_days=0,
    rebalance_price='close_0',
    stock_pool='全市场',
    quantile_count=5,
    commission_rate=0.0016,
    returns_calculation_method='累乘',
    benchmark='无',
    drop_new_stocks=60,
    drop_price_limit_stocks=False,
    drop_st_stocks=True,
    drop_suspended_stocks=True,
    cutoutliers=True,
    normalization=True,
    neutralization=['行业', '市值'],
    metrics=['因子表现概览', '因子分布', '因子行业分布', '因子市值分布', 'IC分析', '买入信号重合分析', '因子估值分析', '因子拥挤度分析', '因子值最大/最小股票', '表达式因子值', '多因子相关性分析'],
    factor_coverage=0.5,
    user_data_merge='left'
)

因子分析: overnight

{ "type": "factor-track", "data": { "exprs": ["overnight"], "options": {"BacktestInterval": ["2012-01-01", "2022-05-18"], "Benchmark": "none", "StockPool": "all", "UserDataMerge": "left", "DropSTStocks": 1, "DropPriceLimitStocks": 0, "DropNewStocks": 60, "DropSuspendedStocks": 1, "QuantileCount": 5, "CommissionRates": 0.0016, "Cutoutliers": 1, "Normalization": 1, "Neutralization": "industry,size", "DelayRebalanceDays": 0, "RebalancePeriod": 20, "RebalancePeriodsReturns": 0, "RebalancePrice": "close_0", "ReturnsCalculationMethod": "cumprod", "FactorCoverage": 0.5, "_HASH": "d24d914809ed95d52c49894b2d793161"} } }

因子表现概览

  累计收益 近1年收益 近3月收益 近1月收益 近1周收益 昨日收益 最大回撤 盈亏比 胜率 夏普比率 收益波动率
最小分位 279.91% 2.78% -11.51% -5.89% 1.92% -0.21% 57.22% 0.89 0.56 0.49 29.25%
最大分位 26.24% -4.39% -12.76% -8.28% 1.69% -0.45% 73.55% 0.87 0.55 0.11 29.84%
多空组合 71.60% 3.48% 0.63% 1.23% 0.11% 0.12% 1.88% 1.25 0.56 1.00 1.92%

基本特征分析

IC分析

-0.04

0.04

-1.14

80.16%

买入信号重合分析

因子估值分析

因子拥挤度分析

因子值最小的20只股票 (2022-05-17)

股票名称 股票代码 因子值
上海能源 600508.SHA -0.7428
国美通讯 600898.SHA -0.7225
德奥退 002260.SZA -0.7021
瑞松科技 688090.SHA -0.6216
金种子酒 600199.SHA -0.6035
蓝焰控股 000968.SZA -0.5941
索菱股份 002766.SZA -0.5851
苏盐井神 603299.SHA -0.5640
燕京啤酒 000729.SZA -0.5294
上海机电 600835.SHA -0.5174
亚士创能 603378.SHA -0.5036
鲁阳节能 002088.SZA -0.4935
华润双鹤 600062.SHA -0.4906
皇庭国际 000056.SZA -0.4877
太辰光 300570.SZA -0.4872
仙琚制药 002332.SZA -0.4849
吉冈精密 836720.BJA -0.4806
华维设计 833427.BJA -0.4797
纬德信息 688171.SHA -0.4683
深科技 000021.SZA -0.4671

因子值最大的20只股票 (2022-05-17)

股票名称 股票代码 因子值
阳普医疗 300030.SZA 0.8086
中国铁物 000927.SZA 0.8125
华安证券 600909.SHA 0.8127
长江投资 600119.SHA 0.8130
中国科传 601858.SHA 0.8142
桂发祥 002820.SZA 0.8200
星徽股份 300464.SZA 0.8224
开润股份 300577.SZA 0.8249
兆丰股份 300695.SZA 0.8258
榕基软件 002474.SZA 0.8321
珠海港 000507.SZA 0.8339
长久物流 603569.SHA 0.8357
宇环数控 002903.SZA 0.8375
方盛制药 603998.SHA 0.8409
华神科技 000790.SZA 0.8603
弘宇股份 002890.SZA 0.8629
第一创业 002797.SZA 0.8734
七匹狼 002029.SZA 0.8762
中央商场 600280.SHA 0.9084
日上集团 002593.SZA 0.9438