Back to Community
Display backtest speed in bars/s

Hello,

being involved in development of other backtesters (in Python and in Julia) I wanted to compare backtest speed over several backtesters
Here is a backtest of a strategy that does (nearly) nothing... except sending to log backtest speed in bars/s.
I'm just sharing for people who want to see how their strategies impact backtest speed.
Here, we can see that speed in slightly inferior to 20'000 bars/s.
This Quantopian 2 / zipline is doing well !

Kind regards

PS : a similar measure with my Julia backtester shows a speed of less than 40'000 ticks/s (but with a MacBook Air mid 2011)

Clone Algorithm
2
Loading...
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
import time

def initialize(context):
    context.t0 = time.time()
    context.aapl = sid(24)
    context.invested = False
    context.i = 0
    context.n = 2000
    # context.n_window = 5
    
def s_speed(iters, t0):
    sp = iters / (time.time() - t0)
    return "%d BARS processed @ %f BARS/s" % (iters, sp)

def handle_data(context, data):
    # Note: data.can_trade() is explained in the next lesson
    if not context.invested and data.can_trade(context.aapl):
        order_target_percent(context.aapl, 0.60)
        context.invested = True
            
    if context.i % context.n == 0 and context.i != 0:
        print(s_speed(context.i, context.t0))
        print("")
    # if context.i % context.n in range(context.n_window):
    #     print("%d %s" % (context.i, data))
    context.i += 1                                    
There was a runtime error.