import numpy as np
import pandas as pd
import utils
import factor_analysis as fa
from get_data import get_data as gd
from factors_library import get_factors as gf
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib
returns = gd.get_stocks_monthly(from_month='2010-01',to_month='2021-11').set_index(['trade_month','stock_code'])
returns = returns[['Mretwd']].rename(columns={'Mretwd':'returns'})
returns
returns | ||
---|---|---|
trade_month | stock_code | |
2010-01 | 000001 | -0.109561 |
000002 | -0.135985 | |
000005 | -0.104651 | |
000006 | -0.120918 | |
000007 | -0.017070 | |
... | ... | ... |
2021-11 | 900948 | -0.085352 |
900952 | -0.000002 | |
900953 | -0.055721 | |
900955 | -0.079365 | |
900957 | -0.040943 |
428134 rows × 1 columns
all_a_pool = gd.get_stocks_daily(trade_date='2021-12-31',pool='all_a_market')
liquid_pool = gd.get_stocks_daily(trade_date='2021-12-31',pool='liquid_perc70')
mc_pool=pd.concat([pd.DataFrame({'市值对数':np.log(all_a_pool.Dsmvtll),'股票池':'全市场'}),pd.DataFrame({'市值对数':np.log(liquid_pool.Dsmvtll),'股票池':'高流动性'})])
fig, ax = plt.subplots(figsize=(10, 3),dpi=100)
matplotlib.rcParams['font.sans-serif']=['kaiti']
sns.kdeplot(data=mc_pool, x="市值对数", hue="股票池", fill=True, common_norm=False, alpha=0.4)
plt.ylabel("密度")
plt.title('20201年12月31日股票池成分股市值分布对比')
plt.show()
summ_df.sort_values('夏普比率',ascending = False)
t值 | 年化收益率(%) | 累计收益率(%) | 年化波动率(%) | 夏普比率 | 最大回测(%) | |
---|---|---|---|---|---|---|
换手率波动率(最近一月) | 2.310941 | 16.615841 | 181.813800 | 22.790853 | 0.729057 | 26.770884 |
换手率(最近一月) | 1.596955 | 11.960025 | 133.398811 | 24.198138 | 0.494254 | 29.917020 |
换手率波动率(最近一年) | 1.568547 | 11.508702 | 128.607808 | 23.751577 | 0.484545 | 38.485839 |
下行Beta | 1.540967 | 10.161958 | 114.204968 | 21.469125 | 0.473329 | 25.452989 |
市场Beta | 1.515955 | 10.296559 | 115.651717 | 22.099795 | 0.465912 | 30.293591 |
非流动性(最近一月) | 1.367809 | 9.358872 | 105.539207 | 22.351728 | 0.418709 | 31.780758 |
条件偏度 | 1.318597 | 9.053815 | 102.232151 | 22.459396 | 0.403119 | 22.119254 |
短期反转 | 1.195095 | 8.314845 | 94.185807 | 22.829977 | 0.364207 | 26.061225 |
总波动率(最近一年) | 1.138422 | 8.936145 | 100.954246 | 25.688815 | 0.347861 | 24.994772 |
相对Beta | 1.102729 | 6.912485 | 78.776576 | 20.694306 | 0.334028 | 40.689706 |
动量(最近一年) | 1.102512 | 6.703755 | 76.467181 | 20.091596 | 0.333660 | 64.222693 |
特定动量 | 1.100871 | 7.043917 | 80.228610 | 21.111327 | 0.333656 | 35.749658 |
特定波动率(最近一年) | 1.026657 | 8.307506 | 94.105642 | 26.552953 | 0.312866 | 33.988191 |
换手率(最近一年) | 0.943649 | 7.326261 | 83.342374 | 25.584575 | 0.286355 | 38.560136 |
总市值对数 | 0.885551 | 6.742618 | 76.897478 | 25.154809 | 0.268045 | 41.691550 |
特定波动率(最近一月) | 0.861525 | 5.512646 | 63.208899 | 21.253626 | 0.259374 | 30.370142 |
总波动率(最近一月) | 0.820765 | 5.546495 | 63.587568 | 22.442749 | 0.247140 | 28.975416 |
非流动性(最近一年) | 0.783385 | 5.486801 | 62.919695 | 23.266667 | 0.235822 | 38.745707 |
流通市值对数 | 0.689302 | 5.368181 | 61.591529 | 25.884174 | 0.207392 | 47.112967 |
异常换手率 | 0.620338 | 3.600087 | 41.629972 | 19.440172 | 0.185188 | 37.526980 |
特定偏度 | 0.616952 | 3.356662 | 38.857288 | 18.245002 | 0.183977 | 33.894420 |
动量(最近六月) | 0.561019 | 3.235404 | 37.473884 | 19.349693 | 0.167207 | 91.670806 |
偏度 | 0.557971 | 2.470875 | 28.717054 | 14.909086 | 0.165729 | 29.771409 |
动量变化 | 0.462799 | 2.239504 | 26.055140 | 16.308854 | 0.137318 | 26.783360 |
非线性市值 | 0.395620 | 1.431782 | 16.718768 | 12.241886 | 0.116958 | 27.106548 |
上行Beta | 0.247077 | 1.345683 | 15.719545 | 18.430242 | 0.073015 | 32.639894 |
流通市值占比 | -0.241870 | -0.553753 | -6.525089 | 7.814972 | -0.070858 | 40.363451 |
turn_std_1m_factor = liquidity_factor[['turn_std_1m']].rename(columns={'turn_std_1m':'factor'})
fa_turn_std_1m = fa.factor_analysis(factors=turn_std_1m_factor,returns=returns)
fa_turn_std_1m.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.277648 | 7.374851 | 83.877475 | 19.017644 | 0.387790 | 32.581290 |
group 2 | 1.376906 | 10.775582 | 120.787332 | 25.412054 | 0.424034 | 42.028981 |
group 3 | 0.904695 | 7.546067 | 85.761254 | 27.460682 | 0.274795 | 52.976309 |
group 4 | 0.488848 | 4.355943 | 50.201458 | 29.748527 | 0.146426 | 66.640158 |
group 5 | -0.903347 | -8.021232 | -97.936325 | 31.405951 | -0.255405 | 120.961724 |
group longshort | 2.310941 | 16.615841 | 181.813800 | 22.790853 | 0.729057 | 26.770884 |
fa_turn_std_1m.quantile_returns_plot()
fa_turn_std_1m.factor_ts_regr_cmpt(pricing_model='FF-3')
OLS Regression Results ============================================================================== Dep. Variable: returns R-squared: 0.674 Model: OLS Adj. R-squared: 0.667 Method: Least Squares F-statistic: 48.20 Date: Fri, 14 Jan 2022 Prob (F-statistic): 2.04e-21 Time: 04:09:44 Log-Likelihood: 266.92 No. Observations: 143 AIC: -525.8 Df Residuals: 139 BIC: -514.0 Df Model: 3 Covariance Type: HAC =============================================================================== coef std err t P>|t| [0.025 0.975] ------------------------------------------------------------------------------- const -0.0203 0.003 -7.254 0.000 -0.026 -0.015 RiskPremium 0.2604 0.056 4.620 0.000 0.149 0.372 SMB 0.7911 0.113 7.009 0.000 0.568 1.014 HML -0.2646 0.141 -1.871 0.063 -0.544 0.015 ============================================================================== Omnibus: 7.260 Durbin-Watson: 2.080 Prob(Omnibus): 0.027 Jarque-Bera (JB): 7.466 Skew: 0.410 Prob(JB): 0.0239 Kurtosis: 3.762 Cond. No. 45.4 ============================================================================== Notes: [1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 5 lags and without small sample correction
fa_turn_std_1m.factor_ts_regr_cmpt(pricing_model='FF-5')
OLS Regression Results ============================================================================== Dep. Variable: returns R-squared: 0.686 Model: OLS Adj. R-squared: 0.674 Method: Least Squares F-statistic: 47.44 Date: Fri, 14 Jan 2022 Prob (F-statistic): 2.87e-28 Time: 04:09:32 Log-Likelihood: 269.46 No. Observations: 143 AIC: -526.9 Df Residuals: 137 BIC: -509.1 Df Model: 5 Covariance Type: HAC =============================================================================== coef std err t P>|t| [0.025 0.975] ------------------------------------------------------------------------------- const -0.0179 0.003 -5.818 0.000 -0.024 -0.012 RiskPremium 0.2294 0.067 3.446 0.001 0.098 0.361 SMB 0.5123 0.162 3.161 0.002 0.192 0.833 HML -0.2333 0.180 -1.297 0.197 -0.589 0.122 RMW -0.8605 0.323 -2.663 0.009 -1.499 -0.222 CMA -0.5015 0.214 -2.342 0.021 -0.925 -0.078 ============================================================================== Omnibus: 4.283 Durbin-Watson: 2.104 Prob(Omnibus): 0.118 Jarque-Bera (JB): 3.755 Skew: 0.361 Prob(JB): 0.153 Kurtosis: 3.331 Cond. No. 86.0 ============================================================================== Notes: [1] Standard Errors are heteroscedasticity and autocorrelation robust (HAC) using 5 lags and without small sample correction
定价模型选择:FF-3模型
fa_turn_std_1m.factor_fm_regr_cmpt()
FamaMacBeth Estimation Summary ===================================================================================== Dep. Variable: returns R-squared: 0.0031 Estimator: FamaMacBeth R-squared (Between): -0.0558 No. Observations: 215554 R-squared (Within): 0.0057 Date: Fri, Jan 14 2022 R-squared (Overall): 0.0031 Time: 04:00:13 Log-likelihood 1.29e+05 Cov. Estimator: Fama-MacBeth Kernel Cov F-statistic: 166.72 Entities: 4200 P-value 0.0000 Avg Obs: 51.322 Distribution: F(4,215549) Min Obs: 1.0000 Max Obs: 143.00 F-statistic (robust): 23.893 P-value 0.0000 Time periods: 143 Distribution: F(4,215549) Avg Obs: 1507.4 Min Obs: 426.00 Max Obs: 2394.0 Parameter Estimates =============================================================================== Parameter Std. Err. T-stat P-value Lower CI Upper CI ------------------------------------------------------------------------------- const 0.0820 0.0270 3.0345 0.0024 0.0290 0.1350 factor -0.0081 0.0009 -9.0512 0.0000 -0.0098 -0.0063 beta 0.0009 0.0032 0.2681 0.7886 -0.0055 0.0072 circ_mc_log -0.0056 0.0018 -3.0357 0.0024 -0.0092 -0.0020 ep_ttm 0.0304 0.0330 0.9226 0.3562 -0.0342 0.0950 ===============================================================================
fa_turn_std_1m.factor_ic_summ()
Rank Information Correlation Summary ====================================================== Start Date: 2010-01-01 Mean IC: -0.0959 End Date: 2021-11-01 Std IC: 0.0814 Frequency: Monthly Prob. Significant IC: 0.9161 No. Turnover: 143 Prob. IC > 0: 0.1189 Information Ratio: -1.1782 ------------------------------------------------------
size_factor = gf.get_size_factor(from_date='2009-12-31',to_date='2021-10-31',pool='liquid_perc70')
size_factor.set_index(['trade_date','stock_code'],inplace=True)
size_factor
mc | mc_log | mc_nonlinear | circ_mc | circ_mc_log | circ_to_total_mc_ratio | ||
---|---|---|---|---|---|---|---|
trade_date | stock_code | ||||||
2009-12-31 | 000001 | 7.567942e+07 | 18.142017 | -0.884212 | 7.126066e+07 | 18.081855 | 0.941612 |
000002 | 1.046436e+08 | 18.466070 | -1.312490 | 1.043824e+08 | 18.463572 | 0.997504 | |
000005 | 5.504288e+06 | 15.521038 | 0.159761 | 5.500733e+06 | 15.520392 | 0.999354 | |
000006 | 5.746386e+06 | 15.564082 | 0.156153 | 5.589346e+06 | 15.536373 | 0.972671 | |
000009 | 1.197644e+07 | 16.298452 | 0.063289 | 1.084956e+07 | 16.199635 | 0.905908 | |
... | ... | ... | ... | ... | ... | ... | ... |
2021-10-29 | 688779 | 4.516272e+07 | 17.625782 | -0.241597 | 8.136354e+06 | 15.911853 | 0.180156 |
688798 | 3.552566e+07 | 17.385766 | -0.133597 | 6.843523e+06 | 15.738813 | 0.192636 | |
688819 | 3.961308e+07 | 17.494670 | -0.179419 | 4.328712e+06 | 15.280781 | 0.109275 | |
688981 | 1.066930e+08 | 18.485466 | -0.926438 | 1.029819e+08 | 18.450064 | 0.965217 | |
689009 | 4.510006e+06 | 15.321809 | 0.214607 | 2.835167e+06 | 14.857611 | 0.628639 |
250696 rows × 6 columns
mc_log_factor = size_factor[['mc_log']].rename(columns={'mc_log':'factor'})
fa_mc_log = fa.factor_analysis(factors=mc_log_factor,returns=returns)
fa_mc_log.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.398638 | 13.615467 | 150.821639 | 31.237827 | 0.435865 | 38.167054 |
group 2 | 0.953467 | 8.861710 | 100.145220 | 30.426154 | 0.291253 | 45.417476 |
group 3 | 0.917918 | 8.030758 | 91.079090 | 28.743353 | 0.279395 | 47.597890 |
group 4 | 0.949985 | 7.671627 | 87.140957 | 26.572253 | 0.288708 | 52.290340 |
group 5 | 1.023024 | 6.474340 | 73.924161 | 20.932607 | 0.309295 | 39.182590 |
group longshort | 0.885551 | 6.742618 | 76.897478 | 25.154809 | 0.268045 | 41.691550 |
fa_mc_log.quantile_returns_plot()
circ_mc_log_factor = size_factor[['circ_mc_log']].rename(columns={'circ_mc_log':'factor'})
fa_circ_mc_log = fa.factor_analysis(factors=circ_mc_log_factor,returns=returns)
fa_circ_mc_log.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.240611 | 12.122511 | 135.119336 | 31.550363 | 0.384227 | 42.820363 |
group 2 | 0.977465 | 9.172312 | 103.517761 | 30.678651 | 0.298980 | 46.438127 |
group 3 | 0.976543 | 8.604304 | 97.343589 | 28.876112 | 0.297973 | 46.135788 |
group 4 | 0.969733 | 7.972364 | 90.439575 | 27.016503 | 0.295092 | 48.785738 |
group 5 | 1.018341 | 6.438625 | 73.527807 | 20.916119 | 0.307831 | 39.523562 |
group longshort | 0.689302 | 5.368181 | 61.591529 | 25.884174 | 0.207392 | 47.112967 |
fa_circ_mc_log.quantile_returns_plot()
mc_nonlinear_factor = size_factor[['mc_nonlinear']].rename(columns={'mc_nonlinear':'factor'})
fa_mc_nonlinear = fa.factor_analysis(factors=mc_nonlinear_factor,returns=returns)
fa_mc_nonlinear.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.029060 | 6.800928 | 77.542825 | 21.828479 | 0.311562 | 39.980278 |
group 2 | 0.949380 | 7.678012 | 87.211072 | 26.610582 | 0.288532 | 52.576964 |
group 3 | 0.897505 | 7.840426 | 88.993461 | 28.723912 | 0.272958 | 47.403166 |
group 4 | 0.960404 | 8.940916 | 101.006082 | 30.466053 | 0.293471 | 45.816190 |
group 5 | 1.437242 | 8.321783 | 94.261593 | 18.998852 | 0.438015 | 25.421333 |
group longshort | 0.395620 | 1.431782 | 16.718768 | 12.241886 | 0.116958 | 27.106548 |
fa_mc_nonlinear.quantile_returns_plot()
circ_to_total_mc_ratio_factor = size_factor[['circ_to_total_mc_ratio']].rename(columns={'circ_to_total_mc_ratio':'factor'})
fa_circ_to_total_mc_ratio = fa.factor_analysis(factors=circ_to_total_mc_ratio_factor,returns=returns,industry_neutral=True)
fa_circ_to_total_mc_ratio.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 0.985737 | 7.157147 | 81.478238 | 23.944366 | 0.298907 | 45.607187 |
group 2 | 1.003905 | 7.480553 | 85.040765 | 24.539014 | 0.304843 | 50.677281 |
group 3 | 0.761171 | 4.672898 | 53.778815 | 20.466886 | 0.228315 | 45.296074 |
group 4 | 1.526094 | 10.140229 | 113.971262 | 21.633986 | 0.468718 | 25.716442 |
group 5 | 0.997483 | 7.750176 | 88.003327 | 25.557382 | 0.303246 | 58.776632 |
group longshort | -0.241870 | -0.553753 | -6.525089 | 7.814972 | -0.070858 | 40.363451 |
fa_circ_to_total_mc_ratio.quantile_returns_plot()
_ido_vol1y: 特质波动率2(twelve-month idiosyncratic volatility),过去252个交易日个股超额收益率关于市场超额收益率正交化处理得到的残差标准差,其中剔除不满120个交易日的股票;
skew: 总偏度(total skewness),过去252个交易日的日度收益率偏度,其中剔除不满120个交易日的股票;
volatility_factor = gf.get_volatility_factor(from_date='2009-12-31',to_date='2021-10-31',pool='liquid_perc70')
volatility_factor.set_index(['trade_date','stock_code'],inplace=True)
volatility_factor
vol_1m | vol_1y | ido_vol_1m | ido_vol_1y | skew | ido_skew | con_skew | ||
---|---|---|---|---|---|---|---|---|
trade_date | stock_code | |||||||
2009-12-31 | 000001 | 0.023381 | 0.030132 | 0.016328 | 0.021933 | 0.607817 | 1.075634 | -7.152257 |
000002 | 0.022913 | 0.028345 | 0.015872 | 0.018598 | 0.130302 | 0.962938 | -11.913605 | |
000005 | 0.032650 | 0.033516 | 0.026909 | 0.025574 | 0.273483 | 1.661326 | -14.046154 | |
000006 | 0.028317 | 0.035414 | 0.022996 | 0.023873 | -0.033927 | 0.391688 | -12.340182 | |
000009 | 0.024583 | 0.036850 | 0.021914 | 0.026666 | 0.006678 | 0.863694 | -15.874289 | |
... | ... | ... | ... | ... | ... | ... | ... | ... |
2021-10-29 | 688779 | 0.030279 | NaN | NaN | NaN | NaN | NaN | NaN |
688798 | 0.027689 | NaN | NaN | NaN | NaN | NaN | NaN | |
688819 | 0.023869 | 0.033233 | 0.020941 | 0.031123 | 0.917616 | 1.209385 | -26.581029 | |
688981 | 0.014825 | 0.025255 | 0.015726 | 0.024773 | 0.761047 | 1.092708 | 22.366436 | |
689009 | 0.034241 | 0.043204 | 0.039255 | 0.040675 | 0.486986 | 0.560439 | -40.570108 |
250696 rows × 7 columns
vol_1m_factor = volatility_factor[['vol_1m']].rename(columns={'vol_1m':'factor'})
fa_vol_1m = fa.factor_analysis(factors=vol_1m_factor,returns=returns)
fa_vol_1m.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.390388 | 7.793571 | 88.479505 | 18.434412 | 0.422773 | 29.990699 |
group 2 | 0.992024 | 7.302258 | 83.077951 | 24.259749 | 0.301003 | 37.717572 |
group 3 | 1.188357 | 9.480826 | 106.858916 | 26.048731 | 0.363965 | 46.253986 |
group 4 | 1.363331 | 11.628683 | 129.883192 | 27.597782 | 0.421363 | 36.578074 |
group 5 | 0.227050 | 2.138550 | 24.891937 | 31.758479 | 0.067338 | 72.907047 |
group longshort | 0.820765 | 5.546495 | 63.587568 | 22.442749 | 0.247140 | 28.975416 |
fa_vol_1m.quantile_returns_plot()
vol_1y_factor = volatility_factor[['vol_1y']].rename(columns={'vol_1y':'factor'})
fa_vol_1y = fa.factor_analysis(factors=vol_1y_factor,returns=returns)
fa_vol_1y.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.295340 | 7.590868 | 86.253710 | 19.289313 | 0.393527 | 34.712859 |
group 2 | 1.151649 | 8.854485 | 100.066673 | 25.170516 | 0.351780 | 44.070652 |
group 3 | 0.980004 | 8.068595 | 91.493299 | 27.044828 | 0.298342 | 45.573449 |
group 4 | 0.295080 | 2.481838 | 28.843053 | 28.315469 | 0.087650 | 68.416735 |
group 5 | -0.136588 | -1.243591 | -14.700536 | 31.177677 | -0.039887 | 96.448599 |
group longshort | 1.138422 | 8.936145 | 100.954246 | 25.688815 | 0.347861 | 24.994772 |
fa_vol_1y.quantile_returns_plot()
ido_vol_1m_factor = volatility_factor[['ido_vol_1m']].rename(columns={'ido_vol_1m':'factor'})
fa_ido_vol_1m = fa.factor_analysis(factors=ido_vol_1m_factor,returns=returns)
fa_ido_vol_1m.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.082863 | 6.119681 | 69.982896 | 18.721520 | 0.326879 | 36.902883 |
group 2 | 1.222293 | 8.663638 | 97.989928 | 23.223565 | 0.373054 | 37.278878 |
group 3 | 1.528605 | 11.432177 | 127.793694 | 24.217914 | 0.472055 | 39.691252 |
group 4 | 0.992191 | 7.755407 | 88.060742 | 25.710458 | 0.301644 | 44.015804 |
group 5 | 0.063682 | 0.577869 | 6.773997 | 30.814125 | 0.018753 | 74.064608 |
group longshort | 0.861525 | 5.512646 | 63.208899 | 21.253626 | 0.259374 | 30.370142 |
fa_ido_vol_1m.quantile_returns_plot()
ido_vol_1y_factor = volatility_factor[['ido_vol_1y']].rename(columns={'ido_vol_1y':'factor'})
fa_ido_vol_1y = fa.factor_analysis(factors=ido_vol_1y_factor,returns=returns)
fa_ido_vol_1y.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.219591 | 7.484544 | 85.084677 | 20.209698 | 0.370344 | 37.352787 |
group 2 | 1.065323 | 7.801887 | 88.570744 | 24.084176 | 0.323942 | 39.662112 |
group 3 | 1.049672 | 8.109558 | 91.941576 | 25.373525 | 0.319607 | 50.519825 |
group 4 | 0.717770 | 6.153059 | 70.354342 | 28.394123 | 0.216702 | 51.998683 |
group 5 | -0.084818 | -0.764821 | -9.020966 | 30.809738 | -0.024824 | 87.534588 |
group longshort | 1.026657 | 8.307506 | 94.105642 | 26.552953 | 0.312866 | 33.988191 |
fa_ido_vol_1y.quantile_returns_plot()
skew_factor = volatility_factor[['skew']].rename(columns={'skew':'factor'})
fa_skew = fa.factor_analysis(factors=skew_factor,returns=returns)
fa_skew.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.349245 | 8.535281 | 96.591304 | 20.738142 | 0.411574 | 28.037534 |
group 2 | 1.072011 | 7.092757 | 80.767771 | 21.825366 | 0.324978 | 40.793522 |
group 3 | 1.011000 | 7.070847 | 80.525920 | 23.073165 | 0.306453 | 52.749602 |
group 4 | 0.947262 | 6.696871 | 76.390950 | 23.361169 | 0.286667 | 49.722503 |
group 5 | 0.872323 | 5.930377 | 67.874250 | 22.539826 | 0.263107 | 39.067870 |
group longshort | 0.557971 | 2.470875 | 28.717054 | 14.909086 | 0.165729 | 29.771409 |
fa_skew.quantile_returns_plot()
ido_skew_factor = volatility_factor[['ido_skew']].rename(columns={'ido_skew':'factor'})
fa_ido_skew = fa.factor_analysis(factors=ido_skew_factor,returns=returns)
fa_ido_skew.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.214858 | 9.086639 | 102.588391 | 24.462189 | 0.371456 | 29.565051 |
group 2 | 0.965377 | 6.987492 | 79.605432 | 23.887377 | 0.292518 | 47.767965 |
group 3 | 1.000714 | 6.787771 | 77.397239 | 22.404638 | 0.302963 | 37.996396 |
group 4 | 0.934279 | 6.197495 | 70.848667 | 21.967361 | 0.282123 | 43.460190 |
group 5 | 0.790031 | 5.559328 | 63.731103 | 23.368439 | 0.237899 | 50.283250 |
group longshort | 0.616952 | 3.356662 | 38.857288 | 18.245002 | 0.183977 | 33.894420 |
fa_ido_skew.quantile_returns_plot()
con_skew_factor = volatility_factor[['con_skew']].rename(columns={'con_skew':'factor'})
fa_con_skew = fa.factor_analysis(factors=con_skew_factor,returns=returns)
fa_con_skew.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 0.066441 | 0.584152 | 6.847449 | 29.854974 | 0.019566 | 66.851833 |
group 2 | 0.036664 | 0.290433 | 3.409045 | 26.935096 | 0.010783 | 62.227852 |
group 3 | 0.443266 | 3.531340 | 40.847534 | 26.694617 | 0.132287 | 54.504311 |
group 4 | 1.183831 | 8.720840 | 98.612732 | 24.130468 | 0.361404 | 39.243979 |
group 5 | 1.586474 | 9.686321 | 109.079600 | 19.917419 | 0.486324 | 33.379730 |
group longshort | 1.318597 | 9.053815 | 102.232151 | 22.459396 | 0.403119 | 22.119254 |
fa_con_skew.quantile_returns_plot()
liquidity_factor = gf.get_liquidity_factor(from_date='2009-12-31',to_date='2021-10-31',pool='liquid_perc70')
liquidity_factor.set_index(['trade_date','stock_code'],inplace=True)
liquidity_factor
turn_1m | turn_std_1m | turn_1y | turn_std_1y | turn_abn | illiq_1m | illiq_1y | ||
---|---|---|---|---|---|---|---|---|
trade_date | stock_code | |||||||
2009-12-31 | 000001 | 9.368108 | 5.240067 | 15.291751 | 9.395660 | 0.612625 | 2.887955e-11 | 3.037886e-11 |
000002 | 16.892911 | 6.620091 | 19.389752 | 7.685814 | 0.871229 | 8.874766e-12 | 1.248956e-11 | |
000005 | 41.317234 | 17.894416 | 42.864445 | 34.987194 | 0.963905 | 1.161325e-10 | 2.746797e-10 | |
000006 | 24.276556 | 11.302615 | 29.452611 | 16.273596 | 0.824258 | 1.434729e-10 | 2.312247e-10 | |
000009 | 21.685049 | 6.760159 | 36.525848 | 21.814985 | 0.593690 | 8.117826e-11 | 1.081805e-10 | |
... | ... | ... | ... | ... | ... | ... | ... | ... |
2021-10-29 | 688779 | 61.461173 | 15.164703 | NaN | NaN | NaN | 4.199975e-11 | NaN |
688798 | 14.120455 | 12.443404 | NaN | NaN | NaN | 2.192218e-10 | NaN | |
688819 | 25.927215 | 7.641897 | 54.252315 | 36.194348 | 0.477901 | 1.389233e-10 | 9.114412e-11 | |
688981 | 11.679183 | 5.572642 | 28.600970 | 18.708997 | 0.408349 | 9.217625e-12 | 8.793054e-12 | |
689009 | 240.100675 | 111.827613 | 487.062947 | 370.057493 | 0.492956 | 2.093390e-10 | 1.842303e-10 |
250696 rows × 7 columns
turn_1m_factor = liquidity_factor[['turn_1m']].rename(columns={'turn_1m':'factor'})
fa_turn_1m = fa.factor_analysis(factors=turn_1m_factor,returns=returns)
fa_turn_1m.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.275586 | 7.419600 | 84.370089 | 19.160261 | 0.387239 | 33.248388 |
group 2 | 1.413675 | 11.226323 | 125.601165 | 25.737528 | 0.436185 | 44.226201 |
group 3 | 0.915188 | 7.763205 | 88.146320 | 27.900797 | 0.278243 | 46.709958 |
group 4 | 0.272076 | 2.447075 | 28.443492 | 30.284109 | 0.080804 | 69.510821 |
group 5 | -0.429093 | -4.092508 | -49.028723 | 33.099497 | -0.123643 | 101.688764 |
group longshort | 1.596955 | 11.960025 | 133.398811 | 24.198138 | 0.494254 | 29.917020 |
fa_turn_1m.quantile_returns_plot()
turn_std_1m_factor = liquidity_factor[['turn_std_1m']].rename(columns={'turn_std_1m':'factor'})
fa_turn_std_1m = fa.factor_analysis(factors=turn_std_1m_factor,returns=returns)
fa_turn_std_1m.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.277648 | 7.374851 | 83.877475 | 19.017644 | 0.387790 | 32.581290 |
group 2 | 1.376906 | 10.775582 | 120.787332 | 25.412054 | 0.424034 | 42.028981 |
group 3 | 0.904695 | 7.546067 | 85.761254 | 27.460682 | 0.274795 | 52.976309 |
group 4 | 0.488848 | 4.355943 | 50.201458 | 29.748527 | 0.146426 | 66.640158 |
group 5 | -0.903347 | -8.021232 | -97.936325 | 31.405951 | -0.255405 | 120.961724 |
group longshort | 2.310941 | 16.615841 | 181.813800 | 22.790853 | 0.729057 | 26.770884 |
fa_turn_std_1m.quantile_returns_plot()
turn_1y_factor = liquidity_factor[['turn_1y']].rename(columns={'turn_1y':'factor'})
fa_turn_1y = fa.factor_analysis(factors=turn_1y_factor,returns=returns)
fa_turn_1y.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.218890 | 7.371642 | 83.842143 | 19.926011 | 0.369951 | 34.776106 |
group 2 | 1.141102 | 8.899263 | 100.553448 | 25.526718 | 0.348625 | 47.152602 |
group 3 | 0.545053 | 4.497377 | 51.799004 | 27.529959 | 0.163363 | 53.016015 |
group 4 | 0.549154 | 4.970753 | 57.131543 | 30.137324 | 0.164937 | 62.422538 |
group 5 | 0.004671 | 0.042529 | 0.499769 | 30.995586 | 0.001372 | 78.752224 |
group longshort | 0.943649 | 7.326261 | 83.342374 | 25.584575 | 0.286355 | 38.560136 |
fa_turn_1y.quantile_returns_plot()
turn_std_1y_factor = liquidity_factor[['turn_std_1y']].rename(columns={'turn_std_1y':'factor'})
fa_turn_std_1y = fa.factor_analysis(factors=turn_std_1y_factor,returns=returns)
fa_turn_std_1y.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.355645 | 8.120766 | 92.064215 | 19.672857 | 0.412790 | 34.547792 |
group 2 | 1.153713 | 8.837373 | 99.880593 | 25.078753 | 0.352385 | 46.747214 |
group 3 | 0.505281 | 4.176001 | 48.166081 | 27.614086 | 0.151227 | 58.273022 |
group 4 | 0.383518 | 3.333855 | 38.597204 | 29.153648 | 0.114355 | 59.535594 |
group 5 | -0.352888 | -3.065206 | -36.543593 | 29.998326 | -0.102179 | 87.322344 |
group longshort | 1.568547 | 11.508702 | 128.607808 | 23.751577 | 0.484545 | 38.485839 |
fa_turn_std_1y.quantile_returns_plot()
turn_abn_factor = liquidity_factor[['turn_abn']].rename(columns={'turn_abn':'factor'})
fa_turn_abn = fa.factor_analysis(factors=turn_abn_factor,returns=returns)
fa_turn_abn.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 0.938714 | 6.353590 | 72.583645 | 22.398981 | 0.283655 | 44.834954 |
group 2 | 1.318741 | 8.827170 | 99.769635 | 21.916015 | 0.402773 | 39.213640 |
group 3 | 1.585334 | 10.623101 | 119.154792 | 21.772752 | 0.487908 | 30.109041 |
group 4 | 1.324481 | 9.478252 | 106.831075 | 23.365466 | 0.405652 | 31.873137 |
group 5 | 0.318777 | 2.665651 | 30.953673 | 28.128562 | 0.094767 | 58.617399 |
group longshort | 0.620338 | 3.600087 | 41.629972 | 19.440172 | 0.185188 | 37.526980 |
fa_turn_abn.quantile_returns_plot()
illiq_1m_factor = liquidity_factor[['illiq_1m']].rename(columns={'illiq_1m':'factor'})
fa_illiq_1m = fa.factor_analysis(factors=illiq_1m_factor,returns=returns)
fa_illiq_1m.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 0.907570 | 5.795132 | 66.365647 | 21.182915 | 0.273576 | 41.513299 |
group 2 | 0.936817 | 7.132500 | 81.206337 | 25.110644 | 0.284043 | 51.758109 |
group 3 | 1.285905 | 10.231997 | 114.957981 | 25.897202 | 0.395100 | 38.796505 |
group 4 | 1.330629 | 11.171584 | 125.017518 | 27.216772 | 0.410467 | 39.383060 |
group 5 | 1.730542 | 15.648732 | 171.904854 | 28.775884 | 0.543814 | 29.657192 |
group longshort | 1.367809 | 9.358872 | 105.539207 | 22.351728 | 0.418709 | 31.780758 |
fa_illiq_1m.quantile_returns_plot()
illiq_1y_factor = liquidity_factor[['illiq_1y']].rename(columns={'illiq_1y':'factor'})
fa_illiq_1y = fa.factor_analysis(factors=illiq_1y_factor,returns=returns)
fa_illiq_1y.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 0.987424 | 6.205410 | 70.936696 | 20.810859 | 0.298181 | 39.593304 |
group 2 | 0.891465 | 6.708638 | 76.521263 | 24.865694 | 0.269795 | 52.033292 |
group 3 | 1.126850 | 9.039417 | 102.075857 | 26.240950 | 0.344478 | 44.497033 |
group 4 | 1.258755 | 10.719337 | 120.185390 | 27.658776 | 0.387556 | 40.552622 |
group 5 | 1.310146 | 12.003218 | 133.856390 | 29.596616 | 0.405560 | 44.389677 |
group longshort | 0.783385 | 5.486801 | 62.919695 | 23.266667 | 0.235822 | 38.745707 |
fa_illiq_1y.quantile_returns_plot()
beta_factor = gf.get_beta_factor(from_date='2009-12-31',to_date='2021-10-31',pool='liquid_perc70')
beta_factor.set_index(['trade_date','stock_code'],inplace=True)
beta_factor
beta | beta_up | beta_down | beta_relative | ||
---|---|---|---|---|---|
trade_date | stock_code | ||||
2009-12-31 | 000001 | 1.009846 | 0.643266 | 0.571294 | 0.071972 |
000002 | 1.044442 | 0.706817 | 0.681236 | 0.025581 | |
000005 | 1.054034 | 0.258128 | 0.812633 | -0.554506 | |
000006 | 1.268346 | 0.825271 | 0.768436 | 0.056834 | |
000009 | 1.254508 | 0.499687 | 0.928245 | -0.428558 | |
... | ... | ... | ... | ... | ... |
2021-10-29 | 688779 | NaN | NaN | NaN | NaN |
688798 | NaN | NaN | NaN | NaN | |
688819 | 1.188440 | 0.303153 | 0.367037 | -0.063884 | |
688981 | 0.498994 | -0.155896 | 0.370523 | -0.526419 | |
689009 | 1.453634 | 0.327101 | 0.562933 | -0.235832 |
250696 rows × 4 columns
beta_mkt_factor = beta_factor[['beta']].rename(columns={'beta':'factor'})
fa_beta_mkt = fa.factor_analysis(factors=beta_mkt_factor,returns=returns)
fa_beta_mkt.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.481018 | 8.592212 | 97.211836 | 19.014343 | 0.451881 | 33.440280 |
group 2 | 1.176691 | 9.064165 | 102.344488 | 25.195596 | 0.359752 | 48.948522 |
group 3 | 1.123959 | 8.991619 | 101.556851 | 26.174686 | 0.343523 | 38.154744 |
group 4 | 0.533483 | 4.380718 | 50.481447 | 27.411570 | 0.159813 | 52.490334 |
group 5 | -0.175998 | -1.557648 | -18.439881 | 30.350962 | -0.051321 | 90.704322 |
group longshort | 1.515955 | 10.296559 | 115.651717 | 22.099795 | 0.465912 | 30.293591 |
fa_beta_mkt.quantile_returns_plot()
beta_down_factor = beta_factor[['beta_down']].rename(columns={'beta_down':'factor'})
fa_beta_down = fa.factor_analysis(factors=beta_down_factor,returns=returns)
fa_beta_down.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.591906 | 9.599000 | 108.136426 | 19.677832 | 0.487808 | 33.028398 |
group 2 | 1.212834 | 9.141151 | 103.179808 | 24.644266 | 0.370924 | 37.703301 |
group 3 | 0.501367 | 3.883322 | 44.848592 | 25.912875 | 0.149861 | 55.781697 |
group 4 | 0.314966 | 2.518423 | 29.263411 | 26.914379 | 0.093572 | 52.849272 |
group 5 | -0.062756 | -0.515100 | -6.068542 | 28.012381 | -0.018388 | 78.300124 |
group longshort | 1.540967 | 10.161958 | 114.204968 | 21.469125 | 0.473329 | 25.452989 |
fa_beta_down.quantile_returns_plot()
beta_up_factor = beta_factor[['beta_up']].rename(columns={'beta_up':'factor'})
fa_beta_up = fa.factor_analysis(factors=beta_up_factor,returns=returns)
fa_beta_up.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.064173 | 7.005094 | 79.799872 | 21.722639 | 0.322479 | 35.220896 |
group 2 | 1.081545 | 6.801604 | 77.550305 | 20.771188 | 0.327454 | 39.877319 |
group 3 | 1.375199 | 9.404094 | 106.028728 | 22.334717 | 0.421053 | 40.998535 |
group 4 | 1.420294 | 10.315676 | 115.857062 | 23.630170 | 0.436547 | 38.295749 |
group 5 | 0.663889 | 5.590558 | 64.080327 | 27.960938 | 0.199942 | 45.346436 |
group longshort | 0.247077 | 1.345683 | 15.719545 | 18.430242 | 0.073015 | 32.639894 |
fa_beta_up.quantile_returns_plot()
beta_relative_factor = beta_factor[['beta_relative']].rename(columns={'beta_relative':'factor'})
fa_beta_relative = fa.factor_analysis(factors=beta_relative_factor,returns=returns)
fa_beta_relative.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 0.063877 | 0.518362 | 6.078085 | 27.564171 | 0.018806 | 64.900845 |
group 2 | 0.752882 | 5.578993 | 63.951014 | 24.606107 | 0.226732 | 49.590335 |
group 3 | 0.694776 | 4.678542 | 53.842426 | 22.449275 | 0.208405 | 56.404044 |
group 4 | 1.481175 | 9.669041 | 108.893006 | 21.296895 | 0.454012 | 37.982690 |
group 5 | 1.056885 | 7.463636 | 84.854660 | 23.257913 | 0.320907 | 34.523922 |
group longshort | 1.102729 | 6.912485 | 78.776576 | 20.694306 | 0.334028 | 40.689706 |
fa_beta_relative.quantile_returns_plot()
mom_factor = gf.get_momentum_factor(from_date='2009-12-31',to_date='2021-10-31',pool='liquid_perc70')
mom_factor.set_index(['trade_date','stock_code'],inplace=True)
mom_factor
mom_1m | mom_6m | mom_12m | imom | mom_chg | ||
---|---|---|---|---|---|---|
trade_date | stock_code | |||||
2009-12-31 | 000001 | 0.017536 | 0.060668 | 1.259420 | -0.017959 | -0.689300 |
000002 | -0.066493 | -0.196948 | 0.489375 | 0.045655 | -0.410984 | |
000005 | -0.101491 | 0.313726 | 1.233333 | 0.116102 | 0.083371 | |
000006 | -0.131135 | -0.088112 | 1.063435 | 0.106806 | -0.886501 | |
000009 | -0.140845 | -0.060812 | 1.761628 | 0.161363 | -1.148737 | |
... | ... | ... | ... | ... | ... | ... |
2021-10-29 | 688779 | -0.071032 | NaN | NaN | NaN | NaN |
688798 | -0.094711 | NaN | NaN | NaN | NaN | |
688819 | -0.089182 | 0.017123 | 0.042573 | 0.066399 | NaN | |
688981 | 0.018505 | -0.026127 | -0.056897 | -0.028073 | 0.046861 | |
689009 | -0.195981 | 0.205324 | 0.115623 | 0.181284 | 0.263038 |
250696 rows × 5 columns
mom_12m_factor = mom_factor[['mom_12m']].rename(columns={'mom_12m':'factor'})
fa_mom_12m = fa.factor_analysis(factors=mom_12m_factor,returns=returns)
fa_mom_12m.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 0.106664 | 0.837978 | 9.811436 | 26.646253 | 0.031448 | 62.462070 |
group 2 | 0.418732 | 2.926489 | 33.942796 | 23.481945 | 0.124627 | 61.877714 |
group 3 | 0.502383 | 3.274838 | 37.923935 | 21.867602 | 0.149758 | 38.265861 |
group 4 | 1.455907 | 9.666119 | 108.861450 | 21.660236 | 0.446261 | 28.972413 |
group 5 | 1.025411 | 7.593134 | 86.278617 | 24.374059 | 0.311525 | 46.811255 |
group longshort | 1.102512 | 6.703755 | 76.467181 | 20.091596 | 0.333660 | 64.222693 |
fa_mom_12m.quantile_returns_plot()
mom_6m_factor = mom_factor[['mom_6m']].rename(columns={'mom_6m':'factor'})
fa_mom_6m = fa.factor_analysis(factors=mom_6m_factor,returns=returns)
fa_mom_6m.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 0.647082 | 5.188345 | 59.575301 | 26.670389 | 0.194536 | 47.283391 |
group 2 | 0.800377 | 5.716759 | 65.490616 | 23.703191 | 0.241181 | 42.958161 |
group 3 | 1.038901 | 6.778038 | 77.289531 | 21.551079 | 0.314510 | 36.275891 |
group 4 | 0.812778 | 5.453893 | 62.551366 | 22.293981 | 0.244635 | 38.077517 |
group 5 | 1.122732 | 8.577287 | 97.049185 | 25.040238 | 0.342540 | 44.785387 |
group longshort | 0.561019 | 3.235404 | 37.473884 | 19.349693 | 0.167207 | 91.670806 |
fa_mom_6m.quantile_returns_plot()
mom_1m_factor = mom_factor[['mom_1m']].rename(columns={'mom_1m':'factor'})
fa_mom_1m = fa.factor_analysis(factors=mom_1m_factor,returns=returns)
fa_mom_1m.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.460095 | 12.141562 | 135.320908 | 26.847654 | 0.452239 | 29.674777 |
group 2 | 1.100619 | 7.955305 | 90.252690 | 23.754483 | 0.334897 | 36.170803 |
group 3 | 1.539560 | 11.079304 | 124.032995 | 23.337980 | 0.474733 | 27.945473 |
group 4 | 1.483165 | 10.281388 | 115.488727 | 22.556556 | 0.455805 | 37.621066 |
group 5 | 0.451821 | 3.556602 | 41.135100 | 26.373547 | 0.134855 | 65.094671 |
group longshort | 1.195095 | 8.314845 | 94.185807 | 22.829977 | 0.364207 | 26.061225 |
fa_mom_1m.quantile_returns_plot()
imom_factor = mom_factor[['imom']].rename(columns={'imom':'factor'})
fa_imom = fa.factor_analysis(factors=imom_factor,returns=returns)
fa_imom.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 0.490319 | 3.847615 | 44.443263 | 26.257312 | 0.146535 | 66.976273 |
group 2 | 1.078078 | 6.894398 | 78.576620 | 21.113767 | 0.326536 | 40.551519 |
group 3 | 1.166800 | 7.937065 | 90.052831 | 22.357512 | 0.355007 | 44.094379 |
group 4 | 1.486700 | 10.276821 | 115.439658 | 22.493360 | 0.456882 | 25.921273 |
group 5 | 1.409480 | 11.139178 | 124.671873 | 25.623129 | 0.434731 | 28.916217 |
group longshort | 1.100871 | 7.043917 | 80.228610 | 21.111327 | 0.333656 | 35.749658 |
fa_imom.quantile_returns_plot()
mom_chg_factor = mom_factor[['mom_chg']].rename(columns={'mom_chg':'factor'})
fa_mom_chg = fa.factor_analysis(factors=mom_chg_factor,returns=returns)
fa_mom_chg.quantile_returns_summ()
t-stats | ann. return rate (%) | acc. return rate (%) | ann. volatility (%) | sharpe ratio | max drawdown (%) | |
---|---|---|---|---|---|---|
quantiles | ||||||
group 1 | 1.024597 | 7.978973 | 90.511973 | 25.590301 | 0.311797 | 33.755689 |
group 2 | 1.224430 | 8.601506 | 97.313105 | 23.022901 | 0.373607 | 30.532712 |
group 3 | 1.346123 | 9.026727 | 101.938088 | 21.936850 | 0.411487 | 37.979675 |
group 4 | 0.675931 | 4.510601 | 51.948265 | 22.263384 | 0.202602 | 53.614477 |
group 5 | 0.780584 | 5.624236 | 64.456833 | 23.920582 | 0.235121 | 51.755750 |
group longshort | 0.462799 | 2.239504 | 26.055140 | 16.308854 | 0.137318 | 26.783360 |
fa_mom_chg.quantile_returns_plot()
summ_dict = {'总市值对数':[0.885551,6.742618,76.897478,25.154809,0.268045,41.691550],
'流通市值对数':[0.689302,5.368181,61.591529,25.884174,0.207392,47.112967],
'非线性市值':[0.395620,1.431782,16.718768,12.241886,0.116958,27.106548],
'流通市值占比':[-0.241870,-0.553753,-6.525089,7.814972,-0.070858,40.363451],
'总波动率(最近一月)':[0.820765,5.546495,63.587568,22.442749,0.247140,28.975416],
'总波动率(最近一年)':[1.138422,8.936145,100.954246,25.688815,0.347861,24.994772],
'特定波动率(最近一月)':[0.861525,5.512646,63.208899,21.253626,0.259374,30.370142],
'特定波动率(最近一年)':[1.026657,8.307506,94.105642,26.552953,0.312866,33.988191],
'偏度':[0.557971,2.470875,28.717054,14.909086,0.165729,29.771409],
'特定偏度':[0.616952,3.356662,38.857288,18.245002,0.183977,33.894420],
'条件偏度':[1.318597,9.053815,102.232151,22.459396,0.403119,22.119254],
'换手率(最近一月)':[1.596955,11.960025,133.398811,24.198138,0.494254,29.917020],
'换手率波动率(最近一月)':[2.310941,16.615841,181.813800,22.790853,0.729057,26.770884],
'换手率(最近一年)':[0.943649,7.326261,83.342374,25.584575,0.286355,38.560136],
'换手率波动率(最近一年)':[1.568547,11.508702,128.607808,23.751577,0.484545,38.485839],
'异常换手率':[0.620338,3.600087,41.629972,19.440172,0.185188,37.526980],
'非流动性(最近一月)':[1.367809,9.358872,105.539207,22.351728,0.418709,31.780758],
'非流动性(最近一年)':[0.783385,5.486801,62.919695,23.266667,0.235822,38.745707],
'市场Beta':[1.515955,10.296559,115.651717,22.099795,0.465912,30.293591],
'下行Beta':[1.540967,10.161958,114.204968,21.469125,0.473329,25.452989],
'上行Beta':[0.247077,1.345683,15.719545,18.430242,0.073015,32.639894],
'相对Beta':[1.102729,6.912485,78.776576,20.694306,0.334028,40.689706],
'动量(最近一年)':[1.102512,6.703755,76.467181,20.091596,0.333660,64.222693],
'动量(最近六月)':[0.561019,3.235404,37.473884,19.349693,0.167207,91.670806],
'短期反转':[1.195095,8.314845,94.185807,22.829977,0.364207,26.061225],
'特定动量':[1.100871,7.043917,80.228610,21.111327,0.333656,35.749658],
'动量变化':[0.462799,2.239504,26.055140,16.308854,0.137318,26.783360]}
summ_df = pd.DataFrame.from_dict(summ_dict, orient='index',columns=['t值','年化收益率(%)','累计收益率(%)','年化波动率(%)','夏普比率','最大回测(%)'])
指标计算:\ 夏普比率(年化):$R_{mean}$为区间内平均收益率,$R_f$为无风险收益率,$\sigma_{R}$为区间内收益波动率,$N$为$\sqrt{250}$或$\sqrt{52}$或$\sqrt{12}$。 $$Sharpe_{annual} = (\frac{R_{mean}-R_f}{\sigma_{R}})\times N$$ 年化收益率:$R_{mean}$为区间内平均收益率,$N$为计算周期天数。 $$R_{annual} = [(1+R_{mean})^{\frac{365}{N}}-1]\times 100\%$$ 年化波动率:$r_{i}$为收益率,$R_{mean}$为区间内平均收益率,$n$为$250$或$52$或$12$。 $$V_{annual} = \sqrt{\frac{\sum_i^N(r_i-R_{mean})^2}{N}}\times \sqrt{n}$$