Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Why is this error happening? "AttributeError: 'SIDData' object has no attribute 'IsInside'"

Hey everyone,
I'm new to Python and Quantopian. I got this error when I build the algo.

AttributeError: 'SIDData' object has no attribute 'IsInside'
... USER ALGORITHM:32, in Entry
if (context.S[stock].IsInside):

Can anyone help me out please?
Below is my sample strategy:

import zipline  
Inside_bar_min = 5

def initialize(context):  
    set_symbol_lookup_date('2015-09-01')  
    context.zyc = symbols('spy','aapl','nflx')[0]  
    beg_min = 20  
    end_min = 40  
    for i in xrange(beg_min,end_min,5):  
        schedule_function(ReconcileData,date_rules.every_day(),time_rules.market_open(minutes=i))  
        schedule_function(InsideBar,date_rules.every_day(),time_rules.market_open(minutes=i))  
        schedule_function(Entry,date_rules.every_day(),time_rules.market_open(minutes=i))  
    context.S = {}  

def handle_data(context,data):  
    record(Leverage  = context.account.leverage)  
    if (context.zyc in context.S and 'IsInside' in context.S[context.zyc]):  
        record(InsideBar_count = 2 if context.S[context.zyc].IsInside else 0)  
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
def Entry(context, data):  
    positions = context.portfolio.positions  
    openPositions = [stock for stock in positions if positions[stock].amount != 0]  
    eligible = []  
    for stock in context.S:  
        if (stock in openPositions):  
            continue  
        if (get_open_orders(stock)):  
            continue  
        if (context.S[stock].IsInside):  
            eligible.append(stock)

    eligible += openPositions  
    eligibleCount = float(len(eligible))  
    for stock in eligible:  
        order_target_percent(stock, (1.0 / eligibleCount))

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
def ReconcileData(context, data):  
    # Reconcile available stocks into context.S  
    for stock in data:  
        if (stock not in context.S):  
            context.S[stock] = zipline.protocol.SIDData(stock)  
    # Reconcile backwards for securities we can no longer trade  
    removeThese = []  
    for stock in context.S:  
        if (stock not in data):  
            removeThese.append(stock)  
    for stock in removeThese:  
        del context.S[stock]  
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
def InsideBar(context,data):  
    highDeck = history(2*Inside_bar_min+1, "1m", "high").dropna(axis=1)  
    lowDeck  = history(2*Inside_bar_min+1, "1m", "low").dropna(axis=1)  
    highDeck = highDeck[[sid for sid in highDeck if sid in data]]  
    lowDeck  = lowDeck[[sid for sid in lowDeck if sid in data]]  
    for stock in context.S:  
        context.S[stock].IsInside = False  
        isInsideTestFailed = False  
        context.S[stock].outside_high = max(highDeck[stock].iloc[-10:-6])  
        context.S[stock].outside_low = min(lowDeck[stock].iloc[-10:-6])  
        context.S[stock].inside_high = max(highDeck[stock].iloc[-5:-1])  
        context.S[stock].inside_low = min(lowDeck[stock].iloc[-5:-1])  
        if context.S[stock].outside_high < context.S[stock].inside_high or context.S[stock].outside_low >context.S[stock].inside_low:  
             isInsideTestFailed = True  
             break  
        if (not isInsideTestFailed):  
             context.S[stock].IsInside = True  

Thank you

1 response

Hi yusen,

I took a look at your algo and changing line 74 from break to continue seems to have solved the problem. The break statement in Python exits you out of the for loop. I think the continue statement is what you wanted in the first place!

As a side note, I was able to find this by using the built-in debugger tool and placing a breakpoint on line 64. I then stepped through the for loop 1 line at a time, and noticed that it only made it through the loop once.

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.