Exemplo n.º 1
0
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
Exemplo n.º 2
0
def port_vortex_indicator(asset_indicator, high_arr, low_arr, close_arr, n):
    """Calculate the port Vortex Indicator for given data.
    Vortex Indicator described here:

        http://www.vortexindicator.com/VFX_VORTEX.PDF

    :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
    :return:  Vortex Indicator in cudf.Series
    """
    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())

    VM = port_lowhigh_diff(asset_indicator.to_gpu_array(),
                           high_arr.data.to_gpu_array(),
                           low_arr.data.to_gpu_array())

    VI = division(Rolling(n, VM).sum(), Rolling(n, TR).sum())
    port_mask_nan(asset_indicator.data.to_gpu_array(), VI, 0, n - 1)
    return cudf.Series(VI)
Exemplo n.º 3
0
def port_average_true_range(asset_indicator, high_arr, low_arr, close_arr, n):
    """Calculate the port Average True Range
    See https://www.investopedia.com/terms/a/atr.asp for details
    :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
    :return: average true range indicator
    """
    tr = port_true_range(asset_indicator.to_gpu_array(),
                         high_arr.to_gpu_array(), low_arr.to_gpu_array(),
                         close_arr.to_gpu_array())
    ATR = PEwm(n, tr, asset_indicator).mean()
    return cudf.Series(ATR, nan_as_null=False)