Back to Community
How to filter exchange_id in Pipeline


I would like to get stocks from Nasdaq only using Pipeline?
When using get_fundamentals, I would use a filter command:
.filter(fundamentals.company_reference.primary_exchange_id == 'NASDAQ') when using the fundamentals

How can I reproduce this filter with pipeline?
I found morningstar.company_reference.primary_exchange_id but when I add that to my inputs, I get the following error message:
TypeError: Don't know how to construct AdjustedArray on data of type .

Any help would be much appreciated

4 responses

Hi Ali, it's not currently possible to pass in strings (exchange_ids) to pipeline filters. At the moment only integers and booleans are supported and we're working on adding this functionality. We'll share with the community once this has been shipped.


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.

EDIT: I made a mistake in my comment above. Only floats are supported in pipeline filters. We are working on fixing integer and boolean filters - when this is done we'll let you know. String filters are not yet supported.


I am having so so much trouble getting a list of stocks from the NASDAQ only to be generated with fundamentals_df. Can you please help me?


at the moment it' possible to use this trick (see the section below def accept_exchange):

class UniverseMask(CustomFactor):  
    Return 1.0 for the following class of assets, otherwise 0.0:  
      * No Financials (103), Real Estate (104), Basic Materials (101) and ADR  
        (Basic Materials are too much sensitive to exogenous macroeconomical shocks.)  
      * Only primary common stocks  
      * Exclude When Distributed(WD), When Issued(WI) and VJ - usuallly companies in bankruptcy  
      * Exclude Halted stocks (_V, _H)  
      * Only NYSE, AMEX and Nasdaq  
      * mkt cap > 5,000,000  
      * invested_capital > 0 (sanity check)  
      * total_assets > 0 (sanity check)  
      * Avoid illiquid stock (dollar trading volume average in the last 10 days less than 100,000)  
    window_length = 10  
    inputs = [USEquityPricing.close, USEquityPricing.volume,  

    def compute(self, today, assets, out, close_price, volume, mkt_cap, is_primary_share, \  
                is_depositary_receipt, sector_code, invested_capital, total_assets):  
        dollar_volume_10d_avg = np.mean(close_price * volume, axis=0)  
        criteria = dollar_volume_10d_avg > 1e5 # Avoid illiquid stock (dollar trading volume average in the last 10 days less than 100,000)  
        price_10d_avg = np.mean(close_price, axis=0)  
        criteria = criteria & (price_10d_avg > 3) # Avoid penny stocks (less tahn $3)  
        criteria = criteria & (mkt_cap[-1] > 5e6) # Mkt cap > 5,000,000  
        criteria = criteria & (is_primary_share[-1]) # Only primary Common Stock  
        criteria = criteria & (~is_depositary_receipt[-1]) # No ADR  
        criteria = criteria & (sector_code[-1] != 101) # No Basic Materials  
        criteria = criteria & (sector_code[-1] != 103) # No Financials  
        criteria = criteria & (sector_code[-1] != 104) # No Real Estate  
        criteria = criteria & (invested_capital[-1] > 0) # Sanity check  
        criteria = criteria & (total_assets[-1] > 0) # Sanity check  

        def accept_symbol(equity):  
            symbol = equity.symbol  
            if symbol.endswith("_PR") or symbol.endswith("_WI") or symbol.endswith("_WD") or \  
               symbol.endswith("_VJ") or symbol.endswith("_V") or symbol.endswith("_H"):  
                return False  
                return True  

        def accept_exchange(equity):  
            exchange =  
            if exchange == "NEW YORK STOCK EXCHANGE":  
                return True  
            elif exchange == "AMERICAN STOCK EXCHANGE":  
                return True  
            elif exchange.startswith("NASDAQ"):  
                return True  
                return False  
        vsid = np.vectorize(sid)  
        equities = vsid(assets)  
        # Exclude When Distributed(WD), When Issued(WI) and VJ (usuallly companies in bankruptcy) and Halted stocks (V, H)  
        vaccept_symbol = np.vectorize(accept_symbol)  
        accept_symbol = vaccept_symbol(equities)  
        criteria = criteria & (accept_symbol)  
        # Only NYSE, AMEX and Nasdaq  
        vaccept_exchange = np.vectorize(accept_exchange)  
        accept_exchange = vaccept_exchange(equities)  
        criteria = criteria & (accept_exchange)  
        out[:] = criteria.astype(float)