So I'm brand new to Quantopian and so far all the algorithms I have seen have defined the stock to be traded in the initialize functions. This seemed really odd to me, because wouldn't you want to identify macro trends, find out what stocks are exemplifying those trends and then trade those stocks instead of just picking a stock to begin with and running your algorithm on just the one stock?
Is there a way to loop through and compare all available stocks, find stocks that meet certain criteria, then initialize those stocks, then run your algorithm?
For example is it possible to write an algorithm that
- compares all stocks after 5 minutes of market open
- singles out the top gaining stock for those first 5 minutes
- initializes that stock
- buys x dollars of that stock at market price
- sets a 0.25% trailing stop loss
- sells stock at 4:15 if stop loss isn't met
Under this model, your algorithm would be trading a different stock each day.
Maybe it's because I just started exploring Quantopian, but I haven't seen this methodology so far. Why is that? If I'm wrong, could you point me to a sample algorithm that uses this logic of comparing all stocks at market open or close to determine which stock should initialize?