Bollinger Bands
Calculate the Bollinger Bands for a given price series.
Bollinger Bands are a volatility indicator that consists of three lines: an upper band, a middle band (simple moving average), and a lower band. The upper and lower bands are calculated as the moving average plus and minus a specified number of standard deviations, respectively.
The formula is as follows:
\[\text{Middle Band} = \operatorname{SMA}(\text{Close},\; \text{Window})\] \[\text{Upper Band} = \text{Middle Band} + (\text{Num Std Dev} \cdot \text{Std Dev})\] \[\text{Lower Band} = \text{Middle Band} - (\text{Num Std Dev} \cdot \text{Std Dev})\]The standard deviation is the population standard deviation (dividing by n), as Bollinger himself specifies and as TA-Lib and StockCharts both implement, not pandas’ default sample standard deviation.
Also known as: Bollinger Bands, BB, volatility bands, price channels.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Bollinger Bands for you. Just ask in plain English.
Calculate the Bollinger Bands in Python
The Bollinger Bands is available in the Technicals module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_bollinger_bands as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(tickers=["AAPL", "MSFT"])
toolkit.technicals.get_bollinger_bands().xs("AAPL", level=1, axis="columns")
Which returns:
| Date | Close | Lower Band | Middle Band | Upper Band |
|---|---|---|---|---|
| 2026-06-18 | 298.01 | 284.642 | 300.742 | 316.843 |
| 2026-06-22 | 297.01 | 284.201 | 300.078 | 315.955 |
| 2026-06-23 | 294.3 | 285.08 | 298.585 | 312.09 |
| 2026-06-24 | 293.08 | 285.388 | 297.358 | 309.328 |
| 2026-06-25 | 275.15 | 280.386 | 294.781 | 309.176 |
| 2026-06-26 | 283.78 | 279.544 | 293.098 | 306.652 |
| 2026-06-29 | 281.74 | 277.796 | 291.684 | 305.571 |
| 2026-06-30 | 289.36 | 277.667 | 291.599 | 305.53 |
| 2026-07-01 | 294.38 | 277.788 | 291.799 | 305.81 |
| 2026-07-02 | 308.63 | 276.137 | 292.727 | 309.318 |
Parameters
get_bollinger_bands accepts the following parameters:
- period (str, optional): The time period to consider for historical data. Can be “daily”, “weekly”, “quarterly”, or “yearly”. Defaults to “daily”.
- close_column (str, optional): The column name for closing prices in the historical data. Defaults to “Adj Close”.
- window (int, optional): Number of periods for moving average calculation. The number of periods (time intervals) over which to calculate the moving average.
- num_std_dev (int, optional): Number of standard deviations for the bands. Defaults to 2.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.
- growth (bool, optional): Whether to calculate the growth of the bands. Defaults to False.
- lag (int | list[int], optional): The lag to use for the growth calculation.
- standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. Defaults to 1.
Related Volatility Indicators
The Technicals module page introduces the module, and the sidebar lists all of its functions.