本文整理汇总了Python中talib.RSI属性的典型用法代码示例。如果您正苦于以下问题:Python talib.RSI属性的具体用法?Python talib.RSI怎么用?Python talib.RSI使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类talib
的用法示例。
在下文中一共展示了talib.RSI属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: onInit
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def onInit(self):
"""初始化策略(必须由用户继承实现)"""
self.writeCtaLog(u'%s策略初始化' %self.name)
# 初始化RSI入场阈值
self.rsiBuy = 50 + self.rsiEntry
self.rsiSell = 50 - self.rsiEntry
# 载入历史数据,并采用回放计算的方式初始化策略数值
initData = self.loadBar(self.initDays)
for bar in initData:
self.onBar(bar)
self.putEvent()
#----------------------------------------------------------------------
示例2: rsi
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def rsi(candles: np.ndarray, period=14, source_type="close", sequential=False) -> Union[float, np.ndarray]:
"""
RSI - Relative Strength Index
:param candles: np.ndarray
:param period: int - default: 14
: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)
r = talib.RSI(source, timeperiod=period)
return r if sequential else r[-1]
示例3: TA_MACD
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def TA_MACD(prices:np.ndarray,
fastperiod:int=12,
slowperiod:int=26,
signalperiod:int=9) -> np.ndarray:
'''
参数设置:
fastperiod = 12
slowperiod = 26
signalperiod = 9
返回: macd - dif, signal - dea, hist * 2 - bar, delta
'''
macd, signal, hist = talib.MACD(prices,
fastperiod=fastperiod,
slowperiod=slowperiod,
signalperiod=signalperiod)
hist = (macd - signal) * 2
delta = np.r_[np.nan, np.diff(hist)]
return np.c_[macd, signal, hist, delta]
# 定义RSI函数
示例4: isBuy
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def isBuy(context, analysis):
# Bullish SMA Crossover
if (getLast(analysis, 'sma_test') == 1):
# Bullish MACD
if (getLast(analysis, 'macd_test') == 1):
return True
# # Bullish Stochastics
# if(getLast(analysis, 'stoch_over_sold') == 1):
# return True
# # Bullish RSI
# if(getLast(analysis, 'rsi_over_sold') == 1):
# return True
return False
示例5: isSell
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def isSell(context, analysis):
# Bearish SMA Crossover
if (getLast(analysis, 'sma_test') == 0):
# Bearish MACD
if (getLast(analysis, 'macd_test') == 0):
return True
# # Bearish Stochastics
# if(getLast(analysis, 'stoch_over_bought') == 0):
# return True
# # Bearish RSI
# if(getLast(analysis, 'rsi_over_bought') == 0):
# return True
return False
示例6: annotate_data
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def annotate_data(self, feed, timeframe):
# Get SMAs
for k, v in six.iteritems(self.sma_intervals):
feed[k] = talib.SMA(feed['closeMid'].values, v)
# Get MACD
# NOTE: talib.MACD() returns (macd, signal, hist)
feed['macd'], _, feed['macd_hist'] = talib.MACD(
feed['closeMid'].values,
fastperiod=12,
slowperiod=26,
signalperiod=9
)
# Get RSI
feed['rsi'] = talib.RSI(feed['closeMid'].values)
return feed
示例7: TA_RSI
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def TA_RSI(prices:np.ndarray,
timeperiod:int=12) -> np.ndarray:
'''
参数设置:
timeperiod = 12
返回: ma
'''
rsi = talib.RSI(prices, timeperiod=timeperiod)
delta = np.r_[np.nan, np.diff(rsi)]
return np.c_[rsi, delta]
# 定义RSI函数
示例8: rsi
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def rsi(self, sym, frequency, *args, **kwargs):
if not self.kbars_ready(sym, frequency):
return []
highs = self.high(sym, frequency)
lows = self.low(sym, frequency)
closes = self.close(sym, frequency)
avg_prices = (highs + lows + closes) / 3.0
return ta.RSI(avg_prices, *args, **kwargs)
示例9: __str__
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def __str__(self):
return 'RSI(data=%s, period=%s)' %(self.data, self.period)
示例10: results
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def results(self, data_frame):
try:
data_frame[self.value] = talib.RSI(data_frame[self.data].values, timeperiod=self.period)
except KeyError:
data_frame[self.value] = np.nan
示例11: technical_indicators_df
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def technical_indicators_df(self, daily_data):
"""
Assemble a dataframe of technical indicator series for a single stock
"""
o = daily_data['Open'].values
c = daily_data['Close'].values
h = daily_data['High'].values
l = daily_data['Low'].values
v = daily_data['Volume'].astype(float).values
# define the technical analysis matrix
# Most data series are normalized by their series' mean
ta = pd.DataFrame()
ta['MA5'] = tb.MA(c, timeperiod=5) / tb.MA(c, timeperiod=5).mean()
ta['MA10'] = tb.MA(c, timeperiod=10) / tb.MA(c, timeperiod=10).mean()
ta['MA20'] = tb.MA(c, timeperiod=20) / tb.MA(c, timeperiod=20).mean()
ta['MA60'] = tb.MA(c, timeperiod=60) / tb.MA(c, timeperiod=60).mean()
ta['MA120'] = tb.MA(c, timeperiod=120) / tb.MA(c, timeperiod=120).mean()
ta['MA5'] = tb.MA(v, timeperiod=5) / tb.MA(v, timeperiod=5).mean()
ta['MA10'] = tb.MA(v, timeperiod=10) / tb.MA(v, timeperiod=10).mean()
ta['MA20'] = tb.MA(v, timeperiod=20) / tb.MA(v, timeperiod=20).mean()
ta['ADX'] = tb.ADX(h, l, c, timeperiod=14) / tb.ADX(h, l, c, timeperiod=14).mean()
ta['ADXR'] = tb.ADXR(h, l, c, timeperiod=14) / tb.ADXR(h, l, c, timeperiod=14).mean()
ta['MACD'] = tb.MACD(c, fastperiod=12, slowperiod=26, signalperiod=9)[0] / \
tb.MACD(c, fastperiod=12, slowperiod=26, signalperiod=9)[0].mean()
ta['RSI'] = tb.RSI(c, timeperiod=14) / tb.RSI(c, timeperiod=14).mean()
ta['BBANDS_U'] = tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[0] / \
tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[0].mean()
ta['BBANDS_M'] = tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[1] / \
tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[1].mean()
ta['BBANDS_L'] = tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[2] / \
tb.BBANDS(c, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)[2].mean()
ta['AD'] = tb.AD(h, l, c, v) / tb.AD(h, l, c, v).mean()
ta['ATR'] = tb.ATR(h, l, c, timeperiod=14) / tb.ATR(h, l, c, timeperiod=14).mean()
ta['HT_DC'] = tb.HT_DCPERIOD(c) / tb.HT_DCPERIOD(c).mean()
ta["High/Open"] = h / o
ta["Low/Open"] = l / o
ta["Close/Open"] = c / o
self.ta = ta
示例12: add_RSI
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def add_RSI(self, timeperiod=14,
type='line', color='secondary', **kwargs):
"""Relative Strength Index."""
if not self.has_close:
raise Exception()
utils.kwargs_check(kwargs, VALID_TA_KWARGS)
if 'kind' in kwargs:
type = kwargs['kind']
name = 'RSI({})'.format(str(timeperiod))
self.sec[name] = dict(type=type, color=color)
self.ind[name] = talib.RSI(self.df[self.cl].values,
timeperiod)
示例13: calculate_cmi_indicator
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def calculate_cmi_indicator(df): # RSI
cmi_period = 30
cmi_ma_period = 10
roc = df['close'].diff(cmi_period)
h1 = ta.MAX(df['high'], cmi_period) - ta.MIN(df['low'], cmi_period)
cmi = abs(roc / h1) * 100
cmi_ma = ta.MA(cmi, cmi_ma_period) # rolling.
return cmi_ma
示例14: rsi
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def rsi(self, n, array=False):
"""
Relative Strenght Index (RSI).
"""
result = talib.RSI(self.close, n)
if array:
return result
return result[-1]
示例15: rsi
# 需要导入模块: import talib [as 别名]
# 或者: from talib import RSI [as 别名]
def rsi(close, period=14):
return talib.RSI(close, period)