December 2018
Beginner to intermediate
684 pages
21h 9m
English
To capture time series dynamics that capture, for example, momentum patterns, we compute historical returns using the pct_change(n_periods), that is, returns over various monthly periods as identified by lags. We then convert the wide result back to long format using .stack(), use .pipe() to apply the .clip() method to the resulting DataFrame and winsorize returns at the [1%, 99%] levels; that is, we cap outliers at these percentiles.
Finally, we normalize returns using the geometric average. After using .swaplevel() to change the order of the MultiIndex levels, we obtain compounded monthly returns for six periods ranging from 1 to 12 months:
outlier_cutoff = 0.01data = pd.DataFrame()lags = [1, 2, 3, 6, 9, 12]