Notebook
In [345]:
import alphalens
Z = W[:-1].copy() # W are the factors
Z /= np.tile(np.sum(np.abs(Z), axis=1), (Z.shape[1], 1)).T #normalize factors
PnL = Z * ret[K+1, :] # multiply by next day returns
PnL = np.sum(PnL, axis=1) # sum P/L across stocks each day
plt.plot(PnL.cumsum()) # cumsum P/L
factors = pd.DataFrame(Z, columns=prices.columns, index=prices.index[K+2:]).stack()
In [346]:
factor_data = alphalens.utils.get_clean_factor_and_forward_returns(
    factors,
    prices,
    quantiles=2,
    periods=(1,2,5), 
    filter_zscore=None)
Dropped 0.4% entries from factor data: 0.4% in forward returns computation and 0.0% in binning phase (set max_loss=0 to see potentially suppressed Exceptions).
max_loss is 35.0%, not exceeded: OK!
In [347]:
alphalens.tears.create_full_tear_sheet(factor_data, long_short=True)
Quantiles Statistics
min max mean std count count %
factor_quantile
1 -0.140107 0.018651 -0.021577 0.015081 32799 50.0
2 -0.030220 0.064397 0.000956 0.014170 32799 50.0
Returns Analysis
1D 2D 5D
Ann. alpha 0.518 0.426 0.250
beta 0.113 0.103 0.070
Mean Period Wise Return Top Quantile (bps) 8.112 6.205 3.233
Mean Period Wise Return Bottom Quantile (bps) -8.112 -6.209 -3.237
Mean Period Wise Spread (bps) 16.225 12.415 6.470
<matplotlib.figure.Figure at 0x7ff45f5d9590>