Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Using history of CustomFactors in pipeline

How can you access the history (e.g. 2 years) of a CustomFactor to train models during backtest? The only examples I've found use 'safe' CustomFactors to get around the window_safe limitation, in order to use CustomFactors as input to other CustomFactors (the Quantopian ML example #3 does this). But I don't want to zscore/rank my factors to make them safe.

Workarounds I thought about:
1. Use a warm-up period and store the custom factor outputs every day into a data frame.
Problems:
1. Stocks move in and out of the universe, meaning some days will have NaN.
2. This breaks when a split/dividend adjustment occurs

2. Calculate the entire history every time the model training CustomFactor runs
Problem: this will waste CPU and probably take forever because each day we calculate n-1 days redundantly (n = history length)

I'm probably overlooking something obvious, since this is probably the most common quantitative trading model implementation in existence (i.e. WF with model retraining every n days). Any examples/pointers in the right direction would be greatly appreciated!

1 response

So nobody is interested in their CustomFactors' raw historical values?

Here's a (radical) idea: would it be possible to let us run the backtester where all data is backadjusted up until the last date of the backtesting period? I can't really see if this would introduce look-ahead bias anywhere (maybe via the other data sets), but it would get rid of the window_safe requirement.