Hi,
I am trying to understand the Annual Portfolio Selection.ipynb notebook (see a link).
From the script below you can see that the stocks_prices have 90 days shift and are grouped by year
# Create yearly groups of the dataset on shifted data to avoid forward bias
year_groups = stocks_price.shift(90).groupby([stocks_price.index.year])
Then it is passed to the annual_unverse_selector function, where stocks_prices has the 90 shift, but stocks_volume does not.
def annual_universe_selector(stocks_price, stocks_volume):
# Choosing from the volumes dataframe the index of the group
stocks_volume = stocks_volume.loc[stocks_price.index]
# Filter the top 100 stocks
filtered_stocks = (stocks_price[:90] * stocks_volume[:90]
).mean().sort_values(ascending=False).index[:100]
# Return the filtered stocks for as a Series
return pd.Series(filtered_stocks)
Shouldn't stocks_volume need to be shifted 90 days also?