當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。