Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Filter price before getting fundamentals

If I want to filter out stocks whose prices are less than $2 and then get fundamentals from the filtered stocks, how can I do it in before_trading_start? If it's not feasible, would handle_data() be a good place to do the filter?

2 responses

Hello Ubi,

It should be easy, but I don't think it is. Only 200 securities can be exposed at a time, so if you are wanting to screen the entire Quantopian universe of bar data, even once per day in before_trading_start, you can't. It might be feasible with fetcher, if you have prepared a list of stocks "whose prices are less than $2." One would wonder if you could generate such a list with the Quantopian research environment and then load it into the backtester via fetcher?

Another option would be to use the set_universe API (https://www.quantopian.com/help#ide-universe), and look at the bottom percentiles. Maybe you would be able to generate a comprehensive list of < $2 stocks in this fashion (or at least < $N, with N < 2). I'll attempt some example code at some point, if it'd be of interest, since this is probably your best option.

Grant

I took a try at identifying stocks that trade in a particular range in Using #Fundamentals to identify uptrending volatile small caps by getting Market Cap and Shares Outstanding, then dividing them to get a rough idea of share price before adding them to my universe. I did the actual range check in handle_data. As Grant notes, the limit of 200 securities becomes a factor.