本文整理汇总了Python中talib.KAMA属性的典型用法代码示例。如果您正苦于以下问题:Python talib.KAMA属性的具体用法?Python talib.KAMA怎么用?Python talib.KAMA使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类talib
的用法示例。
在下文中一共展示了talib.KAMA属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getKamas
# 需要导入模块: import talib [as 别名]
# 或者: from talib import KAMA [as 别名]
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
示例2: kama
# 需要导入模块: import talib [as 别名]
# 或者: from talib import KAMA [as 别名]
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]
示例3: TA_KAMA
# 需要导入模块: import talib [as 别名]
# 或者: from talib import KAMA [as 别名]
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]
示例4: KAMA
# 需要导入模块: import talib [as 别名]
# 或者: from talib import KAMA [as 别名]
def KAMA(Series, timeperiod=30):
res = talib.KAMA(Series.values, timeperiod)
return pd.Series(res, index=Series.index)
示例5: KAMA
# 需要导入模块: import talib [as 别名]
# 或者: from talib import KAMA [as 别名]
def KAMA(data, **kwargs):
_check_talib_presence()
prices = _extract_series(data)
return talib.KAMA(prices, **kwargs)
示例6: predict
# 需要导入模块: import talib [as 别名]
# 或者: from talib import KAMA [as 别名]
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
示例7: add_KAMA
# 需要导入模块: import talib [as 别名]
# 或者: from talib import KAMA [as 别名]
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)
示例8: test_kama
# 需要导入模块: import talib [as 别名]
# 或者: from talib import KAMA [as 别名]
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
示例9: KAMA
# 需要导入模块: import talib [as 别名]
# 或者: from talib import KAMA [as 别名]
def KAMA(series, n=30):
"""Kaufman Adaptive Moving Average"""
return _series_to_series(series, talib.KAMA, n)