Creating forward returns

The goal is to predict returns over a given holding period. Hence, we need to align the features with return values with the corresponding return data point 1, 5, 10, or 20 days into the future for each equity. We achieve this by combining the pandas .groupby() method with the .shift() method as follows:

y = data.loc[:, return_cols]
shifted_y = []
for col in y.columns:
t = int(re.search(r'd+', col).group(0))
shifted_y.append(y.groupby(level='asset')['Returns{}D'.format(t)].shift(-t).to_frame(col))
y = pd.concat(shifted_y, axis=1)
y.info()

MultiIndex: 47377 entries, (2014-01-02, Equity(24 [AAPL])) to (2015-12-31, Equity(47208 [GPRO]))
Data columns (total 4 columns):
Returns1D 47242 non-null float64
Returns5D 46706 non-null float64
Returns10D 46036 non-null float64
Returns20D 44696 non-null float64
dtypes: float64(4)

There are now different numbers of observations for each return series as the forward shift has created missing values at the tail end for each equity.

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

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