Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Can I use all NYSE and NASDAQ stocks in my algo and use a screening function once per month / two weeks ?

Can I use about 6000 stocks from NYSE and NASDAQ stocks in my algo and use a screening function once per month or once per two weeks ?

The algo will reset/erase the list and then append a maximum of 200 stocks with the desired criteria to context.stocks = [] list.

The thing is that I can't use my function within before_trading_start(context) because I need to use the stock price data to sort the stocks:

def before_trading_start(context):  
    sort_stocks(context,data)  

Runtime exception: NameError: global name 'data' is not defined

or

InvalidBeforeTradingStartMethod: 0070 before_trading_start(context, data) accepts too many arguments

So, I will use:

3 responses

Got my answer: InvalidSidCount: 0019 Algorithm must reference 1-200 SIDs. Found 291

Adrian,
Right -- the limit on 200 sids is for accessing pricing data either in handle_data or a scheduled function (via schedule_function())

You can, however, use before_trading_start() to access securities through fundamentals and screen using the data returned by get_fundamentals(). You'll need to keep your universe below 200 once you're done with your screening logic.

Hope this helps,
Josh

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

There are some nuances I have not taken the time to fully understand yet.
Clone this algo and mess around with it: https://www.quantopian.com/posts/how-to-create-a-symbol-from-string#54f5f2248be13134f2000027
There's a point where it processes 306 securities in handle_data during one bar/frame.
Increase the time period beyond one year to watch numbers go up.