Back to Community
How do I convert a bunch of bools (types as filters) to an int?

I am looking to set a variable, SCORE to the number of conditions met.

I have

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  

Here, ROA, CONDITION_TWO, CONDITION_THREE are conditions. I have tried:
if ROA == 'True': SCORE += 1 which throws this error when it is my screen or Pipeline:
TypeError: zipline.pipeline.pipeline.validate_column() expected a value of type zipline.pipeline.term.Term for argument 'term', but got int instead.

I have also tried solutions from Stackoverflow about using count() on the bools in an array. I am typing to sum the Trues in the conditions into the int variable Score to screen stocks. 0, I short. 4, I go long. The screen does not like the variable SCORE nor does the pipeline.
However, when I just put the conditions in the Pipeline, they do return as True or False. That being said the 'NaNs' are stripped after, but I do not think that is the issue.

My remaining code:
``` is_tradeable = (
close_price_below_SMA
& high_dollar_volume
)
return Pipeline(
columns = {
'Close Price' : latest_close,
'ROA' : ROA,
'CONDITION_TWO' : CONDITION_TWO
},
screen = is_tradeable
)

my_pipe = make_pipeline() result = run_pipeline(my_pipe, '2005-01-01',
'2006-01-01').dropna() ```

5 responses
if ROA*1.0 == 1: SCORE += 1  

Will work.

@Guy Fleury: your code throws an error of TypeError: unsupported operand type(s) for *: 'NumExprFilter' and 'float'

if ROA*1 == 1: SCORE += 1  

Then go for an integer.

TypeError: unsupported operand type(s) for *: 'NumExprFilter' and 'int'

It works if I just make it a basic if then based on == 'True' although I do not know if it works because when I add it to the pipeline, it gives me this error:
TypeError: zipline.pipeline.pipeline.validate_column() expected a value of type zipline.pipeline.term.Term for argument 'term', but got int instead.