本文整理匯總了Python中talib.MOM屬性的典型用法代碼示例。如果您正苦於以下問題:Python talib.MOM屬性的具體用法?Python talib.MOM怎麽用?Python talib.MOM使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類talib
的用法示例。
在下文中一共展示了talib.MOM屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: acosc
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def acosc(candles: np.ndarray, sequential=False) -> AC:
"""
Acceleration / Deceleration Oscillator (AC)
:param candles: np.ndarray
:param sequential: bool - default=False
:return: AC(osc, change)
"""
if not sequential and len(candles) > 240:
candles = candles[-240:]
med = talib.MEDPRICE(candles[:, 3], candles[:, 4])
ao = talib.SMA(med, 5) - talib.SMA(med, 34)
res = ao - talib.SMA(ao, 5)
mom = talib.MOM(res, timeperiod=1)
if sequential:
return AC(res, mom)
else:
return AC(res[-1], mom[-1])
示例2: ao
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def ao(candles: np.ndarray, sequential=False) -> AO:
"""
Awesome Oscillator
:param candles: np.ndarray
:param sequential: bool - default=False
:return: AO(osc, change)
"""
if not sequential and len(candles) > 240:
candles = candles[-240:]
med = talib.MEDPRICE(candles[:, 3], candles[:, 4])
res = talib.SMA(med, 5) - talib.SMA(med, 34)
mom = talib.MOM(res, timeperiod=1)
if sequential:
return AO(res, mom)
else:
return AO(res[-1], mom[-1])
示例3: tsi
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def tsi(candles: np.ndarray, long_period=25, short_period=13, source_type="close", sequential=False) -> Union[
float, np.ndarray]:
"""
True strength index (TSI)
:param candles: np.ndarray
:param long_period: int - default: 25
:param short_period: int - default: 13
: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)
r = 100 * (talib.EMA((talib.EMA(talib.MOM(source, 1), long_period)), short_period)) / (
talib.EMA((talib.EMA(np.absolute(talib.MOM(source, 1)), long_period)), short_period))
return r if sequential else r[-1]
示例4: mom
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def mom(candles: np.ndarray, period=10, source_type="close", sequential=False) -> Union[float, np.ndarray]:
"""
MOM - Momentum
:param candles: np.ndarray
:param period: int - default=10
: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.MOM(source, timeperiod=period)
if sequential:
return res
else:
return None if np.isnan(res[-1]) else res[-1]
示例5: momentum
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def momentum(obs, period=14):
prices = obs.xs('open', level=1, axis=1).astype(np.float64)
# mean_volume = obs.xs('volume', level=1, axis=1).astype(np.float64).apply(lambda x: safe_div(x[-period:-1].sum(),
# x[-int(2 * period):-period].sum()), raw=True)
mom = prices.apply(ta.MOM, timeperiod=period, raw=True).fillna(0.0)
return 1 + safe_div(mom, prices.iloc[-period])# * mean_volume
示例6: mom
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def mom(self, sym, frequency, period=5):
if not self.kbars_ready(sym, frequency):
return []
closes = self.close(sym, frequency)
mom = ta.MOM(closes, timeperiod=period)
return mom
示例7: test_indicator_MOM
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def test_indicator_MOM(self):
n = 3
price = 'Close'
result = MOM(df, n)
isinstance(result, pd.DataFrame)
expected = talib.MOM(df[price].values, timeperiod=n)
np.testing.assert_almost_equal(result.values, expected)
示例8: add_MOM
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def add_MOM(self, timeperiod=10,
type='line', color='secondary', **kwargs):
"""Momentum Indicator."""
if not self.has_close:
raise Exception()
utils.kwargs_check(kwargs, VALID_TA_KWARGS)
if 'kind' in kwargs:
type = kwargs['kind']
name = 'MOM({})'.format(str(timeperiod))
self.sec[name] = dict(type=type, color=color)
self.ind[name] = talib.MOM(self.df[self.cl].values,
timeperiod)
示例9: gatorosc
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def gatorosc(candles: np.ndarray, source_type="close", sequential=False) -> GATOR:
"""
Gator Oscillator by Bill M. Williams
:param candles: np.ndarray
:param source_type: str - default: "close"
:param sequential: bool - default=False
:return: GATOR(upper, lower, upper_change, lower_change)
"""
if not sequential and len(candles) > 240:
candles = candles[-240:]
source = get_candle_source(candles, source_type=source_type)
jaw = shift(numpy_ewma(source, 13), 8)
teeth = shift(numpy_ewma(source, 8), 5)
lips = shift(numpy_ewma(source, 5), 3)
upper = np.abs(jaw - teeth)
lower = -np.abs(teeth - lips)
upper_change = talib.MOM(upper, timeperiod=1)
lower_change = -talib.MOM(lower, timeperiod=1)
if sequential:
return GATOR(upper, lower, upper_change, lower_change)
else:
return GATOR(upper[-1], lower[-1], upper_change[-1], lower_change[-1])
# preallocate empty array and assign slice by chrisaycock
示例10: test_mom
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def test_mom():
'''test TA.MOM'''
mom = TA.MOM(ohlc, 15)
talib_mom = talib.MOM(ohlc['close'], 15)
assert round(talib_mom[-1], 5) == round(mom.values[-1], 5)
示例11: MOM
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def MOM(series, n=10):
return _series_to_series(series, talib.MOM, n)
示例12: test_mom
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def test_mom(self):
result = pandas_ta.mom(self.close)
self.assertIsInstance(result, Series)
self.assertEqual(result.name, 'MOM_10')
try:
expected = tal.MOM(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)
示例13: MOM
# 需要導入模塊: import talib [as 別名]
# 或者: from talib import MOM [as 別名]
def MOM(data, **kwargs):
_check_talib_presence()
prices = _extract_series(data)
return talib.MOM(prices, **kwargs)