当前位置: 首页>>代码示例>>Python>>正文


Python talib.EMA属性代码示例

本文整理汇总了Python中talib.EMA属性的典型用法代码示例。如果您正苦于以下问题:Python talib.EMA属性的具体用法?Python talib.EMA怎么用?Python talib.EMA使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在talib的用法示例。


在下文中一共展示了talib.EMA属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ema

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def ema(dataframe, period, field='close'):
    import talib.abstract as ta
    return ta.EMA(dataframe, timeperiod=period, price=field)


# HT_TRENDLINE         Hilbert Transform - Instantaneous Trendline
# KAMA                 Kaufman Adaptive Moving Average
# MA                   Moving average
# MAMA                 MESA Adaptive Moving Average
# MAVP                 Moving average with variable period
# MIDPOINT             MidPoint over period
# MIDPRICE             Midpoint Price over period
# SAR                  Parabolic SAR
# SAREXT               Parabolic SAR - Extended

# SMA                  Simple Moving Average 
开发者ID:freqtrade,项目名称:technical,代码行数:18,代码来源:indicators.py

示例2: _getAtrExtreme

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def _getAtrExtreme(cls, highs, lows, closes, atrPeriod=14, slowPeriod=30, fastPeriod=3):
        """
            获取TTI ATR Exterme通道, which is based on 《Volatility-Based Technical Analysis》
            TTI is 'Trading The Invisible'

            @return: fasts, slows
        """
        # talib 的源码,它的 ATR 不是 N 日简单平均,而是类似 EMA 的方法计算的指数平均
        atr = talib.ATR(highs, lows, closes, timeperiod=atrPeriod)

        highsMean = talib.EMA(highs, 5)
        lowsMean = talib.EMA(lows, 5)
        closesMean = talib.EMA(closes, 5)

        atrExtremes = np.where(closes > closesMean,
                               ((highs - highsMean)/closes * 100) * (atr/closes * 100),
                               ((lows - lowsMean)/closes * 100) * (atr/closes * 100)
                               )

        fasts = talib.MA(atrExtremes, fastPeriod)
        slows = talib.EMA(atrExtremes, slowPeriod)

        return fasts, slows, np.std(atrExtremes[-slowPeriod:]) 
开发者ID:moyuanz,项目名称:DevilYuan,代码行数:25,代码来源:DyST_IntraDayT.py

示例3: stc

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def stc(dataframe, fast=23, slow=50, length=10):

    # First, the 23-period and the 50-period EMA and the MACD values are calculated:
    # EMA1 = EMA (Close, Short Length);
    # EMA2 = EMA (Close, Long Length);
    # MACD = EMA1 – EMA2.
    # Second, the 10-period Stochastic from the MACD values is calculated:
    # %K (MACD) = %KV (MACD, 10);
    # %D (MACD) = %DV (MACD, 10);
    # Schaff = 100 x (MACD – %K (MACD)) / (%D (MACD) – %K (MACD))

    import talib.abstract as ta

    MACD = ta.EMA(dataframe, timeperiod=fast) - ta.EMA(dataframe, timeperiod=slow)
    STOK = ((MACD - MACD.rolling(window=length).min()) / (
            MACD.rolling(window=length).max() - MACD.rolling(window=length).min())) * 100
    STOD = STOK.rolling(window=length).mean()
    dataframe['stc'] = 100 * (MACD - (STOK * MACD)) / ((STOD * MACD) - (STOK * MACD))

    return dataframe['stc'] 
开发者ID:freqtrade,项目名称:technical,代码行数:22,代码来源:indicators.py

示例4: momentum

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def momentum(dataframe, field='close', period=9):
    from pyti.momentum import momentum as m
    return m(dataframe[field], period)


# PLUS_DI              Plus Directional Indicator
# PLUS_DM              Plus Directional Movement
# PPO                  Percentage Price Oscillator
# ROC                  Rate of change : ((price/prevPrice)-1)*100
# ROCP                 Rate of change Percentage: (price-prevPrice)/prevPrice
# ROCR                 Rate of change ratio: (price/prevPrice)
# ROCR100              Rate of change ratio 100 scale: (price/prevPrice)*100
# RSI                  Relative Strength Index
# STOCH                Stochastic
# STOCHF               Stochastic Fast
# STOCHRSI             Stochastic Relative Strength Index
# TRIX                 1-day Rate-Of-Change (ROC) of a Triple Smooth EMA

# ULTOSC               Ultimate Oscillator 
开发者ID:freqtrade,项目名称:technical,代码行数:21,代码来源:indicators.py

