I'm trying to aggregate some data across periods using resampling and so far have something like this:
Data:
val1 val2 val3 ...
date
2022-01-29 0.01 0.08 0.03
2022-01-30 0.04 -0.07 0.02
2022-01-31 0.09 -0.01 0.01
2022-02-01 -0.02 0.01 0.06
...
Code:
((df + 1).resample(frequency).transform(lambda x: x.cumprod()) - 1).resample(frequency).last()
This works exactly how I'd like for monthly or quarterly time series and the like but I'm trying to also get a rolling window from the start of the data set for example, 4 month periods from 2022/01/13: 2022/01/13-2022/05/12, 2022/05/13-2022/09/12, 2022/09/13-2023/01/12 etc I've tried using offsets or creating a custom DatetimeIndex but I either still just get period ends or an invalid frequency error. Is there any way to perform this type of aggregation from the data starting date?