本文整理汇总了Python中talib.BBANDS属性的典型用法代码示例。如果您正苦于以下问题:Python talib.BBANDS属性的具体用法?Python talib.BBANDS怎么用?Python talib.BBANDS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类talib
的用法示例。
在下文中一共展示了talib.BBANDS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getBBands
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def getBBands(df, period=10, stdNbr=2):
try:
close = df['close']
except Exception as ex:
return None
try:
upper, middle, lower = talib.BBANDS(
close.values,
timeperiod=period,
# number of non-biased standard deviations from the mean
nbdevup=stdNbr,
nbdevdn=stdNbr,
# Moving average type: simple moving average here
matype=0)
except Exception as ex:
return None
data = dict(upper=upper, middle=middle, lower=lower)
df = pd.DataFrame(data, index=df.index, columns=['upper', 'middle', 'lower']).dropna()
return df
示例2: _calc_boll_from_ta
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def _calc_boll_from_ta(prices, time_period=20, nb_dev=2):
"""
使用talib计算boll, 即透传talib.BBANDS计算结果
:param prices: 收盘价格序列,pd.Series或者np.array
:param time_period: boll的N值默认值20,int
:param nb_dev: boll的nb_dev值默认值2,int
:return: tuple(upper, middle, lower)
"""
import talib
if isinstance(prices, pd.Series):
prices = prices.values
upper, middle, lower = talib.BBANDS(
prices,
timeperiod=time_period,
nbdevup=nb_dev,
nbdevdn=nb_dev,
matype=0)
return upper, middle, lower
示例3: _bbands
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def _bbands(self, df):
try:
close = df['close']
except Exception as ex:
return None, None, None
if close.shape[0] != self._forwardNDays:
return None, None, None
try:
upper, middle, lower = talib.BBANDS(
close.values,
timeperiod=self._forwardNDays,
# number of non-biased standard deviations from the mean
nbdevup=1,
nbdevdn=1,
# Moving average type: simple moving average here
matype=0)
except Exception as ex:
return None, None, None
return upper, middle, lower
示例4: TA_BBANDS
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def TA_BBANDS(prices:np.ndarray,
timeperiod:int=5,
nbdevup:int=2,
nbdevdn:int=2,
matype:int=0) -> np.ndarray:
'''
参数设置:
timeperiod = 5
nbdevup = 2
nbdevdn = 2
返回: up, middle, low
'''
up, middle, low = talib.BBANDS(prices,
timeperiod,
nbdevup,
nbdevdn,
matype)
ch = (up - low) / middle
delta = np.r_[np.nan, np.diff(ch)]
return np.c_[up, middle, low, ch, delta]
示例5: handle_data
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def handle_data(context):
# 等待数据就绪,否则计算果结为异常值
if len(Close()) < p:
return
# 计算布林带高中低点
upp, mid, low = talib.BBANDS(Close(), p, 2, 2)
# 低买高卖
if MarketPosition() != 1 and Open()[-1] < low[-1]:
Buy(qty, Open()[-1])
elif MarketPosition() != -1 and Open()[-1] > upp[-1]:
SellShort(qty, Open()[-1])
# 绘制布林带曲线
PlotNumeric('upp', upp[-1], RGB_Red())
PlotNumeric('mid', mid[-1], RGB_Blue())
PlotNumeric('low', low[-1], RGB_Green())
# 绘制盈亏曲线
PlotNumeric("profit", NetProfit() + FloatProfit() - TradeCost(), 0xFF00FF, False)
示例6: boll
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def boll(self, sym, frequency, period=5, nbdev_up=2, nbdev_down=2, ma_type=0):
if not self.kbars_ready(sym, frequency):
return [],[],[]
closes = self.close(sym, frequency)
upperband, middleband, lowerband = ta.BBANDS(closes, timeperiod=period,
nbdevup=nbdev_up, nbdevdn=nbdev_down, matype=ma_type)
return upperband, middleband, lowerband
示例7: __recountBoll
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def __recountBoll(self):
"""布林特线"""
if self.inputBollLen < EMPTY_INT: return
l = len(self.lineBar)
if l < min(7, self.inputBollLen)+1:
self.debugCtaLog(u'数据未充分,当前Bar数据数量:{0},计算Boll需要:{1}'.
format(len(self.lineBar), min(7, self.inputBollLen)+1))
return
if l < self.inputBollLen+2:
bollLen = l-1
else:
bollLen = self.inputBollLen
# 不包含当前最新的Bar
listClose=[x.close for x in self.lineBar[-bollLen - 1:-1]]
#
upper, middle, lower = ta.BBANDS(numpy.array(listClose, dtype=float),
timeperiod=bollLen, nbdevup=self.inputBollStdRate,
nbdevdn=self.inputBollStdRate, matype=0)
self.lineUpperBand.append(upper[-1])
self.lineMiddleBand.append(middle[-1])
self.lineLowerBand.append(lower[-1])
# ----------------------------------------------------------------------
示例8: calculate_bbands
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def calculate_bbands(self, period_name, close):
timeperiod = 20
upperband_1, middleband_1, lowerband_1 = talib.BBANDS(close, timeperiod=timeperiod, nbdevup=1, nbdevdn=1, matype=0)
self.current_indicators[period_name]['bband_upper_1'] = upperband_1[-1]
self.current_indicators[period_name]['bband_lower_1'] = lowerband_1[-1]
upperband_2, middleband_2, lowerband_2 = talib.BBANDS(close, timeperiod=timeperiod, nbdevup=2, nbdevdn=2, matype=0)
self.current_indicators[period_name]['bband_upper_2'] = upperband_2[-1]
self.current_indicators[period_name]['bband_lower_2'] = lowerband_2[-1]
示例9: BBANDS
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def BBANDS(Series, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0):
up, middle, low = talib.BBANDS(
Series.values, timeperiod, nbdevup, nbdevdn, matype)
return pd.Series(up, index=Series.index), pd.Series(middle, index=Series.index), pd.Series(low, index=Series.index)
示例10: __str__
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def __str__(self):
return 'BBANDS(data=%s, period=%s, devup=%s, devdown=%s, ma_type=%s)' \
%(self.data, self.period, self.devup, self.devdown, self.ma_type)
示例11: results
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def results(self, data_frame):
try:
upper, middle, lower = talib.BBANDS(data_frame[self.data].values,
self.period,
self.devup,
self.devdown,
matype=self.ma_type)
data_frame[self.upper] = upper
data_frame[self.middle] = middle
data_frame[self.lower] = lower
except KeyError:
data_frame[self.upper] = np.nan
data_frame[self.middle] = np.nan
data_frame[self.lower] = np.nan
示例12: technical_indicators_df
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [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
示例13: add_BBANDS
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def add_BBANDS(self, timeperiod=20, nbdevup=2, nbdevdn=2, matype=0,
types=['line_dashed_thin', 'line_dashed_thin'],
colors=['tertiary', 'grey_strong'], **kwargs):
"""Bollinger Bands.
Note that the first argument of types and colors refers to upper and lower
bands while second argument refers to middle band. (Upper and lower are
symmetrical arguments, hence only 2 needed.)
"""
if not self.has_close:
raise Exception()
utils.kwargs_check(kwargs, VALID_TA_KWARGS)
if 'kind' in kwargs:
kwargs['type'] = kwargs['kind']
if 'kinds' in kwargs:
types = kwargs['type']
if 'type' in kwargs:
types = [kwargs['type']] * 2
if 'color' in kwargs:
colors = [kwargs['color']] * 2
name = 'BBANDS({},{},{})'.format(str(timeperiod),
str(nbdevup),
str(nbdevdn))
ubb = name + '[Upper]'
bb = name
lbb = name + '[Lower]'
self.pri[ubb] = dict(type='line_' + types[0][5:],
color=colors[0])
self.pri[bb] = dict(type='area_' + types[1][5:],
color=colors[1], fillcolor='fill')
self.pri[lbb] = dict(type='area_' + types[0][5:],
color=colors[0], fillcolor='fill')
(self.ind[ubb],
self.ind[bb],
self.ind[lbb]) = talib.BBANDS(self.df[self.cl].values,
timeperiod, nbdevup, nbdevdn, matype)
示例14: bbands
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def bbands(source, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0):
return talib.BBANDS(source, timeperiod, nbdevup, nbdevdn, matype)
示例15: bollinger_bands
# 需要导入模块: import talib [as 别名]
# 或者: from talib import BBANDS [as 别名]
def bollinger_bands(candles: np.ndarray, period=20, devup=2, devdn=2, matype=0, source_type="close",
sequential=False) -> BollingerBands:
"""
BBANDS - Bollinger Bands
:param candles: np.ndarray
:param period: int - default: 20
:param devup: float - default: 2
:param devdn: float - default: 2
:param matype: int - default: 0
:param source_type: str - default: "close"
:param sequential: bool - default=False
:return: BollingerBands(upperband, middleband, lowerband)
"""
if not sequential and len(candles) > 240:
candles = candles[-240:]
source = get_candle_source(candles, source_type=source_type)
upperbands, middlebands, lowerbands = talib.BBANDS(source, timeperiod=period, nbdevup=devup, nbdevdn=devdn,
matype=matype)
if sequential:
return BollingerBands(upperbands, middlebands, lowerbands)
else:
return BollingerBands(upperbands[-1], middlebands[-1], lowerbands[-1])