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


Python talib.BBANDS属性代码示例

本文整理汇总了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 
开发者ID:moyuanz,项目名称:DevilYuan,代码行数:24,代码来源:DyStockDataUtility.py

示例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 
开发者ID:bbfamily,项目名称:abu,代码行数:22,代码来源:ABuNDBoll.py

示例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 
开发者ID:moyuanz,项目名称:DevilYuan,代码行数:24,代码来源:DySS_BBands.py

示例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] 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:23,代码来源:talib_numpy.py

示例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) 
开发者ID:epolestar,项目名称:equant,代码行数:22,代码来源:boll.py

示例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 
开发者ID:myquant,项目名称:strategy,代码行数:12,代码来源:ta_indicator_mixin.py

示例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])


    # ---------------------------------------------------------------------- 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:31,代码来源:ctaLineBar.py

示例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] 
开发者ID:mcardillo55,项目名称:cbpro-trader,代码行数:13,代码来源:IndicatorSubsystem.py

示例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) 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:6,代码来源:talib_series.py

示例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) 
开发者ID:edouardpoitras,项目名称:NowTrade,代码行数:5,代码来源:technical_indicator.py

示例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 
开发者ID:edouardpoitras,项目名称:NowTrade,代码行数:16,代码来源:technical_indicator.py

示例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 
开发者ID:jiewwantan,项目名称:StarTrader,代码行数:42,代码来源:data_preprocessing.py

示例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) 
开发者ID:plotly,项目名称:dash-technical-charting,代码行数:42,代码来源:ta.py

示例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) 
开发者ID:noda-sin,项目名称:ebisu,代码行数:4,代码来源:__init__.py

示例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]) 
开发者ID:jesse-ai,项目名称:jesse,代码行数:28,代码来源:bollinger_bands.py


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