本文整理匯總了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)