When I'm defining these periods (i.e. say 1, 3, and 5) in alphalens,
am I asking alphalens to calculate what the period return would be for
the securities in the pipeline for each day? For example, for securities
in day 1, it calculates a 1, 3 and 5 period return and then for securities
in day 2 in calculates 1, 3, and 5 day returns
(based on factor weights if I'm not mistaken).
'Factor Weighted Long/Short Portfolio Cumulative Return' is the only plot that uses security weighted by factor value, all the other plots use security equal weighting, i.e. if a quantile contains 100 securities then each security has 1/100 weight
What if securities are in day 1 and day 2 and the factors change from
day 2 to day 1? Isn't there overlap? Is the periods parameter to help
us identify holding periods? For example, 5 day period looks better
than 1 period so go with a strategy using 5 days (but then again
pipeline runs everyday before trading start so I am confused as to how
this can work out efficiently). Am I looking at this all wrong? Or Is
this just the return of the portfolio based on different periods (i.e.
p1/p0, p3/p0 , p5/p0) and not the returns of the portfolio if you held
the securities for 1, 3, or 5 days?
You are understanding it right and I'll explain how Alphalens handles the overlapping. I'll be a little verbose to summarize how Alphalens works, this might help other people.
Alphalens expects to receive in input a factor that ranks the stocks in a certain way. Alphalens helps you verify that top and bottom ranked stocks perform the opposite (positive vs negative returns) in the days (periods) after the ranking is computed. To verify the ranking scheme, Alphalens groups the stocks in quantiles (or bins) and computes the average of the forward returns (returns in the days following the ranking) of the stocks in the same quantile.
Those quantile mean forward returns are calculated by Alphalens every single date the input factor DataFrame has values for (every date is considered a new starting point for forward returns calculation). This makes sense because we want to test the factor quality every time the factor is computed. All in all, what we are looking for is to answer the question: After the stocks are ranked by our factor, what happens on average to the quantile returns?
Ideally a factor applies is ranking scheme every trading day , but this is not compulsory, e.g. a factor might generate values only on Mondays and in this case the factor we would give to Alphalens would contain values only for those dates corresponding to Mondays while the other days would be nan or not present at all.
Now let's imagine we want to analyze a factor that ranks the stocks every day and we like to analyze the performance after 22 days/periods (this correspond to an algorithm that rebalances its portfolio monthly as there are 22 trading days per month on average). Alphalens would calculate the quantile 22 days forward returns for every single date (because the factor DataFrame has values every day) and average them. In this way you get the mean returns by factor quantile, but how does Alphalens calculate the cumulative return plots?
Alphalens builds the cumulative returns plots starting from the 22 days forward returns calculated every day. It seems there is a problem of overlapping though. If we want to hold securities for 22 days, it means we cannot trade the factor every day, but every 22 days instead. If this is the case then the cumulative returns are very dependent on the particular trading day we start the computation. E.g. In a year, a hypothetical algorithm that uses that factor would only trades 12 times, one trade every 22 days. This doesn't give us meaningful statistical results. Alphalens is able to calculate the factor forward returns every single day and we make use of only 1/22th of those information?
To overcome the issue and give a more meaningful result, Alphalens builds 22 cumulative returns time series, where each cumulative return time series starts on a subsequent day from the previous one. This way all the possible outcomes for a rebalancing period of 22 days are covered and Alphalens returns an average of those results. In this way all the information coming from the daily 22 day forward returns is used and the results can be much more trusted.