本文整理匯總了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]
示例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
示例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
示例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
示例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)
示例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)