My factor takes advantage of mean reversion.
The factor is generated by the interaction of the daily HLC for a stock with two price levels, similar to Bollinger bands (calculation in no way related to BB).
The factor ranges from 0 to 1. Factors between 0 & 0.5 are buy signals, and factors between 0.5 & 1 are sell signals. But what if there are no factors above 0.5 on a day in which the market moves uniformly down? Buy signals closer to 0 are stronger than those closer to 0.5.
On days when market uniformity is not high the factor generates many buy and sell signals and the cumulative portfolio appears as I would expect.
On days when uniformity is high, is the long/short portfolio in Alphalens then constructed by taking the best buy signals (closest to 0) and treating the worst buy signals (those with the highest factors) as sell signals?
In which case, the cumulative portfolio is not reflecting the intention of the factors.
Is there any way I could prevent the use of days in which there are either all buys or all sells? I'm having a go at doing this within the pipeline using
pipeline_output.groupby(level=0).sum()
to count how many buy signals and sell signals each day, and adding some logic to nullify all signals on such days. Is that a sensible approach?