Asher11 Asher11 - 1 year ago 631
Python Question

Deprecated rolling window option in OLS from Pandas to Statsmodels

as the title suggests, where has the rolling function option in the ols command in Pandas migrated to in statsmodels? I can't seem to find it.
Pandas tells me doom is in the works:

FutureWarning: The pandas.stats.ols module is deprecated and will be removed in a future version. We refer to external packages like statsmodels, see some examples here:
model = pd.ols(y=series_1, x=mmmm, window=50)

in fact, if you do something like:

import statsmodels.api as sm

model = sm.OLS(series_1, mmmm, window=50).fit()


you get results (window does not impair the running of the code) but you get only the parameters of the regression run on the entire period, not the series of parameters for each of the rolling period it should be supposed to work on.

Answer Source

I thought one way could be either using a combination of pandas rolling window function, apply and statsmodels OLS, e.g.


where my_ols calls sm.ols.

Alternatively, maybe the rolling VAR function in statsmodels can somehow be used for rolling regression by feeding the right inputs - see

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download