同花顺Supermind量化交易 多因子专题(一)--时序回归 附源代码

355 阅读1分钟

通常在Barra 模型中,因子暴露直接来自基本面或者技术面数据本身,而在学术界通常使用时序回归得到因子暴露。

时序回归得到每支股票的因子暴露

截面回归不同于Barra模型,其第一步是时序回归,用来确定因子暴露值,而不是直接拿因子值作为因子暴露值。

In [11]:

from sklearn.linear_model import LinearRegression

stock_params = pd.DataFrame(columns = ["intercept", "coef"],index=stock_list)

i=0

for stock in price.columns:  
    
    x=return_date_total_factor_array.reshape(-1,1)
    y=price[stock].reshape(-1,1)
    
    model = LinearRegression()
    
    try:
        model.fit(x,y)
    
        stock_params.ix[i,'intercept']  = model.intercept_[0]
        stock_params.ix[i,'coef'] = model.coef_[0][0]
    
    
    except:
        stock_params.ix[i,'intercept'] =np.nan
        stock_params.ix[i,'coef'] =np.nan
    
    
    i=i+1
    
stock_params.dropna(inplace=True)    
stock_params.head()
    

Out[11]:

interceptcoef
601088.SH-0.134711-0.545668
002624.SZ-0.149889-0.504071
600583.SH-0.1220590.0627217
600383.SH-0.04485870.698046
601633.SH-0.01796910.459616

因子暴露的概率密度分布

In [12]:

fig = plt.figure(figsize = (20, 8))
ax = stock_params['coef'].plot.kde(label = 'Beta')
ax.set_title('Beta',size=25)
ax.legend()    

Out[12]:

<matplotlib.legend.Legend at 0x7fa715c4cb38>

查看以上策略详情请到supermind量化交易官网查看:同花顺Supermind量化交易 多因子专题(一)--时序回归 附源代码