fynance.features.indicators.cci¶
-
fynance.features.indicators.
cci
(X, high=None, low=None, w=20, axis=0, dtype=None)¶ Compute Commodity Channel Index of size w for each X’ series’.
CCI is an oscillator introduced by Donald Lamber in 1980 [2]. It is calculated as the difference between the typical price of a commodity and its simple moving average, divided by the moving mean absolute deviation of the typical price.
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.
- high, low : np.ndarray[dtype, ndim=1 or 2], optional
Series of high and low prices, if None then p_t is computed with only closed prices. Must have the same shape as X.
- w : int, optional
Size of the lagged window of the moving average, must be positive. If
w is None
orw=0
, thenw=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.
Returns: - np.ndarray[dtype, ndim=1 or 2]
Commodity Channal Index for each series.
See also
Notes
The index is usually scaled by an inverse factor of 0.015 to provide more readable numbers:
\[\begin{split}cci = \frac{1}{0.015} \frac{p_t - sma^w_t(p)}{mad^w_t(p)} \\ \text{where, }p = \frac{p_{close} + p_{high} + p_{low}}{3}\end{split}\]References
[2] https://en.wikipedia.org/wiki/Commodity_channel_index Examples
>>> X = np.array([60, 100, 80, 120, 160, 80]).astype(np.float64) >>> cci(X, w=3, dtype=np.float64) array([ 0. , 66.66666667, 0. , 100. , 100. , -100. ])