Vectorized backtesting with pandas
As we mentioned in the introduction to this chapter, there are two approaches to carrying out backtests. The simpler one is called vectorized backtesting. In this approach, we multiply a signal vector/matrix (containing an indicator of whether we are entering or closing a position) by the vector of returns. By doing so, we calculate the performance over a certain period of time.
Due to its simplicity, this approach cannot deal with many of the issues we described in the introduction, for example:
- We need to manually align the timestamps to avoid look-ahead bias.
- There is no explicit position sizing.
- All performance measurements are calculated manually at the very end of the backtest.
- Risk-management rules like stop-loss are not easy to incorporate.
That is why we should use vectorized backtesting mostly if we are dealing with simple trading strategies and want to explore their initial potential in a few lines...