Zipline CustomFilter
Posted on Aug. 11, 2017, 3:45 p.m.
In this post I present a simple CustomFilter I made to check if an asset is in a given list on a given day. Why would someone want such a filter? Zipline comes with the StaticAssets filter, but this only checks if an asset is in a given list. I want to change that list by day. Why would I want to do this? Well I moved my code off of Quantopian and into Zipline for performance and flexibility reasons. However one of the things that Quantopian offers is free data, and some code. "With freedom comes responsibility." So I wanted to evaluate the performance of the Quantopian data against other data sets. This may be straight forward with a single ticker but a pipeline algo changes tickers with each update. Here is the code for the CustomFilter:
class StaticAssetsByDate(CustomFilter):
"""This is mostly for debug, it simply checks if an asset is in a dict for a given day."""
window_length = 1
inputs = []
def add_dict(self, asset_d):
self.asset_d = asset_d
def compute(self, today, assets, out):
if today not in self.asset_d:
raise Exception("holy shit, date not found in asset_d")
out[:] = assets.isin(self.asset_d[today])