Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Filter by Morningstar Sector Codes

Hello. I am pretty new to Python and Quantopian. I am trying to implement a stock filter based off of Morningstar sector codes. I have followed some of the posted 'help' notebooks on this topic but I keep getting a 'element_of() missing 1 required positional argument: 'choices' error message with my code. I am not really sure how to proceed from here.

Ideally, I'd like to only filter by one sector (309 = energy) but I included two sectors in my code to help with the 'choices' error. Still nothing.

Any help would be appreciated!

-Chris

3 responses

here you go:

sector = Sector()

my_sectors = sector.element_of([

        #101,#XLB MATERIALS  
        #102,#XLY CONS.DISC  
        #103,#XLF FINANCIAL  
        #104,#IYR REAL ESTATE  
        #205,#XLP CONS.STAP  
        #206,#XLV HEALTH CARE  
        #207,#XLU UTILITIES  
        #308,#IYZ TELECOM  
        309,#XLE ENERGY  
        #310,#XLI INDUSTRIAL  
        #311#XLK TECHNOLOGY  

])

qtu = QTradableStocksUS()

universe = qtu & my_sectors

If you want to filter for more sectors, just remove the # infront of the sector code :)

Then you could use "universe" in "screen = universe" in the pipleline or "mask=universe" and so forth. :)

notebook

Thank you, Niclas! This works perfectly.