コード例 #1
0
def adosc(high,
          low,
          close,
          volume,
          open_=None,
          fast=None,
          slow=None,
          talib=None,
          offset=None,
          **kwargs):
    """Indicator: Accumulation/Distribution Oscillator"""
    # Validate Arguments
    fast = int(fast) if fast and fast > 0 else 3
    slow = int(slow) if slow and slow > 0 else 10
    _length = max(fast, slow)
    high = verify_series(high, _length)
    low = verify_series(low, _length)
    close = verify_series(close, _length)
    volume = verify_series(volume, _length)
    offset = get_offset(offset)
    if "length" in kwargs: kwargs.pop("length")
    mode_tal = bool(talib) if isinstance(talib, bool) else True

    if high is None or low is None or close is None or volume is None: return

    # Calculate Result
    if Imports["talib"] and mode_tal:
        from talib import ADOSC
        adosc = ADOSC(high, low, close, volume, fast, slow)
    else:
        ad_ = ad(high=high, low=low, close=close, volume=volume, open_=open_)
        fast_ad = ema(close=ad_, length=fast, **kwargs)
        slow_ad = ema(close=ad_, length=slow, **kwargs)
        adosc = fast_ad - slow_ad

    # Offset
    if offset != 0:
        adosc = adosc.shift(offset)

    # Handle fills
    if "fillna" in kwargs:
        adosc.fillna(kwargs["fillna"], inplace=True)
    if "fill_method" in kwargs:
        adosc.fillna(method=kwargs["fill_method"], inplace=True)

    # Name and Categorize it
    adosc.name = f"ADOSC_{fast}_{slow}"
    adosc.category = "volume"

    return adosc
コード例 #2
0
def adosc_talib(my_close, my_high, my_low, my_volume, fastperiod, slowperiod):

    x = ADOSC(my_high.values,
              my_low.values,
              my_close.values,
              my_volume.values,
              fastperiod=fastperiod,
              slowperiod=slowperiod)
    return x
コード例 #3
0
def getTechnicalInd(data, window=10):
    close = data['Close']
    high = data['High']
    low = data['Low']
    volume = data['Volume']
    #madev = roc = willr=rsi=apo=atr=obv=adosc=slowk=fastk=slowd=fastd=vpos=vneg={}
    window = 10
    for i in range(0, window):

        # momentum indicators
        # rate of change: (price/prevPrice - 1)*100
        data["roc{0}".format(i)] = ROC(close.shift(i), timeperiod=10)
        # williams oscillator
        data["willr{0}".format(i)] = WILLR(high.shift(i),
                                           low.shift(i),
                                           close.shift(i),
                                           timeperiod=14)

        # relative strength index
        data["rsi{0}".format(i)] = RSI(close.shift(i), timeperiod=14)

        # absolute price oscillator: slowMA(price) - fastMA(price)
        data["apo{0}".format(i)] = APO(close.shift(i),
                                       fastperiod=12,
                                       slowperiod=26,
                                       matype=0)
        # volatility indicator

        data["atr{0}".format(i)] = ATR(high.shift(i),
                                       low.shift(i),
                                       close.shift(i),
                                       timeperiod=14)  # average true range
        # Volume indicator
        # on balance volume
        data["obv{0}".format(i)] = OBV(close.shift(i), volume.shift(i))
        # chaikin A/D oscillator
        data["adosc{0}".format(i)] = ADOSC(high.shift(i),
                                           low.shift(i),
                                           close.shift(i),
                                           volume.shift(i),
                                           fastperiod=3,
                                           slowperiod=10)

        # Stochastic Oscillator Slow %k: (C-L)/(H-L)*100
        data["slowk{0}".format(i)], data["slowd{0}".format(i)] = STOCH(
            high.shift(i),
            low.shift(i),
            close.shift(i),
            fastk_period=5,
            slowk_period=3,
            slowk_matype=0,
            slowd_period=3,
            slowd_matype=0)

        # STOCHF - Stochastic Fast
        data["fastk{0}".format(i)], data["fastd{0}".format(i)] = STOCHF(
            high.shift(i),
            low.shift(i),
            close.shift(i),
            fastk_period=5,
            fastd_period=3,
            fastd_matype=0)

        #vortex
        data["vortex_indicator_pos{0}".format(i)] = vortex_indicator_pos(
            high.shift(i), low.shift(i), close.shift(i), n=14, fillna=False)
        data["vortex_indicator_neg{0}".format(i)] = vortex_indicator_neg(
            high.shift(i), low.shift(i), close.shift(i), n=14, fillna=False)

        # returns
    for i in range(1, window):
        # overlap studies
        data["madev{0}".format(i)] = close - close.shift(1).rolling(
            window=i).mean()
        data["return{0}".format(i)] = close - close.shift(i)
    # std
    for i in range(2, window):
        data["std{0}".format(i)] = close.rolling(
            i).std()  #Standard deviation for a period of 5 days

    return data  #madev, roc,willr,rsi,apo,atr,obv,adosc,slowk,slowd,fastk,fastd,vpos, vneg, returns, stds
