Bollinger Band Strategy Developed with ChatGPT: Backtest Results

We already discussed how to create and backtest a trading strategy using Chat GPT in a prior article and video, but today we are going to skip the idea generation stage and jump right into the trading rules and backtest: How to make a Bollinger Band strategy using ChatGPT.

Bollinger bands are one of the most popular technical indicators in technical analysis. Can ChatGPT come up with a profitable trading strategy and do a backtest?

In this article, we are going to look at what Bollinger Bands are, ask ChatGPT to create a Bollinger Band trading strategy, and backtest the strategy using Python.

What are Bollinger Bands?

Bollinger Bands are a technical indicator developed by John Bollinger in the early 1980s. It consists of three lines: a middle band and an upper and lower band.

The middle band is a simple moving average of the securities closing price. The upper and lower bands are set above and below the moving average by a certain number of standard deviations of price, thus incorporating volatility. The idea behind Bollinger Bands arose from the observation that volatility was dynamic, not static as was widely believed at the time. 

Bollinger Bands strategies typically use the 20-period moving average. By default, the upper and lower bands are set two standard deviations above and below the moving average. However, traders can customize the number of periods in the moving average as well as the number of deviations.

Creating a Bollinger Bands strategy with ChatGPT

We asked ChatGPT to make 2 trading strategies using Bollinger Bands and this is what it came up with (we quote ChatGPT):

  1. Bollinger Bands mean reversion strategy: In this strategy, you look for the price of an asset to revert back to its mean after it has moved away from it. When the price moves above the upper band, it indicates that the asset is overbought and is likely to fall back to its mean, and when the price moves below the lower band, it indicates that the asset is oversold and is likely to rise back to its mean. 
  1. Bollinger bands squeeze strategy: Here you look for periods of low volatility in the market. This can be identified when the Bollinger Bands are close together. When the bands start to expand again, it indicates that there may be a breakout in the price of the asset. 

The mean reversion strategy is a classic strategy well known by many traders. The squeeze strategy is also popular, but not discussed much, so we are going to backtest this one.

Now, we are going to ask it to write a python code to backtest the strategy using pandas, finance and matplotlib.

ChatGPT Bollinger Bands strategy – trading rules

In this strategy, a squeeze is identified when the Bollinger Bands “squeeze” inside the Keltner Channels. The Keltner Channels are very similar to the Bollinger Bands but instead of using standard deviation to calculate the upper and lower band they use the stocks average true range (ATR). In this case it is 2 times the ATR.

This is not the usual definition of squeeze but it is an interesting strategy that Chat GPT came up with so we are going to backtest it anyway.

ChatGPT Bollinger Bands strategy trading rules

The trading rules are very simple:

Trading Rules

THIS SECTION IS FOR MEMBERS ONLY. _________________ Click Here To Get Access Click Here To Get Access To Trading Rules

ChatGPT Bollinger Bands strategy – backtests

We started the backtest since the inception of the SPY in 1993. The data is not adjusted for dividends and splits. Here is the equity curve:

ChatGPT Bollinger Bands strategy

The compounded returns look low, and as you can see, the returns are a bit erratic and the drawdown might be tad too hogh for most traders.

Here are some trading metrics and statistics we calculated on our own:

  • CAGR is 2.53% (buy and hold 7.64%)
  • Time spent in the market is 31%
  • Riskadjusted return is 8.16% (CAGR divided by time spend in the market)
  • Maximum drawdown is 34.07% (-56.47% for buy and hold)

To be honest, the strategy performs poorly. If we adjust the return for the time spent in the market it improves, but not dramatically. The maximum drawdown decreases as well.

ChatGPT Bollinger Bands strategy – conclusion

To sum up, ChatGPT did come up with an unusual strategy, at least for us. However, the strategy wasn’t very profitable. Nevertheless, it did the backtest perfectly and proved one more time how useful it can be for trading, even though the strategy is not useful for live trading.

List of investment strategies

We have written over 1200 articles on this blog since we started in 2012. Many articles contain specific investment rules that can be backtested for profitability and performance metrics.

The trading rules are compiled into a package where you can purchase all of them (recommended) or just a few of your choice. We have hundreds of investment ideas in the compilation.

The strategies are taken from our landing page of investment strategies.

For a list of the strategies we have made, please click on the green banner:

These strategies must not be misunderstood for the premium strategies that we charge a fee for:

Related reading: ChatGPT Trading Strategies (How To Use AI To Make Strategies)


How do Bollinger Bands work?

Bollinger Bands consist of three lines – a middle band (simple moving average) and upper and lower bands (set above and below the moving average by a certain number of standard deviations). The upper and lower bands indicate potential overbought or oversold conditions. For instance, when the price moves above the upper band, it suggests overbought conditions, signaling a potential reversal.

What is a Bollinger Bands mean reversion strategy?

This strategy involves looking for the price of an asset to revert back to its mean after moving away from it. It identifies overbought conditions when the price is above the upper band and oversold conditions when below the lower band. The squeeze strategy identifies periods of low volatility when the Bollinger Bands are close together. An expansion in the bands suggests a potential breakout in the asset’s price.

What are the trading rules for the ChatGPT Bollinger Bands strategy?

In this strategy, a squeeze is identified when the Bollinger Bands “squeeze” inside the Keltner Channels, which use the stock’s average true range (ATR) to calculate upper and lower bands. The trading rules involve buying and holding when the lower Bollinger Band is above the Keltner lower band and the upper Bollinger band is under the Keltner upper band. Selling occurs if either of these conditions is not met.

Similar Posts