Creating forward returns and factor quantiles

To utilize alphalens, we need to provide signals for a universe of assets like those returned by the ranks of the MeanReversion factor, and the forward returns earned by investing in an asset for a given holding period. See Notebook 03_performance_eval_alphalens.ipynb for details.

We will recover the prices from the single_factor.pickle file as follows (factor_data accordingly):

performance = pd.read_pickle('single_factor.pickle')

prices = pd.concat([df.to_frame(d) for d, df in performance.prices.items()],axis=1).T
prices.columns = [re.findall(r"[(.+)]", str(col))[0] for col in
prices.columns]
prices.index = prices.index.normalize()
prices.info()

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 755 entries, 2015-01-02 to 2017-12-29
Columns: 1661 entries, A to ZTS
dtypes: float64(1661)

The GitHub repository's alpha factor evaluation Notebook has more detail on how to conduct the evaluation in a sector-specific way.

We can create the alphalens input data in the required format using the get_clean_factor_and_forward_returns utility function that also returns the signal quartiles and the forward returns for the given holding periods:

HOLDING_PERIODS = (5, 10, 21, 42)
QUANTILES = 5
alphalens_data = get_clean_factor_and_forward_returns(factor=factor_data,
prices=prices,
periods=HOLDING_PERIODS,
quantiles=QUANTILES)

Dropped 14.5% entries from factor data: 14.5% 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!

 The alphalens_data DataFrame contains the returns on an investment in the given asset on a given date for the indicated holding period, as well as the factor value, that is, the asset's MeanReversion ranking on that date, and the corresponding quantile value:

date

asset

5D

10D

21D

42D

factor

factor_quantile

01/02/15

A

0.07%

-5.70%

-2.32%

4.09%

2618

4

AAL

-3.51%

-7.61%

-11.89%

-10.23%

1088

2

AAP

1.10%

-5.40%

-0.94%

-3.81%

791

1

AAPL

2.45%

-3.05%

8.52%

15.62%

2917

5

ABBV

-0.17%

-2.05%

-6.43%

-13.70%

2952

5

 

The forward returns and the signal quantiles are the basis for evaluating the predictive power of the signal. Typically, a factor should deliver markedly different returns for distinct quantiles, such as negative returns for the bottom quintile of the factor values and positive returns for the top quantile.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.232.185.167