Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to manually generate a Dataframe for analysis in Alphalens?

Hey guys,

i am still quite new to Quantopian. I have been playing around with some technical indicators to get used to the API.
Now in my recent notebook i was trying to analyse a crossover indicator. One can chose the weightfunction for the two moving averages and optionally one can also weight the moving averages with the volume of the stock. Thats pretty much all about the indicator.

So far so good. Since the moving averages arent windows safe i checked for the crossovers outside the pipeline and generate signals for upcrosses and downcrosses, where an upcross = 1 and a downcross =-1.

Now to learn something i also implemented more or less the code from Global Equity Pricing and Fundamental Data to be able to chose any domain for research.

I merged everything togehter and made the quantiles to be simply a shift by 1 of my indicator, so that every -1 falls in the zeroth, every 0 in the first and every 1 in the second quantil. Of course one will have very unequaly sized bins where the middle quantile has 99.3% of all data corresponding to no crossover happened.

I ran alphalens on that merged Dataframe and i got NaNs for the alpha and beta score. So i wondered weither this is due to the great difference in quantilesize.

To test that idea, i went and just dropped the middle quantile all together. Strangely this alters "Mean Period Wise Return Top Quantile" and "Mean Period Wise Return Bottom Quantile" when i put the resulting Dataframe into alphalens. But since the top and bottom quantile stayed the top and bottom quantil this confuses me.
It seems like i am getting something fundamentaly wrong about alphalens here since i can neither explain why i get NaNs nor can i explain why dropping the middle quantil changes the returns of the remaining quantiles. Can anyone explain that behavior?

Thanks for your help! :)