bollinger_band¶
Defined in fynance.features.indicators
- bollinger_band(X, w=20, n=2, kind='s', axis=0, dtype=None)[source]
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:
- Xnp.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.
- wint, optional
Size of the lagged window of the moving average, must be positive. If
w is Noneorw=0, thenw=X.shape[axis]. Default is 20.- axis{0, 1}, optional
Axis along wich the computation is done. Default is 0.
- dtypenp.dtype, optional
The type of the output array. If dtype is not given, infer the data type from X input.
- nfloat, 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
emaandemstdfor details.If ‘s’ (default) then use simple moving average/standard deviation, see
smaandsmstdfor details.If ‘w’ then use weighted moving average/standard deviation, see
wmaandwmstdfor details.
- Returns:
- upper_band, lower_bandnp.ndarray[dtype, ndim=1 or 2]
Respectively upper and lower bollinger bands for each series.
See also
z_score,rsi,hma,macd_hist,cci
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
>>> import warnings >>> X = np.array([60, 100, 80, 120, 160, 80]).astype(np.float64) >>> with warnings.catch_warnings(): ... warnings.simplefilter("ignore", DeprecationWarning) ... 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])