Some advertising.
What you want is also a kind of convolution filter. There's a PR [1]
in statsmodels to add these along with a recursive filter and some
seasonal decomposition stuff. It's mostly done. It just needs a once
over. It wraps pandas code correctly, though you'd have to shift the
index back, because it's assumed the filter is centered around t.
There's an option for a one-sided, backwards looking filter, but I
suppose we could add a forwards-looking one as well to make the shift
unnecessary. I never knew a use case for it. There are many ways to do
this using convolution, fft convolution, or scipy.signal.lfilter, FYI.
FFT might be tough to beat for long series.
[1]
https://github.com/statsmodels/statsmodels/pull/1484
[~/statsmodels/statsmodels-cython/statsmodels/tsa/filters/]
[8]: drange = pd.date_range('1/1/2013', '3/1/2013', freq='1H')
[~/statsmodels/statsmodels-cython/statsmodels/tsa/filters/]
[9]: x = pd.Series(np.random.random(size=len(drange)), index=drange)
[~/statsmodels/statsmodels-cython/statsmodels/tsa/filters/]
[10]: pd.rolling_sum(x[::-1], 24)[::-1].head(5)
[10]:
2013-01-01 00:00:00 10.912721
2013-01-01 01:00:00 11.697446
2013-01-01 02:00:00 12.077230
2013-01-01 03:00:00 11.589507
2013-01-01 04:00:00 12.504221
Freq: H, dtype: float64
[~/statsmodels/statsmodels-cython/statsmodels/tsa/filters/]
[11]: filt = [0] * 23 + [1] * 24 # only care about upcoming 24
[~/statsmodels/statsmodels-cython/statsmodels/tsa/filters/]
[12]: sm.tsa.filters.convolution_filter(x, filt).shift(-23,
freq='H').dropna().head(5)
[12]:
2013-01-01 00:00:00 10.912721
2013-01-01 01:00:00 11.697446
2013-01-01 02:00:00 12.077230
2013-01-01 03:00:00 11.589507
2013-01-01 04:00:00 12.504221
Freq: H, dtype: float64
> For more options, visit
https://groups.google.com/d/optout.