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


Python talib.ROCR属性代码示例

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


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

示例1: rocr

# 需要导入模块: import talib [as 别名]
# 或者: from talib import ROCR [as 别名]
def rocr(candles: np.ndarray, period=10, source_type="close", sequential=False) -> Union[float, np.ndarray]:
    """
    ROCR - Rate of change ratio: (price/prevPrice)

    :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.ROCR(source, timeperiod=period)

    if sequential:
        return res
    else:
        return None if np.isnan(res[-1]) else res[-1] 
开发者ID:jesse-ai,项目名称:jesse,代码行数:23,代码来源:rocr.py

示例2: rebalance

# 需要导入模块: import talib [as 别名]
# 或者: from talib import ROCR [as 别名]
def rebalance(self, obs):
        """
        Performs portfolio rebalance within environment
        :param obs: pandas DataFrame: Environment observation
        :return: numpy array: Portfolio vector
        """
        if not self.init:
            n_pairs = obs.columns.levels[0].shape[0]
            action = np.ones(n_pairs)
            action[-1] = 0
            self.crp = array_normalize(action)
            self.init = True

        if self.step:
            x = self.predict(obs)
            price_relative = obs.xs('open', level=1, axis=1).apply(lambda x: ta.ROCR(x, timeperiod=1),
                                                                   raw=True).fillna(1.0)
            cov_mat = price_relative.cov()
            return self.update(cov_mat, x)
        else:
            return self.crp 
开发者ID:naripok,项目名称:cryptotrader,代码行数:23,代码来源:apriori.py

示例3: get_indicator

# 需要导入模块: import talib [as 别名]
# 或者: from talib import ROCR [as 别名]
def get_indicator(df, indicator):
        ret_df = df
        if 'MACD' in indicator:
            macd, macdsignal, macdhist = ta.MACD(df.close.values, fastperiod=12, slowperiod=26, signalperiod=9)
            ret_df = KlineData._merge_dataframe(pd.DataFrame([macd, macdsignal, macdhist]).T.rename(columns={0: "macddif", 1: "macddem", 2: "macdhist"}), ret_df)
            ret_df = KlineData._merge_dataframe(line_intersections(ret_df, columns=['macddif', 'macddem']), ret_df)
        if 'MFI' in indicator:
            real = ta.MFI(df.high.values, df.low.values, df.close.values, df.volume.values, timeperiod=14)
            ret_df = KlineData._merge_dataframe(pd.DataFrame([real]).T.rename(columns={0: "mfi"}), ret_df)
        if 'ATR' in indicator:
            real = ta.NATR(df.high.values, df.low.values, df.close.values, timeperiod=14)
            ret_df = KlineData._merge_dataframe(pd.DataFrame([real]).T.rename(columns={0: "atr"}), ret_df)
        if 'ROCR' in indicator:
            real = ta.ROCR(df.close.values, timeperiod=10)
            ret_df = KlineData._merge_dataframe(pd.DataFrame([real]).T.rename(columns={0: "rocr"}), ret_df)
        ret_df['date'] = pd.to_datetime(ret_df['date'], format='%Y-%m-%d')
        return ret_df 
开发者ID:tenstone,项目名称:klineyes,代码行数:19,代码来源:kline_data.py

示例4: price_relative

# 需要导入模块: import talib [as 别名]
# 或者: from talib import ROCR [as 别名]
def price_relative(obs, period=1):
    prices = obs.xs('open', level=1, axis=1).astype(np.float64)
    price_relative = prices.apply(ta.ROCR, timeperiod=period, raw=True).fillna(1.0)
    return price_relative 
开发者ID:naripok,项目名称:cryptotrader,代码行数:6,代码来源:apriori.py

示例5: add_ROCR

# 需要导入模块: import talib [as 别名]
# 或者: from talib import ROCR [as 别名]
def add_ROCR(self, timeperiod=10,
             type='line', color='tertiary', **kwargs):
    """Rate of Change (Ratio)."""

    if not self.has_close:
        raise Exception()

    utils.kwargs_check(kwargs, VALID_TA_KWARGS)
    if 'kind' in kwargs:
        type = kwargs['kind']

    name = 'ROCR({})'.format(str(timeperiod))
    self.sec[name] = dict(type=type, color=color)
    self.ind[name] = talib.ROCR(self.df[self.cl].values,
                                timeperiod) 
开发者ID:plotly,项目名称:dash-technical-charting,代码行数:17,代码来源:ta.py

示例6: ROCR

# 需要导入模块: import talib [as 别名]
# 或者: from talib import ROCR [as 别名]
def ROCR(data, **kwargs):
    _check_talib_presence()
    prices = _extract_series(data)
    return talib.ROCR(prices, **kwargs) 
开发者ID:ranaroussi,项目名称:qtpylib,代码行数:6,代码来源:talib_indicators.py


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