Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Please help with Set universe!

As you can see when i try to use set universe and loop through all the stocks in the portfolio, it doesnt give me an error but the algo crushes. Is it a problem with the syntax? BTW Please include more detailed documentation in quantopian since it will make learning it a lot easier haha

10 responses

Looks like a bug on our end - to my eye the code looks fine, and I see something in our error logs that looks wrong to me. I'm going to have someone take a look with me.

Sorry for the problem.

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.

haha Its fine. Im actually very surprised since i didnt see a single algo that used set universe to conduct analysis on several securities like that.
Im assuming thats the point of set universe, to avoid bias. Again, If at all possible please expand your documentation please!
I am starting an undergrad algo trading club and i would like to use quantopian, but teaching it to students may prove challenging without more
detailed documentation. Thank you Dan :)

Just checking - you did see the doc sections here and here? But you are looking for more? (That's a fine request, I just want to make sure you saw what we do have).

II actually did not see the second documentation thank you! My only comments in that the examples your provided in the second sections combine a lot of things and cloud a bit the understanding of how to use the methods. A simpler version perhaps would be great, especially with batch transform.
Are there plans for quantopian to incorporate bars and maybe perhaps days starting the first day at 0 and going up? That would be fantastic!
In a sense you could retrieve past data based on the day. i.e price[5] > price[4] > price[3] meaning if the market went up three days in a row or stuff like that.
Sorry for my long demanding comment probably requested too much haha.

The feedback is helpful, thank you.

You can do the price[5] type construct using batch transforms.

def handle_data(context, data):  
    my_thirds = whimsical_third(data)  
    log.info(my_thirds)  
@batch_transform(refresh_period=1, window_length=10)  
def whimsical_third(datapanel):  
    prices_df = datapanel['price']  
    if len(prices_df) > 3:  
        third_day = prices_df.ix[-3]  
        return (third_day)  
    else:  
        return None  

would something like this work?

def handle_data(context, data):  
    day_price= d_price(data,days)  
    log.info(day_price)  
@batch_transform(refresh_period=1, window_length=10)  
def d_price(datapanel,days):  
    prices_df = datapanel['price']  
    if len(prices_df) > days:  
        d_price = prices_df.ix[-days]  
        return (d_price)  
    else:  
        return None  

Sure. See attached.

Am I wrong but it seems that the price it logs is the price from three days ago and every new day the price changes.
Is there a way to keep track of how many days passed since the algo started?

Sure. You can get_datetime() in your algorithm and store the date, then use that date in whatever operation you'd like to count the time as it progresses.

Daniel, it looks like you need to change what you are passing to the order function, the order function expects a Security object, however you are passing to it the data keyed by the Security in the bar's data.

i.e. it should be order(sid, 1000), not order(data[sid], 1000)

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.