quantopian / alphalens

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

tear_sheet_walkthrough pricing is not next day's open #338

Closed grananqvist closed 5 years ago

grananqvist commented 5 years ago

Problem Description

I was looking at alphalens/examples/tear_sheet_walk_through.ipynb and pricing is calculated by pricing = pan.loc[:,:,'Open'].iloc[1:], which is supposed to mean the trade is executed on next day's open. But simply doing iloc doesn't shift the open prices in relation to the timestamps, so what the example is doing is calculating returns from a open price before the signal was generated.

Am I correct? It was very confusing for me because it looked like I had snooping bias in my experiments following this example.

And what you actually want as pricing is the open price the next day, which is

pan['Open'].groupby(level=-1).shift(-1)

Right?

Versions

luca-s commented 5 years ago

There are few consideration here. Generally speaking I would not change the price information, but I would adapt the factor data instead, so that the latter is correctly aligned to the price data (right timestamps to avoid look ahead bias). So the price data should be correct in my opinion.

Then, you can read in the construction of the factor data:

# introduce look-ahead bias and make the factor predictive
predictive_factor = predictive_factor.shift(-lookahead_bias_days)

I would say that the author introduced the look-ahead bias so that the alphalens plots were meaningful.