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)
```

In [347]:

```
alphalens.tears.create_full_tear_sheet(factor_data, long_short=True)
```