Back to Community
Custom Factors and out variable - Local variable 'out' is assigned to but never used

I have created a custom factor but when I run algorithm the IDE complains that out variable is never used although I am returning correct data type and dimension.

class EfficiencyRatio(CustomFactor):  
    inputs = [USEquityPricing.close]  
    window_length = 10  
    def compute(self, today, assets, out, close):  
           er = efficiencyRatio(close)  
           print("ER type and dim: ", type(er), er.ndim)  
           out = er

2011-01-04PRINT('er type and dim: type numpy.ndarray, 1)

Can anyone see what is wrong?

5 responses

Hi Can,

All you need to to is change out --> out[:], that should do it!


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.


Is this Kaufman' ER? If so you are presamably using True Range not close? Are you having to use loops or have you found a way to vectorize? I have just make a custom factor for a 252 Efficiency Ratio but am going to have to re- think it. It works as it should but the looping is incredibly computationally expensive.

Blast.... Can't edit a post for typos on an android.

Hi Anthony,
Yes, I am using the Kaufman ER. Right now I have not done any optimizations. I am learning the Quantopian framework and have a couple of ideas I want to test with ER. I am looping through the np.array for now but I don't think it's that hard to vectorize if needed, also using close not true range. I read somewhere that the before_trading method has about 30 mins to execute code so for now I don't see any problems but that may change.