December 2018
Beginner to intermediate
684 pages
21h 9m
English
To use lagged values as input variables or features associated with the current observations, we use the .shift() method to move historical returns up to the current period:
for t in range(1, 7): data[f'return_1m_t-{t}'] = data.groupby(level='ticker').return_1m.shift(t)
Similarly, to compute returns for various holding periods, we use the normalized period returns computed previously and shift them back to align them with the current financial features:
for t in [1,2,3,6,12]: data[f'target_{t}m'] = data.groupby(level='ticker')[f'return_{t}m'].shift(-t)