Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Attribute Error : Need help

Hi Quantopians,

I'm having difficulties executing this part of my algo. I'm getting a 'SIDData' object has no attribute 'RC'. Don't know what to make of it . here's a sample of the algo :

def handle_entry ( context, data):  

    context.leverage = 1.00  

    prices = history(200, '1d','close_price')  
    # Formula for ROC that will be applies to all securities  
    RC = prices.apply(talib.ROC,timeperiod = 20).iloc[-1]  
    #  
    #  
    for stock in data :  
        if data[stock].RC > RC[context.equity] :  
            order_target_percent(stock,context.weights * context.leverage)  

Can someone indicates what I did wrong here ?

Thanks

Lionel

2 responses

Lionel, are you still looking for help on this one?

If so, RC gets calculated for all the stocks in your algo. If you want to access it for a specific stock, you have to index into it:

# RC for all the stocks in the algo  
RC = prices.apply(talib.ROC,timeperiod = 20).iloc[-1]  

# RC for a specific stock  
RC_stock =  RC[stock]

# RC for a different stock  
RC_equity = RC[context.equity]

# ordering logic  
if RC_stock > RC_equity :  
            order_target_percent(stock,context.weights * context.leverage)  

From the code snippet I'm not sure what "stock" and "context.equity" are referring to, but this should get you on the right track.

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.

Hi Alisa ,

Thanks for your reply. What I ended up doing was apply the RC to to all nine securities individually , which is a pain :


    if rate_of_change[context.stock1] > rate_of_change[context.b] and rate_of_change[context.a] > rate_of_change[context.b]  :  
        order_target_percent(context.stock1,0.10 * context.leverage)  

    if rate_of_change[context.stock2] > rate_of_change[context.b] and rate_of_change[context.a] > rate_of_change[context.b] :  
        order_target_percent(context.stock2,0.10* context.leverage)  

But let me see if I can make it better by using your suggestions.

Thanks