Python talib.CCI Examples

The following are 13 code examples of talib.CCI(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module talib , or try the search function .
Example #1
Source File: features.py    From trading-server with GNU General Public License v3.0 7 votes vote down vote up
def CCI(self, period: int, bars: list):
        """
        Return CCI (Commodity Chanel Index) for n bars close price.
​
        CCI = (Typical Price − MA) / 0.015 * Mean Deviation

        where:
            Typical Price = ∑P((H + L + C) / 3))
            P = number of bars (period)
            MA = Moving Average = (∑P Typical Price) / P
            Mean Deviation=(∑P | Typical Price - MA |) / P
        """

        self.check_bars_type(bars)

        cci = ta.CCI(
            bars['high'], bars['low'], bars['close'], timeperiod=period)

        return cci 
Example #2
Source File: cci.py    From jesse with MIT License 6 votes vote down vote up
def cci(candles: np.ndarray, period=14, sequential=False) -> Union[float, np.ndarray]:
    """
    CCI - Commodity Channel Index

    :param candles: np.ndarray
    :param period: int - default=14
    :param sequential: bool - default=False

    :return: float | np.ndarray
    """
    if not sequential and len(candles) > 240:
        candles = candles[-240:]

    res = talib.CCI(candles[:, 3], candles[:, 4], candles[:, 2], timeperiod=period)

    if sequential:
        return res
    else:
        return None if np.isnan(res[-1]) else res[-1] 
Example #3
Source File: talib_wrapper.py    From tia with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def CCI(frame, n=14, high_col='high', low_col='low', close_col='close'):
    return _frame_to_series(frame, [high_col, low_col, close_col], talib.CCI, n) 
Example #4
Source File: talib_numpy.py    From QUANTAXIS with MIT License 5 votes vote down vote up
def TA_CCI(high:np.ndarray, 
           low:np.ndarray, 
           close:np.ndarray, 
           timeperiod:int=14) -> np.ndarray:
    """
    名称:平均趋向指数的趋向指数
    简介:使用CCI指标,指标判断CCI趋势。
    CCI - Commodity Channel Index
    """
    real = talib.CCI(high, 
                     low, 
                     close, 
                     timeperiod=timeperiod)
    delta = np.r_[np.nan, np.diff(real)]
    return np.c_[real, delta] 
Example #5
Source File: talib_indicators.py    From QUANTAXIS with MIT License 5 votes vote down vote up
def CCI(DataFrame, N=14):
    res = talib.CCI(DataFrame.high.values, DataFrame.low.values, DataFrame.close.values, N)
    return pd.DataFrame({'CCI': res}, index=DataFrame.index) 
Example #6
Source File: ta_indicator_mixin.py    From strategy with Apache License 2.0 5 votes vote down vote up
def cci(self, sym, frequency, period=14):
        if not self.kbars_ready(sym, frequency):
            return []

        highs = self.high(sym, frequency)
        lows = self.low(sym, frequency)
        closes = self.close(sym, frequency)

        cci = ta.CCI(highs, lows, closes, timeperiod=period)

        return cci 
Example #7
Source File: ta.py    From dash-technical-charting with MIT License 5 votes vote down vote up
def add_CCI(self, timeperiod=14,
            type='line', color='secondary', **kwargs):
    """Channel Commodity Index."""

    if not (self.has_high and self.has_low and self.has_close):
        raise Exception()

    utils.kwargs_check(kwargs, VALID_TA_KWARGS)
    if 'kind' in kwargs:
        type = kwargs['kind']

    name = 'CCI({})'.format(str(timeperiod))
    self.sec[name] = dict(type=type, color=color)
    self.ind[name] = talib.CCI(self.df[self.hi].values,
                               self.df[self.lo].values,
                               self.df[self.cl].values,
                               timeperiod) 
Example #8
Source File: array_manager.py    From 51bitqunt with MIT License 5 votes vote down vote up
def cci(self, n, array=False):
        """
        Commodity Channel Index (CCI).
        """
        result = talib.CCI(self.high, self.low, self.close, n)
        if array:
            return result
        return result[-1] 
Example #9
Source File: ta_lib.py    From ctpbee with MIT License 5 votes vote down vote up
def cci(self, n, array=False):
        """
        Commodity Channel Index (CCI).
        """
        result = talib.CCI(self.high, self.low, self.close, n)
        if array:
            return result
        return result[-1] 
Example #10
Source File: TinyQuantBase.py    From futuquant with Apache License 2.0 5 votes vote down vote up
def cci(self, n, array=False):
        """CCI指标"""
        result = talib.CCI(self.high, self.low, self.close, n)
        if array:
            return result
        return result[-1]

    # ---------------------------------------------------------------------- 
Example #11
Source File: test_indicator_momentum.py    From pandas-ta with MIT License 5 votes vote down vote up
def test_cci(self):
        result = pandas_ta.cci(self.high, self.low, self.close)
        self.assertIsInstance(result, Series)
        self.assertEqual(result.name, 'CCI_14_0.015')

        try:
            expected = tal.CCI(self.high, self.low, self.close)
            pdt.assert_series_equal(result, expected, check_names=False)
        except AssertionError as ae:
            try:
                corr = pandas_ta.utils.df_error_analysis(result, expected, col=CORRELATION)
                self.assertGreater(corr, CORRELATION_THRESHOLD)
            except Exception as ex:
                error_analysis(result, CORRELATION, ex) 
Example #12
Source File: talib_indicators.py    From qtpylib with Apache License 2.0 5 votes vote down vote up
def CCI(data, **kwargs):
    _check_talib_presence()
    _, phigh, plow, pclose, _ = _extract_ohlc(data)
    return talib.CCI(phigh, plow, pclose, **kwargs) 
Example #13
Source File: ctaLineBar.py    From vnpy_crypto with MIT License 4 votes vote down vote up
def __recountCci(self):
        """CCI计算
        顺势指标又叫CCI指标,CCI指标是美国股市技术分析 家唐纳德·蓝伯特(Donald Lambert)于20世纪80年代提出的,专门测量股价、外汇或者贵金属交易
        是否已超出常态分布范围。属于超买超卖类指标中较特殊的一种。波动于正无穷大和负无穷大之间。但是,又不需要以0为中轴线,这一点也和波动于正无穷大
        和负无穷大的指标不同。
        它最早是用于期货市场的判断,后运用于股票市场的研判,并被广泛使用。与大多数单一利用股票的收盘价、开盘价、最高价或最低价而发明出的各种技术分析
        指标不同,CCI指标是根据统计学原理,引进价格与固定期间的股价平均区间的偏离程度的概念,强调股价平均绝对偏差在股市技术分析中的重要性,是一种比
        较独特的技术指标。
        它与其他超买超卖型指标又有自己比较独特之处。象KDJ、W%R等大多数超买超卖型指标都有“0-100”上下界限,因此,它们对待一般常态行情的研判比较适用
        ,而对于那些短期内暴涨暴跌的股票的价格走势时,就可能会发生指标钝化的现象。而CCI指标却是波动于正无穷大到负无穷大之间,因此不会出现指标钝化现
        象,这样就有利于投资者更好地研判行情,特别是那些短期内暴涨暴跌的非常态行情。
        http://baike.baidu.com/view/53690.htm?fromtitle=CCI%E6%8C%87%E6%A0%87&fromid=4316895&type=syn


        """
        if self.inputCciLen <= 0:
            return

        # 1、lineBar满足长度才执行计算
        if len(self.lineBar) < self.inputCciLen+2:
            self.debugCtaLog(u'数据未充分,当前Bar数据数量:{0},计算CCI需要:{1}'.
                             format(len(self.lineBar), self.inputCciLen + 2))
            return

        # 计算第1根RSI曲线

        # 3、inputCc1Len(包含当前周期)
        if self.mode == self.TICK_MODE:
            listClose = [x.close for x in self.lineBar[-self.inputCciLen - 2:-1]]
            listHigh = [x.high for x in self.lineBar[-self.inputCciLen - 2:-1]]
            listLow  = [x.low for x in self.lineBar[-self.inputCciLen - 2:-1]]
            idx = 2
        else:
            listClose = [x.close for x in self.lineBar[-self.inputCciLen-1:]]
            listHigh = [x.high for x in self.lineBar[-self.inputCciLen - 1:]]
            listLow = [x.low for x in self.lineBar[-self.inputCciLen - 1:]]
            idx = 1

        barCci = ta.CCI(high=np.array(listHigh, dtype=float), low=np.array(listLow, dtype=float),
                        close=np.array(listClose, dtype=float), timeperiod=self.inputCciLen)[-1]

        barCci = round(float(barCci), 3)

        l = len(self.lineCci)
        if l > self.inputCciLen*8:
            del self.lineCci[0]
        self.lineCci.append(barCci)