Python Backtesting Primer using backtesting.py

B/O Trading Blog
8 min readJun 23, 2022

Photo by Mika Baumeister on Unsplash.com

Here is a step-by-step tutorial on how to start backtesting trading strategies using Python and the backtesting.py framework.

This story is solely for general information purposes, and should not be relied upon for trading recommendations or financial advice. Source code and information is provided for educational purposes only, and should not be relied upon to make an investment decision. Please review my full cautionary guidance before continuing.

What is Backtesting?

According to Investopedia, “Backtesting assesses the viability of a trading strategy by discovering how it would play out using historical data.”

So we are basically testing your strategy using a range of historic price data to find out how the strategy had performed if we had used it at some point in the past.

The intent is that we want to make sure the strategy provides reliable entry and exit signals in a variety of market conditions so that we can avoid loss and hopefully gain profits from trading in the future.

Although past pricing data may not be a good indicator of future performance, unfortunately it’s the best we have to work with.

Trade Ideas provides AI…

--

--

B/O Trading Blog

Blogging about algorithmic trading, Python utilities and passive income opportunities.