Asher11 - 9 months ago 202

Python Question

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: http://statsmodels.sourceforge.net/stable/regression.html`

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()

print(model.summary())

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.

`x.rolling(window=60).apply(my_ols)`

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 http://statsmodels.sourceforge.net/0.6.0/generated/statsmodels.tsa.vector_ar.dynamic.DynamicVAR.html