Is there a way to incorporate intraday data into pipeline calculations? For example, consider the following hypothetical custom factor:
class ComputeWMA10(CustomFactor):
inputs = [USEquityPricing.close, data.current]
window_length = 9
def compute(self, today, assets, out, close, current):
intraday_hist = np.append(close[0:], current) # Append last 9 days of history with current price to get len(10) array
weights = np.arange(1,11) # Get weights 1-10
wma10 = pd.Series(intraday_hist).rolling(10).apply(lambda prices: np.dot(prices, weights)/weights.sum(), raw=True).iloc[-1]
out[:] = wma10
This takes data.current() and appends it to a window of last prices, with the idea being it could be run just prior to market close to get as close as possible to close-to-close performance. The first challenge here is that neither context nor data are passed to custom factors within the traditional zipline algorithm structure. The second is that there are other arguments passed to data.current() - e.g. "price".
For simple factors, the pipeline output can be appended with a new column - for example:
assets = pipe_results.index
pipe_results['current'] = data.current(assets, 'price')
The factor could then be backed into to include the current price. For a 20 Day SMA factor you would take the ((SMA20 * 19) + Current)/20. However, for more complex factors like the WMA factor above, this cannot be done.
Has anybody come up with a solution to incorporate pipeline results intraday?