quantopian / alphalens

Performance analysis of predictive (alpha) stock factors
http://quantopian.github.io/alphalens
Apache License 2.0
3.33k stars 1.14k forks source link

Changed pd.rolling_mean() to use the new *.rolling().mean() API #214

Closed mmargenot closed 6 years ago

mmargenot commented 6 years ago

I changed the instances of rolling_mean to use the new API. The instances of rolling_apply that are used elsewhere should be updated on top of these.

luca-s commented 6 years ago

@mmargenot as it is related to this commit, would you remove the rolling_apply inside utils.py as well?

Current code

    sub_portfolios = pd.rolling_apply(sub_portfolios,
                                      period,
                                      rate_of_returns,
                                      min_periods=1,
                                      args=(period,))   

That should become:

    sub_portfolios = sub_portfolios.rolling(window=period, min_periods=1) \
                                   .apply(rate_of_returns, args=(period,))         
twiecki commented 6 years ago

Thanks @mmargenot, changing the requirement to >= 0.18 is fine.

twiecki commented 6 years ago

CC @richafrank.

richafrank commented 6 years ago

Thanks. The requirement bump to 0.18 sounds good to me, as that matches the lower bound for zipline.

I assume the pandas API change here is in fact supported by 0.18? Confirming only because the travis build is testing with latest pandas (0.20).

twiecki commented 6 years ago

Yeah, I was worried about that too but thought I misremembered. I don't think 0.18 supports .rolling().mean() yet.

Should probably also add a test-matrix for older pandas versions here.

mmargenot commented 6 years ago

The API reference for pandas has New in version 0.18.0. for both pandas.Series.rolling and pandas.DataFrame.rolling, here and here. I can make it 0.18.1 just to be safe?

mmargenot commented 6 years ago

@luca-s I can definitely fix the rolling_apply. I just wanted to get this one first.

twiecki commented 6 years ago

Thanks @mmargenot!