Back to Community
Having Trouble with Filters specifically NumExprFilter

In my make_pipeline() func, I have

HIGH_ROA = (roa > 0) if HIGH_ROA == 'True': SCORE +=1
where SCORE is the variable I want to screen for. I want stocks below 3 on the Score and above 8. However, my screen which looks like this:
SHORT = False if SCORE <= 2: SHORT = True LONG = False if SCORE >= 9: LONG = True # Our screen to remove certain stocks is_tradeable = ( close_price_below_SMA & high_dollar_volume & (SHORT | LONG) ) does not filter out any stocks because of SHORT or LONG. When I try to add SCORE to my Filter, I get a Value Error; int detected error. The docs imply it has something to do with filters.

4 responses

How is SCORE defined? Since Pipelines are cross-sectional, the return from the if statements should be an array of numbers - not just a single integer.

I define it in the pipeline as SCORE = 0. I see what you are saying. Can you explain how to do that on this platform? I have worked with pandas, not this abstract pipeline so I am a little unsure how to.

In your other post, you had this:

def make_pipeline():  
    # Return on Asset rules  
    roa = morningstar.operation_ratios.roa.latest  
    ROA = (roa > 0)                         # BOOL  
    CONDITION_TWO = .....         # BOOL  
    CONDITION_THREE = ....      # BOOL  
    SCORE = 0  

Pipeline computations (before you run them) are defined as a set of expressions which are performed on references to BoundColumn data. It may be better to define a CustomFactor like this:

from quantopian.factors import CustomFactor 

class Screen(CustomFactor):  
    inputs = [morningstar.operation_ratios.roa.latest , *args]  
    def compute(self, today, assets, out, roa, *args):  
        score = 0

        # Conditions  
        if (roa >0):  
            score += 1

        out[:] = score

def make_pipeline():  
    score_screen = Screen()  
    return Pipeline( columns = {'Screen':score_screen}  

This will return a Pandas DataFrame of SCORE for each asset for each date. You can then use that to define your trading logic, for example if Screen > 4 you can call order() with longs and Screen == 0 you can short.

You are a hero. Next question.
I have a class:

class Previous(CustomFactor):  
    # Returns value of input x trading days ago where x is the window_length  
    # Both the inputs and window_length must be specified as there are no defaults

    def compute(self, today, assets, out, inputs):  
        out[:] = inputs[0]  

that I use within that new Custom Factor class.

class SCORE(CustomFactor):  
    inputs = [morningstar.operation_ratios.roa.latest,  
    # how is roa defined  
    def compute(self, today, assets, roa, roa_1_year_ago, out, inputs):  
        score = 0  
        # Return on Asset rules  
        roa = morningstar.operation_ratios.roa.latest  
        if (roa > 0): score += 1  
        roa_1_year_ago = Previous(inputs = [morningstar.operation_ratios.roa], window_length = 252)  
        if (roa > roa_1_year_ago): score +=1  

My question is two-fold, how would i list the roa_1_year_ago in the inputs to the function? Also, how does the inputs variable map to the compute parameters. In your answer I did not see roa being defined at all. Was I correct in defining roa in the compute method?