Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
batch transform w/ set_universe hangs - what am I doing wrong?

This code appears to hang when run on minute data. What am I doing wrong?

from pytz import timezone

# globals for get_data batch transform decorator  
R_P = 0  # refresh period in days  
W_L = 15  # window length in days

def initialize(context):  
    set_universe(universe.DollarVolumeUniverse(floor_percentile=99.5, ceiling_percentile=100.0))  
def handle_data(context, data):  
    # get data  
    d = get_data(data)  
    if d == None:  
       return  
    if not intradingwindow_check(context):  
        return  
    context.stocks = [sid for sid in data]  
    print len(context.stocks)  
@batch_transform(refresh_period=R_P, window_length=W_L, clean_nans=False) # set globals R_P & W_L above  
def get_data(datapanel):  
    p = datapanel['price']  
    v = datapanel['volume']  
    return [p,v]

def intradingwindow_check(context):  
    # Converts all time-zones into US EST to avoid confusion  
    loc_dt = get_datetime().astimezone(timezone('US/Eastern'))  
    # if loc_dt.hour > 10 and loc_dt.hour < 15:  
    if loc_dt.hour == 10 and loc_dt.minute == 0:  
        return True  
    else:  
        return False  
3 responses

Hi Grant,

I took a look at your code and tried to run the backtest myself. I was able to get results quickly when I backtested for a one-week period. Expanding the backtest window to two years indeed caused the backtest to run slowly.

Have you tried using history? That function is faster and uses less memory, it seems it would serve your purpose in this example. Let me know if that works!

Alisa

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.

Thanks Alisa,

Are you sure you did the backtest correctly? The batch transform window length is 15 days, so the duration of your backtest needs to be > 15 days.

Regarding history, it will not return minute-level data, as I understand, just daily closing prices, and the most recent minute data.

Grant

Hi Grant,

We spent some time digging around today to identify what was going on. It turns out there was bug related to the roll over of set_universe(). Now that we're aware, I'll put it in our bug tracking system to take a closer look. In the meantime, your code should run fine within a quarter time period of a set universe. Thanks for the find!

Alisa