quantopian / alphalens

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

The behavior of get_clean_factor_and_forward_returns in regards to periods is strange. #292

Closed mmargenot closed 6 years ago

mmargenot commented 6 years ago

If I say I want (1, 15, 30) as periods, I occasionally get formatted outputs like:

image

There does not seem to be a firm way to predict whether my period value will be augmented by 1, 2, or more. To have a non-deterministic change like this seems undesirable. Is this expected behavior?

luca-s commented 6 years ago

The days we expect to see reported by Alphalens are trading days but it can be tricky to detect the actual number of trading days since there is no trading calendar passed to Alphalens. There is a logic though that tries to infer the trading calendar and so the actual trading days. This logic probably fails with some input. If there is a way I can replicate the bug I will fix that.

luca-s commented 6 years ago

Just an update. I found out that since Alphalens is not aware of the public holidays the computation of the periods goes wrong. For short periods we don't see the problem because Alphalens performs several tests and it is unlikely that in all those tests there is always a public holiday in between the period. The longer the period the more likely Alphalens fails in detecting the right period length. I will find a solution.

mmargenot commented 6 years ago

Nice catch! It definitely seems worse as periods get longer.

luca-s commented 6 years ago

Fixed in #295