I have just started to use Quantopian and zipline (awesome work by the way) but haven't been able to work out the "right" way to back-test a dynamically set basket of stocks.
How should I define a selection of stocks at run-time, or more precisely outside of the class deriving TradingAlgorithm? (I am using zipline locally in this case)
It is easy to define within the class, but this requires changing the code every time I want to look at different stocks. I would have thought I could just pass data for stocks of interest, but the obvious code:
data = load_from_yahoo()
class MyAlg(TradingAlgorithm):
def handle_data(context, data):
for stock in data:
# do stuff
Will include the benchmark index (SPX).
It feels messy to just exclude SPX, what if the benchmark changes.
Any suggestions?
Thanks!