Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Quantiles doesn't have eq method

https://www.quantopian.com/docs/api-reference/pipeline-api-reference#zipline.pipeline.Factor.quantiles
zipline.pipeline.classifiers.classifier.Quantiles does not have eq (==) method, but it has other comp methods (<=, >, etc). Just wondering why?
Also, method '!=' doesn't count '-1'. For example, q = quantiles(2); q != 0 -> it would take only q==1 but not include q == -1.

2 responses

Factors implement the following comparison operators: <, <=, !=, >=, >. For internal technical reasons, factors do not override the equal operator ==. To perform an equal comparison use the .eq method. In both cases the result is a filter. Something like this would create two filters. One with assets where the factor value is 0 and another where the value is greater than 0.

 factor_eq_zero = my_factor.eq(0)  
 factor_gt_zero = my_factor > 0

However, in the original post the example used quantiles. The quantiles method returns a classifier and NOT a factor. The comparison operators are not defined for classifiers. A comparison like this my_classifier > 0 doesn't work. One must use the .eq or .element_of methods for comparison. The inverse operator ~ is also helpful. Something like this

 classifier_eq_0 = my_factor.quantiles(2).eq(0)  
 classifier_eq_0_or_1 = my_factor.quantiles(2).element_of([0, 1])  
 classifier_not_eq_0 = ~my_factor.quantiles(2).eq(0)  

There is more info in the documentation (https://www.quantopian.com/docs/api-reference/pipeline-api-reference#zipline.pipeline.Classifier.element_of).

Hope that helps explain things.

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.

Thanks, for quick respond. It really helps.