Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Alphalens - Using current returns to predict current returns

As a test, I wanted to see how the rank of returns could be used as a factor in alphalens. I shifted the 'get_pricing' dataframe so that I could compare the current returns with current returns i.e. I used returns to predict itself (using close prices). The fact that I used ranks means that good performance is never guaranteed - it all depends on how the market did on any given day. However, when comparing mean returns by quantile, one should expect them to be increasing from left to right but this not the case. After all, we are perfectly predicting the ranks. Please if someone could assist in helping me understand this? Please refer to the notebook attached.

6 responses

Your code is correct, except that you need to shift the price by 2 days. This seems surprising but keep in mind the following: pipeline Returns calculation is done every day with yesterday close price and 2 days before close price. So "today" you can get "yesterday" returns and you need to shift the prices by 2 days to introduce the bias you need to make the factor predict the future.

Thanks Luca. So then am I correct in saying that USEquityPricing.close refers to yesterday's close price while the result from "get_pricing" given parameter "close_price" yields todays most recent price?

Yes, that's correct. Pipeline output might seem surprising but it makes sense. When Pipeline is used in an algorithm, the pipeline output is fetched in 'before_trading_start', that means before the today price information is available . So "today" most recent open/low/high/close prices refer to yesterday. I guess Q wanted to keep the same reasoning in Research.

Great! One more question. I've attached a notebook where window_length=3. From my understanding this is 2-day returns and should correspond to the parameter period=2 in 'get_pricing'. But when I run alphalens, the IC is higher in period 1 not 2. Any ideas why this is the case?

In your first NB, with 1 day returns (window_length=2) you have to shift with period=2. Now, with 2 days returns (window_length=3) you have to shift with period=3.

Try with 4 day returns (window_length=5) and shift with period=5. You can clearly see the IC is higher in period 4, where it should be.

Yeah, its working! Thank you Luca