I have data (dataframe called returns) that looks like this
DATE TICKER RETURN_DATA
2010-01-01 xxx 0.05
2010-01-01 yyy 0.01
2010-01-02 xxx 0.02
2010-01-02 yyy 0.08
.....
2010-01-29 xxx 0.11
2010-01-29 yyy 0.01
what I try to do is to calculate 4(n)-weeks rolling returns.
I implemented this
def rolling_fct(returns, window_len):
return returns.groupby('TICKER')['RETURN_DATA'].rolling(window=window_len).apply(lambda x: np.prod(1+x)-1)
where window_len = 28 days, this works but I just discovered I need to roll this over a time delta rather than having a window_len = integer. The problems is that I am dealing with public holidays etc, so my window length is not fixed.
I am looking for the same rolling logic just on a time delta rather than a length.