Indicators

#### Next topic

fynance.features.indicators.cci

# fynance.features.indicators.bollinger_band¶

fynance.features.indicators.bollinger_band(X, w=20, n=2, kind='s', axis=0, dtype=None)

Compute the bollinger bands of size w for each X’ series’.

Bollinger Bands are a type of statistical chart characterizing the prices and volatility over time of a financial instrument or commodity, using a formulaic method propounded by J. Bollinger in the 1980s [1].

Parameters: X : np.ndarray[dtype, ndim=1 or 2] Elements to compute the indicator. If X is a two-dimensional array, then an indicator is computed for each series along axis. w : int, optional Size of the lagged window of the moving average, must be positive. If w is None or w=0, then w=X.shape[axis]. Default is 20. axis : {0, 1}, optional Axis along wich the computation is done. Default is 0. dtype : np.dtype, optional The type of the output array. If dtype is not given, infer the data type from X input. n : float, optional Number of standard deviations above and below the moving average. Default is 2. kind : {‘s’, ‘e’, ‘w’} If ‘e’ then use exponential moving average/standard deviation, see ema and emstd for details. If ‘s’ (default) then use simple moving average/standard deviation, see sma and smstd for details. If ‘w’ then use weighted moving average/standard deviation, see wma and wmstd for details. upper_band, lower_band : np.ndarray[dtype, ndim=1 or 2] Respectively upper and lower bollinger bands for each series.

Notes

Let $$\mu_t$$ the moving average and $$\sigma_t$$ is the moving standard deviation of size w for X at time t.

$\begin{split}upperBand_t = \mu_t + n \times \sigma_t \\ lowerBand_t = \mu_t - n \times \sigma_t\end{split}$

References

Examples

>>> X = np.array([60, 100, 80, 120, 160, 80]).astype(np.float64)
>>> upper_band, lower_band = bollinger_band(X, w=3, n=2)
>>> upper_band
array([ 60.        , 120.        , 112.65986324, 132.65986324,
185.31972647, 185.31972647])
>>> lower_band
array([60.        , 40.        , 47.34013676, 67.34013676, 54.68027353,
54.68027353])