コード例 #4
0
def setvolume(open, high, low, close, volume):
    #volume
    df["obv"] = OBV(close, volume)
    #df["ad"] = AD(high, low, close, volume)
    df["ad"] = ADOSC(high, low, close, volume, fastperiod=3, slowperiod=10)
コード例 #5
0
corrected_data=corrected_data[['Open','High','Low','Close','Volume']]
corrected_data=corrected_data[~((corrected_data['High']==0) |
               (corrected_data['Open']==0)  |
                (corrected_data['Close']==0) |
                (corrected_data['Low']==0) |
                (corrected_data['Volume']==0))]
print(corrected_data.shape)

print('<<< Extract Technical Indicators....')  
corrected_data['SMA_10']=corrected_data['Close'].rolling(window=10).mean()
corrected_data['WMA_10']=WMA(corrected_data['Close'], timeperiod=10)
corrected_data['rsi']=RSI(corrected_data['Close'], timeperiod=10)
corrected_data['stoc_k'], corrected_data['stoc_d'] = STOCH(corrected_data['High'],corrected_data['Low'],corrected_data['Close'],10,6,0,6)
corrected_data['mom']=MOM(corrected_data['Close'], timeperiod=10)
corrected_data['macd'],_,_=MACD(corrected_data['Close'], fastperiod=12, slowperiod=26, signalperiod=10)
corrected_data['adosc']=ADOSC(corrected_data['High'], corrected_data['Low'], corrected_data['Close'], corrected_data['Volume'], fastperiod=3, slowperiod=10)
corrected_data['cci']=CCI(corrected_data['High'], corrected_data['Low'], corrected_data['Close'],timeperiod=10)
corrected_data['willr']=WILLR(corrected_data['High'], corrected_data['Low'], corrected_data['Close'],timeperiod=10)
null_value_checks(corrected_data)
corrected_data=corrected_data[~corrected_data['macd'].isnull()]
null_value_checks(corrected_data)
corrected_data_ta=corrected_data

print('<<< Completed extraction. Reading Forex Data....')  
exchange_rate=pd.read_csv('./Data/GBP_USD.csv')
print(exchange_rate.head(2))
exchange_rate['Match_Date']=pd.to_datetime(exchange_rate['Date'],format='%b %d, %Y')
print('Shape of Exchange Rate: ', exchange_rate.shape)
null_value_checks(exchange_rate)
exchange_rate=exchange_rate[::-1]
コード例 #6
0
                                  slowperiod=26,
                                  signalperiod=9)
# print('-----------------------------------MACD-----------------------------------')
# print(macd[34:37])
# print(macdsignal[34:37])
# print(macdhist[34:37])
#
rsi = RSI(fechamento, timeperiod=14)
# print('-----------------------------------RSI-----------------------------------')
# print(rsi[34:37])
# Momentum Indicators # Volume Indicators
mfi = MFI(maximo, minimo, fechamento, volume, timeperiod=14)
# print('-----------------------------------MFI-----------------------------------')
# print(mfi[34:37])

#Volume Indicators
ad = AD(maximo, minimo, fechamento, volume)
adosc = ADOSC(maximo, minimo, fechamento, volume, fastperiod=3, slowperiod=10)
obv = OBV(fechamento, volume)

# dataFrameConcatened = pd.concat(fechamento, rsi)
dataFrameConcatened = np.concatenate((abertura, rsi), axis=0)
print(dataFrameConcatened)

ax = plt.gca()
# brsr6CSV.plot(kind='line',x='DATA',y='ABERTURA',ax=ax)
brsr6CSV.plot(kind='line', x='DATA', y='FECHAMENTO', color='red', ax=ax)
plt.plot(upBR, label='BB UP')
plt.plot(lowBR, label='BB Low')
plt.show()