Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
runtime error : SIDData' object has no attribute 'price

Hi,

I have a test csv file with signals for each day that I want to trade with. After using fetch csv and universe_func, I was able to get the symbols into my universe.

However, when I run the program, I get the runtime error 'SIDData' object has no attribute 'price'. I need the current price of the security for part of the algorithm.

I followed the example of using fetcher to create custom universe. Does anyone know what I am doing wrong?

import pandas as pd

pd.set_printoptions(max_columns=10)

def initialize(context):  
    # import the custom CSV data file  
    fetch_csv("https://dl.dropboxusercontent.com/s/jk2aldddnstbduy/analyst action spy trade may 2014.csv",  
              pre_func=preview,  
              post_func=preview,  
              date_column='date',  
              universe_func=my_universe)  
    context.max_notional = 1000000.1  
    context.min_notional = -1000000.0  
    context.istraded = {}  


# my_universe returns a set of securities that define your universe.  
def my_universe(context, fetcher_data):  
    # fetcher_data is the data resulting from the CSV file from fetcher.

    # set my_stocks to be every sid in the fetcher_data  
    my_stocks = set(fetcher_data['sid'])

    # log the size of the universe for debugging  
    context.count = len(my_stocks)  
    print 'total universe size: {c}'.format(c=context.count)

    # return the sids we identified earlier  
    return my_stocks

# see a snapshot of your CSV for debugging  
def preview(df):  
    log.info(' %s ' % df.head())  
    return df

def handle_data(context,data):  
    # Convert to EST timezone  
    exchange_time = pd.Timestamp(get_datetime()).tz_convert('US/Eastern')  

    # loop over the stocks in universe  
    for stock in data:  
        print stock.symbol  
        print data[stock].price  
1 response

Stocks don't necessarily trade every minute - you ran into an instance where a stock in your universe was missing price data in a minute bar, causing the runtime error.

You can add a check to your code to guard against missing data by doing the following :

for stock in data:  
        if 'price' in data[stock]:  
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.