14 min read

Backtesting a Stocks in Play Day Trading Paper with PyBroker

In the last post, we backtested an opening range breakout strategy on QQQ using PyBroker. In this tutorial, we'll backtest the strategy from the paper A Profitable Day Trading Strategy for the U.S. Equity Market, which dynamically selects 20 stocks with unusual opening volume every day.

Backtesting on more than one symbol

Libraries like Backtesting.py can only backtest single symbol strategies. PyBroker can run a strategy on many symbols under a single shared account, which means you can backtest more interesting strategies on a portfolio of stocks.

To show how this works, let's run the backtest from our last post on a hardcoded list of popular stocks. PyBroker has a ctx.session variable for each symbol, which means each symbol can independently track its own opening range. So AAPL's opening range won't mix with NVDA's, and the execution function doesn't need to change at all. The only logic we are changing is in the position sizing function so that we allocate a portion of the account's cash to each symbol.

This post is for subscribers only