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