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.
The band width tracks volatility: bands that narrow sharply (a squeeze) often precede a larger move, without saying in which direction. A close at or beyond a band is not a sell or buy signal by itself, since prices can walk along a band in a trend. Bollinger’s own setting is a 20-period average with 2 standard deviations; this method defaults to a window of 14, so pass window=20 to match most charting platforms.
Also known as: Bollinger Bands, BB, volatility bands, price channels.
Bollinger Bands in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_bollinger_bands as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
tickers=["USDJPY"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.technicals.get_bollinger_bands().xs("USDJPY", level=1, axis="columns").tail(5)
Or, after setting up the Finance Toolkit MCP, ask:
How did the dollar against the yen move within its Bollinger Bands from 26 to 31 December 2025?
Which returns:
| Date | Close | Lower Band | Middle Band | Upper Band |
|---|---|---|---|---|
| 2025-12-26 | 156.5 | 154.489 | 156.076 | 157.664 |
| 2025-12-28 | 156.32 | 154.562 | 156.129 | 157.697 |
| 2025-12-29 | 156.03 | 154.588 | 156.146 | 157.704 |
| 2025-12-30 | 156.33 | 154.627 | 156.179 | 157.732 |
| 2025-12-31 | 156.85 | 154.808 | 156.296 | 157.785 |
Parameters
get_bollinger_bands accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The time period to consider for historical data. Can be “intraday”, “daily”, “weekly”, “monthly”, “quarterly” or “yearly”. Defaults to “daily”. | "weekly" |
close_column | str | The column name for closing prices in the historical data. Defaults to “Adj Close”. | "Close" |
window | int | Number of periods for moving average calculation. The number of periods (time intervals) over which to calculate the moving average. Defaults to 14. | 20 |
num_std_dev | float | Number of standard deviations for the bands. Defaults to 2. | 3 |
rounding | int | None | The number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise). | 2 |
growth | bool | Whether to calculate the growth of the bands. Defaults to False. | True |
lag | int | list[int] | The lag to use for the growth calculation. Defaults to 1. | 4 |
standardize | bool | Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False. | True |