Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Speed, measuring runtime

Code that can be added to any backtest to measure overall runtime.

Output

1969-12-31 16:00 initialize:10 INFO 2017-03-02 to 2018-03-02  
2018-03-02 13:00 run_end:25 INFO Runtime  0 hr 0.6 min  

Code

import time

START = time.time()

def initialize(context):  
    log.info('{} to {}'.format(get_environment('start').date(), get_environment('end').date()))  
    schedule_function(run_end, date_rules.every_day(), time_rules.market_open(minutes=390))  
    # It has to be done like that b/c market_close is 1 minute before close

def run_end(context, data):  
    if get_datetime() == get_environment('end'):  # end of run  
        elapsed = (time.time() - START) / 60  # minutes  
        log.info('Runtime  {} hr {} min'.format(int(elapsed / 60), '%.1f' % (elapsed % 60)))  

Example minimal backtest with pipeline, QTradableStocksUS and a fundamental, doesn't do any trading.