.. _performance: Computational Performance ========================= .. automodule:: src.boatwright Ultimately, how fast a backtest executes is a function of several factors: the number and complexity of technical indicators computed in :ref:`boatwright.Strategy.calc_signals() `, the length of the dataframe, and the number of orders that are generated and processed by the broker throughout :ref:`boatwright.Backtest.run() `, and of course the user's hardware. In this testing the :ref:`MACD `, i.e. the simplest strategy, is backtested using a 2019 MacBook Pro (Processor: 2 Ghz Quad-Core Intel i5 cores, Memory: 16 GB 3733 MHz LPDDR4X) First, timing a single backtest indicates that the 'bottle-neck' of backtests is not the calculation of the technical indicators, but the backtest process :: data length: 437356 time calc_signals(): 0.89 s time backtest(): 185.92 s total_time: 186.81 s This is anticipated as the technical indicators in the MACD strategy are moving averages computed with pandas rolling windows, and so leverages the efficiency of the pandas data processing library which is highly optimized for performance with critical code paths written in Cython or C. The backtest process is written in python as a loop iterating through each row of the dataframe, which is necessary but comparably less efficient. Next, backtest runtime is explored as a function of 'number of bars' or length of input dataframe revealing an exponential relationship between the length of the backtest and runtime. 100,000 bars of data, which runs in ~40s, is a 69.44 day long backtest for 'MINUTE' granularity, and 11.42 years for 'HOUR' granularity, and 2.74 centries for 'DAY' granularity. **Python source code:** :download:`../../examples/performance_testing/backtest_vs_nbars.py` .. literalinclude:: ../../examples/performance_testing/backtest_vs_nbars.py .. image:: runtime_vs_nbars.png :align: center Parrallel processing of backtests is also supported. The analysis below executes a parameter scan, composed of 23 backtests, first sequentially, and then in parallel with 3 cores, demonstrating a jump in efficiency. :: number of backtests: 23 length of backtest: 44331.0 sequential runtime: 98.0715708732605 s parallel runtime: 32.0289888381958 s **Python source code:** :download:`../../examples/performance_testing/sequential_vs_parallel.py` .. literalinclude:: ../../examples/performance_testing/sequential_vs_parallel.py