18 Jun 02:28 2014

### Rolling exponentionally weighted functions? Exponentially weighted regression?

It appears to me that the ewm{a,var,std,corr,cov} functions are all expanding-window based. (This isn't 100% obvious from the documentation, as "span" suggests that it may be interpreted as a window length.) Any reason there aren't rolling_ewm{a,var,std,corr,cov} functions that take an additional window parameter?

Is the easiest / most efficient way to accomplish this by using rolling_apply() with the corresponding ewm{a,var,std,corr,cov} function?

Separately, I think it would be useful to have an ewmregression function (and a rolling version thereof), i.e. something like this [I haven't actually tested this code, so caveat emptor]:

Seth

-- Is the easiest / most efficient way to accomplish this by using rolling_apply() with the corresponding ewm{a,var,std,corr,cov} function?

Separately, I think it would be useful to have an ewmregression function (and a rolling version thereof), i.e. something like this [I haven't actually tested this code, so caveat emptor]:

def ewmregression(arg1, arg2,

com=None, span=None, halflife=None,

min_periods=0,

bias=False,

freq=None,

pairwise=None,

how=None):

'''

Regress arg1 on arg2, returning (slope, intercept)

'''

slope = pd.ewmcov(arg1=arg1, arg2=arg2, com=com, span=span, halflife=halflife, min_periods=min_periods, bias=bias, freq=freq, pairwise=pairwise, how=how) / \

pd.ewmvar(arg=arg2, com=com, span=span, halflife=halflife, min_periods=min_periods, bias=bias, freq=freq, how=how)

intercept = pd.ewma(arg=arg1, com=com, span=span, halflife=halflife, min_periods=min_periods, freq=freq, adjust=True, how=how) - \

(slope * pd.ewma(arg=arg2, com=com, span=span, halflife=halflife, min_periods=min_periods, freq=freq, adjust=True, how=how))

return (slope, intercept)

com=None, span=None, halflife=None,

min_periods=0,

bias=False,

freq=None,

pairwise=None,

how=None):

'''

Regress arg1 on arg2, returning (slope, intercept)

'''

slope = pd.ewmcov(arg1=arg1, arg2=arg2, com=com, span=span, halflife=halflife, min_periods=min_periods, bias=bias, freq=freq, pairwise=pairwise, how=how) / \

pd.ewmvar(arg=arg2, com=com, span=span, halflife=halflife, min_periods=min_periods, bias=bias, freq=freq, how=how)

intercept = pd.ewma(arg=arg1, com=com, span=span, halflife=halflife, min_periods=min_periods, freq=freq, adjust=True, how=how) - \

(slope * pd.ewma(arg=arg2, com=com, span=span, halflife=halflife, min_periods=min_periods, freq=freq, adjust=True, how=how))

return (slope, intercept)

Seth

You received this message because you are subscribed to the Google Groups "PyData" group.

To unsubscribe from this group and stop receiving emails from it, send an email to pydata+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.

For more options, visit https://groups.google.com/d/optout.