當前位置: 首頁>>代碼示例>>Python>>正文


Python talib.TRANGE屬性代碼示例

本文整理匯總了Python中talib.TRANGE屬性的典型用法代碼示例。如果您正苦於以下問題:Python talib.TRANGE屬性的具體用法?Python talib.TRANGE怎麽用?Python talib.TRANGE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在talib的用法示例。


在下文中一共展示了talib.TRANGE屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: trange

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import TRANGE [as 別名]
def trange(candles: np.ndarray, sequential=False) -> Union[float, np.ndarray]:
    """
    TRANGE - True Range

    :param candles: np.ndarray
    :param sequential: bool - default=False

    :return: float | np.ndarray
    """
    if not sequential and len(candles) > 240:
        candles = candles[-240:]

    res = talib.TRANGE(candles[:, 3], candles[:, 4], candles[:, 2])

    if sequential:
        return res
    else:
        return None if np.isnan(res[-1]) else res[-1] 
開發者ID:jesse-ai,項目名稱:jesse,代碼行數:20,代碼來源:trange.py

示例2: test_tr

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import TRANGE [as 別名]
def test_tr():
    '''test TA.TR'''

    tr = TA.TR(ohlc)
    talib_tr = talib.TRANGE(ohlc['high'], ohlc['low'], ohlc['close'])

    assert round(talib_tr[-1], 5) == round(tr.values[-1], 5) 
開發者ID:peerchemist,項目名稱:finta,代碼行數:9,代碼來源:test_reg.py

示例3: TRANGE

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import TRANGE [as 別名]
def TRANGE(frame, high_col='high', low_col='low', close_col='close'):
    return _frame_to_series(frame, [high_col, low_col, close_col], talib.TRANGE) 
開發者ID:bpsmith,項目名稱:tia,代碼行數:4,代碼來源:talib_wrapper.py

示例4: test_true_range

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import TRANGE [as 別名]
def test_true_range(self):
        result = pandas_ta.true_range(self.high, self.low, self.close)
        self.assertIsInstance(result, Series)
        self.assertEqual(result.name, 'TRUERANGE_1')

        try:
            expected = tal.TRANGE(self.high, self.low, 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) 
開發者ID:twopirllc,項目名稱:pandas-ta,代碼行數:16,代碼來源:test_indicator_volatility.py

示例5: TRANGE

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import TRANGE [as 別名]
def TRANGE(data, **kwargs):
    _check_talib_presence()
    _, phigh, plow, pclose, _ = _extract_ohlc(data)
    return talib.TRANGE(phigh, plow, pclose, **kwargs)


# ---------------------------------------------
# Parrern Recognition
# --------------------------------------------- 
開發者ID:ranaroussi,項目名稱:qtpylib,代碼行數:11,代碼來源:talib_indicators.py

示例6: ADX_MA

# 需要導入模塊: import talib [as 別名]
# 或者: from talib import TRANGE [as 別名]
def ADX_MA(data, period=14, smooth=14, limit=18):
    """
    Moving Average ADX
    ADX Smoothing Trend Color Change on Moving Average and ADX Cross. Use on Hourly Charts - Green UpTrend - Red DownTrend - Black Choppy No Trend

    Source: https://www.tradingview.com/script/owwws7dM-Moving-Average-ADX/
    Translator: 阿財(Rgveda@github)(4910163#qq.com)

    Parameters
    ----------
    data : (N,) array_like
        傳入 OHLC Kline 序列。
        The OHLC Kline.
    period : int or None, optional
        DI 統計周期 默認值為 14
        DI Length period. Default value is 10. 
    smooth : int or None, optional
        ADX 平滑周期 默認值為 14
        ADX smoothing length period. Default value is 10.
    limit : int or None, optional
        ADX 限製閾值 默認值為 18
        ADX MA Active limit threshold. Default value is 18.

    Returns
    -------
    adx, ADXm : ndarray
        ADXm 指標和趨勢指示方向 (-1, 0, 1) 分別代表 (下跌, 無明顯趨勢, 上漲)
        ADXm indicator and thread directions sequence. (-1, 0, 1) means for (Neagtive, No Trend, Positive)

    """
    up = data.high.pct_change()
    down = data.low.pct_change() * -1

    trur = TA_HMA(talib.TRANGE(data.high.values, data.low.values, data.close.values) , period)
    plus = 100 * TA_HMA(np.where(((up > down) & (up > 0)), up, 0), period) / trur
    minus = 100 * TA_HMA(np.where(((down > up) & (down > 0)), down, 0), period) / trur

    # 這裏是dropna的替代解決辦法,因為我覺得nparray的傳遞方式如果隨便drop了可能會跟 data.index
    # 對不上,所以我選擇補零替代dropna
    plus = np.r_[np.zeros(period + 2), plus[(period + 2):]]
    minus = np.r_[np.zeros(period + 2), minus[(period + 2):]]
    sum = plus + minus 
    adx = 100 * TA_HMA(abs(plus - minus) / (np.where((sum == 0), 1, sum)), smooth)
    adx = np.r_[np.zeros(smooth + 2), adx[(smooth + 2):]]
    ADXm = np.where(((adx > limit) & (plus > minus)), 1, np.where(((adx > limit) & (plus < minus)), -1, 0))
    return adx, ADXm 
開發者ID:QUANTAXIS,項目名稱:QUANTAXIS,代碼行數:48,代碼來源:talib_numpy.py


注:本文中的talib.TRANGE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。