示例5: vwmacd

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def vwmacd(candles: np.ndarray, fastperiod=12, slowperiod=26, signalperiod=9, sequential=False) -> VWMACD:
    """
    VWMACD - Volume Weighted Moving Average Convergence/Divergence

    :param candles: np.ndarray
    :param fastperiod: int - default: 12
    :param slow_period: int - default: 26
    :param signal_period: int - default: 9
    :param sequential: bool - default: False

    :return: VWMACD(macd, signal, hist)
    """
    if not sequential and len(candles) > 240:
        candles = candles[-240:]

    vwma_slow = talib.SMA(candles[:, 2] * candles[:, 5], slowperiod) / talib.SMA(candles[:, 5], slowperiod)
    vwma_fast = talib.SMA(candles[:, 2] * candles[:, 5], fastperiod) / talib.SMA(candles[:, 5], fastperiod)
    vwmacd = vwma_fast - vwma_slow
    signal = talib.EMA(vwmacd, signalperiod)
    hist = vwmacd - signal

    if sequential:
        return VWMACD(vwmacd, signal, hist)
    else:
        return VWMACD(vwmacd[-1], signal[-1], hist[-1]) 
开发者ID:jesse-ai,项目名称:jesse,代码行数:27,代码来源:vwmacd.py

示例6: ema

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def ema(candles: np.ndarray, period=5, source_type="close", sequential=False) -> Union[float, np.ndarray]:
    """
    EMA - Exponential Moving Average

    :param candles: np.ndarray
    :param period: int - default: 5
    :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.EMA(source, timeperiod=period)

    return res if sequential else res[-1] 
开发者ID:jesse-ai,项目名称:jesse,代码行数:20,代码来源:ema.py

示例7: tsi

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [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] 
开发者ID:jesse-ai,项目名称:jesse,代码行数:23,代码来源:tsi.py

示例8: _calc_ma_from_ta

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def _calc_ma_from_ta(prices, time_period=10, from_calc=EMACalcType.E_MA_MA):
    """
    使用talib计算ma,即透传talib.MA or talib.EMA计算结果
    :param prices: 收盘价格序列,pd.Series或者np.array
    :param time_period: 移动平均的N值,int
    :param from_calc: EMACalcType enum对象,移动移动平均使用的方法
    """

    import talib
    if isinstance(prices, pd.Series):
        prices = prices.values

    if from_calc == EMACalcType.E_MA_MA:
        ma = talib.MA(prices, timeperiod=time_period)
    else:
        ma = talib.EMA(prices, timeperiod=time_period)
    return ma 
开发者ID:bbfamily,项目名称:abu,代码行数:19,代码来源:ABuNDMa.py

示例9: EMA

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def EMA(self, period: int, bars: list):
        """
        Exponential moving average of previous n bars close price.

        EMA = price(t) * k + EMA(y) * ( 1 − k )

        where:
            t = today (current bar for any period)
            y = yesterday (previous bar close price)
            N = number of bars (period)
            k = 2 / (N + 1) (weight factor)
        """

        self.check_bars_type(bars)

        ema = ta.EMA(bars['close'], timeperiod=period)

        return ema 
开发者ID:s-brez,项目名称:trading-server,代码行数:20,代码来源:features.py

示例10: MACD

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def MACD(self, name,  bars: list):
        """
        Return MACD for given time series. Bars list must be 26 bars
        in length (last 26 bars for period).

        MACD = EMA(12) - EMA(26)

        Note we only use the MACD, not signal or histogram.
        """

        self.check_bars_type(bars)

        macd, signal, hist = ta.MACD(
            bars['close'], fastperiod=12, slowperiod=26, signalperiod=9)

        return macd 
开发者ID:s-brez,项目名称:trading-server,代码行数:18,代码来源:features.py

示例11: getRuntimeEma

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def getRuntimeEma(self, ema_num):
        """
        实时计算EMA得值
        :param ema_num:第几条均线, 1,对应inputEma1Len,,,,
        :return:
        """
        if ema_num not in [1, 2, 3]:
            return None

        ema_len = 1
        if ema_num == 1 and self.inputEma1Len > 0:
            ema_len = self.inputEma1Len
        elif ema_num == 2 and self.inputEma2Len > 0:
            ema_len = self.inputEma2Len
        elif ema_num == 3 and self.inputEma3Len > 0:
            ema_len = self.inputEma3Len
        else:
            return None

        ema_data_len = min(ema_len*2, ema_len + 20)
        # 1、lineBar满足长度才执行计算
        if len(self.lineBar) < ema_data_len:
            self.debugCtaLog(u'数据未充分,当前Bar数据数量:{0},计算实时EMA需要:{1}'.
                             format(len(self.lineBar), ema_data_len))
            return

        listClose = [x.close for x in self.lineBar[-ema_data_len - 1:]]
        rtEma = ta.EMA(np.array(listClose, dtype=float), ema_len)[-1]
        rtEma = round(float(rtEma), self.round_n)
        return rtEma 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:32,代码来源:ctaLineBar.py

示例12: __recountYB

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def __recountYB(self):
        """某种趋势线"""

        if not self.inputYb:
            return

        if self.inputYbLen <1:
            return

        if self.inputYbRef < 1:
            self.debugCtaLog(u'参数 self.inputYbRef:{}不能低于1'.format(self.inputYbRef))
            return

        # 1、lineBar满足长度才执行计算
        if len(self.lineBar) < 4 * self.inputYbLen:
            self.debugCtaLog(u'数据未充分,当前Bar数据数量:{0},计算YB 需要:{1}'.
                             format(len(self.lineBar), 4 * self.inputYbLen))
            return

        emaLen = self.inputYbLen
        # 3、获取前InputN周期(不包含当前周期)的K线
        if self.mode == self.TICK_MODE:
            list_mid3 = [x.mid3 for x in self.lineBar[-emaLen*4 - 1:-1]]
        else:
            list_mid3 = [x.mid3 for x in self.lineBar[-emaLen*4:]]
        bar_mid3_ema10 = ta.EMA(np.array(list_mid3, dtype=float), emaLen)[-1]
        bar_mid3_ema10 = round(float(bar_mid3_ema10), self.round_n)

        if len(self.lineYb) > emaLen*4:
            del self.lineYb[0]

        self.lineYb.append(bar_mid3_ema10)

        if len(self.lineYb) < self.inputYbRef + 1:
            return

        if self.lineYb[-1] > self.lineYb[-1 - self.inputYbRef]:
            self.yb_count = self.yb_count + 1 if self.yb_count >= 0 else 1
        else:
            self.yb_count = self.yb_count - 1 if self.yb_count <= 0 else -1 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:42,代码来源:ctaLineBar.py

示例13: getRuningYb

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def getRuningYb(self):
        """
        获取未完结的bar计算出来的YB值
        :return: None,空值;float,计算值
        """
        if not self.inputYb :
            return None
        if self.inputYbLen < 1:
            return None
        if self.inputYbRef < 1:
            self.debugCtaLog(u'参数 self.inputYbRef:{}不能低于1'.format(self.inputYbRef))
            return None

        # 1、lineBar满足长度才执行计算
        if len(self.lineBar) < 4 * self.inputYbLen:
            self.debugCtaLog(u'数据未充分,当前Bar数据数量:{0},计算YB 需要:{1}'.
                             format(len(self.lineBar), 4 * self.inputYbLen))
            return None

        emaLen = self.inputYbLen
        # 3、获取前InputN周期(包含当前周期)的K线
        list_mid3 = [x.mid3 for x in self.lineBar[-emaLen*4:-1]]
        last_bar_mid3 = (self.lineBar[-1].close + self.lineBar[-1].high + self.lineBar[-1].low)/3
        list_mid3.append(last_bar_mid3)
        bar_mid3_ema10 = ta.EMA(np.array(list_mid3, dtype=float), emaLen)[-1]
        bar_mid3_ema10 = round(float(bar_mid3_ema10), self.round_n)
        return bar_mid3_ema10
    # ---------------------------------------------------------------------- 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:30,代码来源:ctaLineBar.py

示例14: calculate_obv

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def calculate_obv(self, period_name, closing_prices, volumes):
        obv = talib.OBV(closing_prices, volumes)
        obv_ema = talib.EMA(obv, timeperiod=3)

        self.current_indicators[period_name]['obv_ema'] = obv_ema[-1]
        self.current_indicators[period_name]['obv'] = obv[-1] 
开发者ID:mcardillo55,项目名称:cbpro-trader,代码行数:8,代码来源:IndicatorSubsystem.py

示例15: Volume_HMA

# 需要导入模块: import talib [as 别名]
# 或者: from talib import EMA [as 别名]
def Volume_HMA(klines, period=5):
    """
    交易量加权船型移动平均线 HMA,方向指示性类似于 Moving Average ADX,但它们通过不同的指标实现。
    Hull Moving Average with Volume weighted, diretions similar like ADX_MA

    Source: https://www.tradingview.com/script/XTViDINu-VHMA/
    Translator: 阿财(Rgveda@github)(4910163#qq.com)

    Parameters
    ----------
    klines : (N,) array_like
        传入 OHLC Kline 序列。
        The OHLC Kline.
    period : int or None, optional
        DI 统计周期 默认值为 10
        DI Length period. Default value is 10. 

    Returns
    -------
    vhma, Trend : ndarray
        vhma 指标和 Trend 趋势指示方向 (-1/-2, 0, 1/2) 分别代表 (下跌, 无明显趋势, 上涨)
        the vhma indicator and thread directions sequence. (-1/-2, 0, 1/2) means for (Neagtive, No Trend, Positive)

    """
    src1 = talib.EMA(klines.close * klines.volume, period) / talib.EMA(klines.volume, period)
    vhma = TA_HMA(src1, period)
    vhma_s = pd.Series(vhma)

    lineDirection = np.where((vhma > vhma_s.shift(1).values), 1, -1)
    hu = np.where((vhma > vhma_s.shift(2).values), 1, -1)
    return vhma, lineDirection + hu 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:33,代码来源:talib_numpy.py


注:本文中的talib.EMA属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。