Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
before_trading_start - times out in Q2

Prior to Q2, this code did not time-out:

import time

def initialize(context):  
    context.stocks = sid(8554)  
    context.iterations = 4*6*1000000000 # ~ 4.4 minutes  
    # context.iterations = 5*6*1000000000 # TimeoutException: Call to before_trading_start timed out

def before_trading_start(context,data):  
    start = time.clock()  
    for k in xrange(context.iterations):  
        pass  
    elapsed = time.clock() - start  
    print 'Running time: ' + str(elapsed/60) + ' minutes'  

Now, when I run it, I get the error:

TimeoutException: Call to before_trading_start timed out
There was a runtime error on line 13.

My understanding is that there were no hardware/platform changes in going to Q2. So why would it run less efficiently?

1 response

By scaling the number of iterations by a factor of 3/4, I get about the same dwell time in before_trading_start. So, it is possible that Q2 runs more slowly than Q1 (didn't think of trying this in testdrive before Q1 got shut off), or maybe there are other factors, independent of the Q2 change. I think the take-away is that in writing algos that may time-out, significant margin needs to be built in, to avoid timing out, since the system performance is not fixed--it could change.

import time

def initialize(context):  
    context.stocks = sid(8554)  
    context.iterations = 3*6*1000000000 # ~ 4.2 minutes under Q2  
    # context.iterations = 4*6*1000000000 # ~ 4.4 minutes under Q1  
    # context.iterations = 5*6*1000000000 # TimeoutException: Call to before_trading_start timed out under Q1

def before_trading_start(context,data):  
    start = time.clock()  
    for k in xrange(context.iterations):  
        pass  
    elapsed = time.clock() - start  
    print 'Running time: ' + str(elapsed/60) + ' minutes'