Python talib.MOM Examples
The following are 13
code examples of talib.MOM().
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: ao.py From jesse with MIT License | 7 votes |
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])
Example #2
Source File: acosc.py From jesse with MIT License | 6 votes |
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])
Example #3
Source File: tsi.py From jesse with MIT License | 6 votes |
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]
Example #4
Source File: mom.py From jesse with MIT License | 6 votes |
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]
Example #5
Source File: apriori.py From cryptotrader with MIT License | 5 votes |
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
Example #6
Source File: ta_indicator_mixin.py From strategy with Apache License 2.0 | 5 votes |
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
Example #7
Source File: test_pandas_talib.py From pandas_talib with MIT License | 5 votes |
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)
Example #8
Source File: ta.py From dash-technical-charting with MIT License | 5 votes |
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)
Example #9
Source File: gatorosc.py From jesse with MIT License | 5 votes |
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
Example #10
Source File: test_reg.py From finta with GNU Lesser General Public License v3.0 | 5 votes |
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)
Example #11
Source File: talib_wrapper.py From tia with BSD 3-Clause "New" or "Revised" License | 5 votes |
def MOM(series, n=10): return _series_to_series(series, talib.MOM, n)
Example #12
Source File: test_indicator_momentum.py From pandas-ta with MIT License | 5 votes |
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)
Example #13
Source File: talib_indicators.py From qtpylib with Apache License 2.0 | 5 votes |
def MOM(data, **kwargs): _check_talib_presence() prices = _extract_series(data) return talib.MOM(prices, **kwargs)