コード例 #1
0
ファイル: indicator.py プロジェクト: zxlwrz/gQuant
def port_average_directional_movement_index(asset_indicator, high_arr, low_arr,
                                            close_arr, n, n_ADX):
    """Calculate the port Average Directional Movement Index for given data.

    :param asset_indicator: the indicator of beginning of the stock
    :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.data.to_gpu_array(),
                          low_arr.data.to_gpu_array())
    tr = port_true_range(asset_indicator.to_gpu_array(),
                         high_arr.data.to_gpu_array(),
                         low_arr.data.to_gpu_array(),
                         close_arr.data.to_gpu_array())
    ATR = PEwm(n, tr, asset_indicator).mean()
    PosDI = division(PEwm(n, UpI, asset_indicator).mean(), ATR)
    NegDI = division(PEwm(n, DoI, asset_indicator).mean(), ATR)
    NORM = division(abs_arr(substract(PosDI, NegDI)), summation(PosDI, NegDI))
    port_mask_nan(asset_indicator.data.to_gpu_array(), NORM, -1, 0)
    ADX = cudf.Series(PEwm(n_ADX, NORM, asset_indicator).mean())
    return ADX
コード例 #2
0
ファイル: indicator.py プロジェクト: zfy1989lee/gQuant
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)
コード例 #3
0
def port_relative_strength_index(asset_indicator, 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.data.to_gpu_array(),
                          low_arr.data.to_gpu_array())
    UpI_s = shift(UpI, 1)
    UpI_s[0] = 0
    UpI_s = cudf.Series(UpI_s) * (1.0 - asset_indicator)
    DoI_s = shift(DoI, 1)
    DoI_s[0] = 0
    DoI_s = cudf.Series(DoI_s) * (1.0 - asset_indicator)
    PosDI = PEwm(n, UpI_s, asset_indicator).mean()
    NegDI = PEwm(n, DoI_s, asset_indicator).mean()
    RSI = division(PosDI, summation(PosDI, NegDI))
    return cudf.Series(RSI)
コード例 #4
0
ファイル: indicator.py プロジェクト: zfy1989lee/gQuant
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