Python talib.KAMA Examples

The following are 10 code examples of talib.KAMA(). 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: DyStockDataUtility.py    From DevilYuan with MIT License 6 votes vote down vote up
def getKamas(df, mas, dropna=True):
        """
            获取周期内的考夫曼均价
            @mas: [5, 10, 20, 30, 60, ...]
        """
        if df is None:
            return pd.DataFrame([])

        means = {}
        names = []
        for ma in mas:
            mean = talib.KAMA(df['close'].values, ma)
            name = 'kama%s'%ma
            
            means[name] = mean
            names.append(name)

        df = pd.DataFrame(means, index=df.index, columns=names)

        return df.dropna() if dropna else df 
Example #2
Source File: kama.py    From jesse with MIT License 6 votes vote down vote up
def kama(candles: np.ndarray, period=30, source_type="close", sequential=False) -> Union[float, np.ndarray]:
    """
    KAMA - Kaufman Adaptive Moving Average

    :param candles: np.ndarray
    :param period: int - default: 30
    :param source_type: str - default: "close"
    :param sequential: bool - default=False

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

    source = get_candle_source(candles, source_type=source_type)
    res = talib.KAMA(source, timeperiod=period)

    return res if sequential else res[-1] 
Example #3
Source File: DyStockDataUtility.py    From DevilYuan with MIT License 6 votes vote down vote up
def getKamas(df, mas, dropna=True):
        """
            获取周期内的考夫曼均价
            @mas: [5, 10, 20, 30, 60, ...]
        """
        if df is None:
            return pd.DataFrame([])

        means = {}
        names = []
        for ma in mas:
            mean = talib.KAMA(df['close'].values, ma)
            name = 'kama%s'%ma
            
            means[name] = mean
            names.append(name)

        df = pd.DataFrame(means, index=df.index, columns=names)

        return df.dropna() if dropna else df 
Example #4
Source File: apriori.py    From cryptotrader with MIT License 5 votes vote down vote up
def predict(self, obs):
        """
        Performs prediction given environment observation
        """
        prices = obs.xs('open', level=1, axis=1).astype(np.float64)
        mu = prices.apply(tl.KAMA, timeperiod=self.window, raw=True).iloc[-1].values

        price_relative = np.append(safe_div(mu, prices.iloc[-1].values) - 1, [0.0])

        return price_relative 
Example #5
Source File: talib_numpy.py    From QUANTAXIS with MIT License 5 votes vote down vote up
def TA_KAMA(close, timeperiod=30):
    """
    请直接用 talib.KAMA(close, timeperiod)
    KAMA - Kaufman Adaptive Moving Average
    """
    real = talib.KAMA(close, timeperiod=timeperiod)
    return np.c_[real] 
Example #6
Source File: talib_series.py    From QUANTAXIS with MIT License 5 votes vote down vote up
def KAMA(Series, timeperiod=30):
    res = talib.KAMA(Series.values, timeperiod)
    return pd.Series(res, index=Series.index) 
Example #7
Source File: ta.py    From dash-technical-charting with MIT License 5 votes vote down vote up
def add_KAMA(self, timeperiod=20,
             type='line', color='secondary', **kwargs):
    """Kaufmann Adaptive Moving Average."""

    if not self.has_close:
        raise Exception()

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

    name = 'KAMA({})'.format(str(timeperiod))
    self.pri[name] = dict(type=type, color=color)
    self.ind[name] = talib.KAMA(self.df[self.cl].values,
                                timeperiod) 
Example #8
Source File: test_reg.py    From finta with GNU Lesser General Public License v3.0 5 votes vote down vote up
def test_kama():
    '''test TA.KAMA'''

    ma = TA.KAMA(ohlc, period=30)
    talib_ma = talib.KAMA(ohlc['close'], timeperiod=30)

    # assert round(talib_ma[-1], 5) == round(ma.values[-1], 5)
    # assert 1519.60321 == 1524.26954
    pass  # close enough 
Example #9
Source File: talib_wrapper.py    From tia with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def KAMA(series, n=30):
    """Kaufman Adaptive Moving Average"""
    return _series_to_series(series, talib.KAMA, n) 
Example #10
Source File: talib_indicators.py    From qtpylib with Apache License 2.0 5 votes vote down vote up
def KAMA(data, **kwargs):
    _check_talib_presence()
    prices = _extract_series(data)
    return talib.KAMA(prices, **kwargs)