Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
What to do if the backtest is too slow?

I cloned and runned the full backtest "long-short-equity" algo from Lecture39, see here.
Although the period is only one year long, I could not finish it in one hour.
Anything I can do at this moment? Thanks.

2 responses

Hmm,

You are right. It's slow.

Try deleting the entire 'handle_data' method (which runs every minute). Move the recording logic somewhere else to only run once a day. Perhaps move it to the 'daily_clean' function.

def daily_clean(context, data):

    for stock in context.portfolio.positions:  
        if stock not in context.security_set and data.can_trade(stock):  
            order_target_percent(stock, 0)

    record(num_positions=len(context.portfolio.positions),  
           exposure=context.account.net_leverage,  
           leverage=context.account.leverage)

Not sure why the recording was done every minute. Generally, limit the use of the 'handle_data' function to keep things fast.

Another thing to try to speed the algorithm up is to replace the 'filter_universe' function with one of the newer Q500US or Q1500US built in filters.

See attached.

@Dan Once again, thanks for your help. It works normal.