Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Is there any way to get run_pipeline in the algorithm environment? and/or a way to grab factor data n days ago?

I have been using alphalens.performance.average_cumulative_return_by_quantile to generate data to plug into an algorithm for it to weight different factors, and it seems to work really well... in sample data. However, it tends to hold on for a couple months into the next year where it is out of sample. So I was wondering if it was possible to set this up to run something like every month in a backtest, to keep the testing close to where it is getting the weights.

Unfortunately, when setting this up, apparently alphalens is not a whitelisted object you can import. Is there a way around this? and/or why is alphalens blocked?

I am considering building my own crude version of what alphalens.performance.average_cumulative_return_by_quantile does to do it myself, however this will probably suck a lot, so any help here is appreciated.

Edit:
After a lot of fiddling I managed to create such code for myself, and I guess due to programming it with the end goal in mind, cutting out some stuff that I did not need it to do, and by various other miracles it runs in about 40 seconds for the same timeframe that with alphalens took over two hours. However, it is only now when I plug this into my algorithm do I find out that run_pipeline is also on such a list that I cannot import it into the algorithm environment.

I would now consider building my own version of this, except that I have no idea how to grab past values of a factor.
Ideally, there would be something that instead of somefactor.latest, I could do somefactor.latest(n) where n is how many days ago that factor goes to, so that I could run through the window I want and build a dataframe similar to that which is outputted by run_pipeline.

So where I stand now is that I need either a way to use run_pipeline in the backtestor, a way to grab factor data n days ago, and/or something that I havn't even thought of yet to get this working.