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