import statsmodels.api as sm def get_halflife(s): s_lag = s.shift(1) s_lag.iloc[0] = s_lag.iloc[1] s_ret = s - s_lag s_ret.iloc[0] = s_ret.iloc[1] s_lag2 = sm.add_constant(s_lag) model = sm.OLS(s_ret,s_lag2) res = model.fit() # print(res.summary()) halflife = round(-np.log(2) / list(res.params)[1],0) return halflife