Bollinger Bands®

get_bollinger_bands(quotes, lookback_periods=20, standard_deviations=2)


name type notes
quotes Iterable[Quote] Iterable of the Quote class or its sub-class.
See here for usage with pandas.DataFrame
lookback_periods int, default 20 Number of periods (N) for the center line moving average. Must be greater than 1 to calculate; however we suggest a larger period for statistically appropriate sample size.
standard_deviations int, default 2 Width of bands. Standard deviations (D) from the moving average. Must be greater than 0.

Historical quotes requirements

You must have at least N periods of quotes to cover the warmup periods.

quotes is an Iterable[Quote] collection of historical price quotes. It should have a consistent frequency (day, hour, minute, etc). See the Guide for more information.




name type notes
date datetime Date
sma float, Optional Simple moving average (SMA) of Close price (center line)
upper_band float, Optional Upper line is D standard deviations above the SMA
lower_band float, Optional Lower line is D standard deviations below the SMA
percent_b float, Optional %B is the location within the bands. (Price-lower_band)/(upper_band-lower_band)
z_score float, Optional Z-Score of current Close price (number of standard deviations from mean)
width float, Optional Width as percent of SMA price. (upper_band-lower_band)/sma


See Utilities and Helpers for more information.


from stock_indicators import indicators

# This method is NOT a part of the library.
quotes = get_historical_quotes("SPY")

# calculate BollingerBands(20, 2)
results = indicators.get_bollinger_bands(quotes, 20, 2)

About Bollinger Bands®

Created by John Bollinger, Bollinger Bands depict volatility as standard deviation boundary lines from a moving average of Close price. Bollinger Bands® is a registered trademark of John A. Bollinger. [Discuss] 💬