当前位置: 首页>>代码示例>>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;未经允许,请勿转载。