Example #1
0
def trix(close_arr, n):
    """Calculate TRIX for given data.

    :param close_arr: close price of the bar, expect series from cudf
    :param n: time steps
    :return: trix indicator in cudf.Series
    """
    EX1 = Ewm(n, close_arr).mean()
    EX2 = Ewm(n, EX1).mean()
    EX3 = Ewm(n, EX2).mean()
    return rate_of_change(cudf.Series(EX3), 2)
Example #2
0
def chaikin_oscillator(high_arr, low_arr, close_arr, volume_arr, n1, n2):
    """Calculate Chaikin Oscillator for given data.

    :param high_arr: high price of the bar, expect series from cudf
    :param low_arr: low price of the bar, expect series from cudf
    :param close_arr: close price of the bar, expect series from cudf
    :param volume_arr: volume the bar, expect series from cudf
    :param n1: n1 time steps
    :param n2: n2 time steps
    :return: Chaikin Oscillator indicator in cudf.Series
    """
    ad = (2.0 * close_arr - high_arr - low_arr) / (high_arr -
                                                   low_arr) * volume_arr
    Chaikin = cudf.Series(Ewm(n1, ad).mean()) - cudf.Series(Ewm(n2, ad).mean())
    return Chaikin
Example #3
0
def mass_index(high_arr, low_arr, n1, n2):
    """Calculate the Mass Index for given data.

    :param high_arr: high price of the bar, expect series from cudf
    :param low_arr: low price of the bar, expect series from cudf
    :param n1: n1 time steps
    :param n1: n2 time steps
    :return: Mass Index in cudf.Series
    """
    Range = high_arr - low_arr
    EX1 = Ewm(n1, Range).mean()
    EX2 = Ewm(n1, EX1).mean()
    Mass = division(EX1, EX2)
    MassI = Rolling(n2, Mass).sum()
    return cudf.Series(MassI)
Example #4
0
def true_strength_index(close_arr, r, s):
    """Calculate True Strength Index (TSI) for given data.

    :param close_arr: close price of the bar, expect series from cudf
    :param r: r time steps
    :param s: s time steps
    :return: True Strength Index in cudf.Series
    """
    M = diff(close_arr, 1)
    aM = abs_arr(M)
    EMA1 = Ewm(r, M).mean()
    aEMA1 = Ewm(r, aM).mean()
    EMA2 = Ewm(s, EMA1).mean()
    aEMA2 = Ewm(s, aEMA1).mean()
    TSI = division(EMA2, aEMA2)
    return cudf.Series(TSI)
Example #5
0
def relative_strength_index(high_arr, low_arr, n):
    """Calculate Relative Strength Index(RSI) for given data.

    :param high_arr: high price of the bar, expect series from cudf
    :param low_arr: low price of the bar, expect series from cudf
    :param n: time steps to do EWM average
    :return: Relative Strength Index in cudf.Series
    """
    UpI, DoI = upDownMove(high_arr.to_gpu_array(), low_arr.to_gpu_array())
    UpI_s = shift(UpI, 1)
    UpI_s[0] = 0
    DoI_s = shift(DoI, 1)
    DoI_s[0] = 0
    PosDI = Ewm(n, UpI_s).mean()
    NegDI = Ewm(n, DoI_s).mean()
    RSI = division(PosDI, summation(PosDI, NegDI))
    return cudf.Series(RSI, nan_as_null=False)
Example #6
0
def exponential_moving_average(close_arr, n):
    """Calculate the exponential weighted moving average for the given data.

    :param close_arr: close price of the bar, expect series from cudf
    :param n: time steps
    :return: expoential weighted moving average in cu.Series
    """
    EMA = Ewm(n, close_arr).mean()
    return cudf.Series(EMA)
Example #7
0
def macd(close_arr, n_fast, n_slow):
    """Calculate MACD, MACD Signal and MACD difference

    :param close_arr: close price of the bar, expect series from cudf
    :param n_fast: fast time steps
    :param n_slow: slow time steps
    :return: MACD MACDsign MACDdiff
    """
    EMAfast = Ewm(n_fast, close_arr).mean()
    EMAslow = Ewm(n_slow, close_arr).mean()
    MACD = substract(EMAfast, EMAslow)
    average_window = 9
    MACDsign = Ewm(average_window, MACD).mean()
    MACDdiff = substract(MACD, MACDsign)
    out = collections.namedtuple('MACD', 'MACD MACDsign MACDdiff')
    return out(MACD=cudf.Series(MACD),
               MACDsign=cudf.Series(MACDsign),
               MACDdiff=cudf.Series(MACDdiff))
Example #8
0
def stochastic_oscillator_d(high_arr, low_arr, close_arr, n):
    """Calculate stochastic oscillator D for given data.

    :param high_arr: high price of the bar, expect series from cudf
    :param low_arr: low price of the bar, expect series from cudf
    :param close_arr: close price of the bar, expect series from cudf
    :param n: time steps
    :return: stochastic oscillator D in cudf.Series
    """
    SOk = stochastic_oscillator_k(high_arr, low_arr, close_arr)
    SOd = Ewm(n, SOk).mean()
    return cudf.Series(SOd)
Example #9
0
def average_directional_movement_index(high_arr, low_arr, close_arr, n, n_ADX):
    """Calculate the Average Directional Movement Index for given data.

    :param high_arr: high price of the bar, expect series from cudf
    :param low_arr: low price of the bar, expect series from cudf
    :param close_arr: close price of the bar, expect series from cudf
    :param n: time steps to do EWM average
    :param n_ADX: time steps to do EWM average of ADX
    :return: Average Directional Movement Index in cudf.Series
    """
    UpI, DoI = upDownMove(high_arr.to_gpu_array(), low_arr.to_gpu_array())
    last_ele = len(high_arr) - 1
    tr = true_range(high_arr.to_gpu_array(), low_arr.to_gpu_array(),
                    close_arr.to_gpu_array())
    ATR = Ewm(n, tr).mean()
    PosDI = division(Ewm(n, UpI).mean(), ATR)
    NegDI = division(Ewm(n, DoI).mean(), ATR)
    NORM = division(abs_arr(substract(PosDI, NegDI)), summation(PosDI, NegDI))
    NORM[last_ele] = math.nan
    ADX = cudf.Series(Ewm(n_ADX, NORM).mean(), nan_as_null=False)
    return ADX
Example #10
0
def average_true_range(high_arr, low_arr, close_arr, n):
    """Calculate the Average True Range
    See https://www.investopedia.com/terms/a/atr.asp for details

    :param high_arr: high price of the bar, expect series from cudf
    :param low_arr: low price of the bar, expect series from cudf
    :param close_arr: close price of the bar, expect series from cudf
    :param n: time steps
    :return: average true range indicator
    """
    tr = true_range(high_arr.data.to_gpu_array(), low_arr.data.to_gpu_array(),
                    close_arr.data.to_gpu_array())
    ATR = Ewm(n, tr).mean()
    return cudf.Series(ATR)
Example #11
0
def coppock_curve(close_arr, n):
    """Calculate Coppock Curve for given data.

    :param close_arr: close price of the bar, expect series from cudf
    :param n: time steps
    :return: Coppock Curve in cudf.Series
    """
    M = diff(close_arr, int(n * 11 / 10) - 1)
    N = shift(close_arr, int(n * 11 / 10) - 1)
    ROC1 = division(M, N)
    M = diff(close_arr, int(n * 14 / 10) - 1)
    N = shift(close_arr, int(n * 14 / 10) - 1)
    ROC2 = division(M, N)
    Copp = Ewm(n, summation(ROC1, ROC2)).mean()
    return cudf.Series(Copp)