예제 #1
0
파일: indicator.py 프로젝트: zxlwrz/gQuant
def kst_oscillator(close_arr, r1, r2, r3, r4, n1, n2, n3, n4):
    """Calculate KST Oscillator for given data.

    :param close_arr: close price of the bar, expect series from cudf
    :param r1: r1 time steps
    :param r2: r2 time steps
    :param r3: r3 time steps
    :param r4: r4 time steps
    :param n1: n1 time steps
    :param n2: n2 time steps
    :param n3: n3 time steps
    :param n4: n4 time steps
    :return:  KST Oscillator in cudf.Series
    """
    M1 = diff(close_arr, r1 - 1)
    N1 = shift(close_arr, r1 - 1)
    M2 = diff(close_arr, r2 - 1)
    N2 = shift(close_arr, r2 - 1)
    M3 = diff(close_arr, r3 - 1)
    N3 = shift(close_arr, r3 - 1)
    M4 = diff(close_arr, r4 - 1)
    N4 = shift(close_arr, r4 - 1)
    term1 = Rolling(n1, division(M1, N1)).sum()
    term2 = scale(Rolling(n2, division(M2, N2)).sum(), 2.0)
    term3 = scale(Rolling(n3, division(M3, N3)).sum(), 3.0)
    term4 = scale(Rolling(n4, division(M4, N4)).sum(), 4.0)
    KST = summation(summation(summation(term1, term2), term3), term4)
    return cudf.Series(KST)
예제 #2
0
파일: indicator.py 프로젝트: zxlwrz/gQuant
def port_ppsr(asset_indicator, high_arr, low_arr, close_arr):
    """Calculate port Pivot Points, Supports and Resistances 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
    :return: PP R1 S1 R2 S2 R3 S3
    """
    high_gpu = high_arr.data.to_gpu_array()
    low_gpu = low_arr.data.to_gpu_array()
    close_gpu = close_arr.data.to_gpu_array()
    PP = average_price(high_gpu, low_gpu, close_gpu)
    R1 = substract(scale(PP, 2.0), low_gpu)
    S1 = substract(scale(PP, 2.0), high_gpu)
    R2 = substract(summation(PP, high_gpu), low_gpu)
    S2 = summation(substract(PP, high_gpu), low_gpu)
    R3 = summation(high_gpu, scale(substract(PP, low_gpu), 2.0))
    S3 = substract(low_gpu, scale(substract(high_gpu, PP), 2.0))
    out = collections.namedtuple('PPSR', 'PP R1 S1 R2 S2 R3 S3')
    return out(PP=cudf.Series(PP),
               R1=cudf.Series(R1),
               S1=cudf.Series(S1),
               R2=cudf.Series(R2),
               S2=cudf.Series(S2),
               R3=cudf.Series(R3),
               S3=cudf.Series(S3))
예제 #3
0
def ppsr(high_arr, low_arr, close_arr):
    """Calculate Pivot Points, Supports and Resistances 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
    :return: PP R1 S1 R2 S2 R3 S3
    """
    high_gpu = high_arr.to_gpu_array()
    low_gpu = low_arr.to_gpu_array()
    close_gpu = close_arr.to_gpu_array()
    PP = average_price(high_gpu, low_gpu, close_gpu)
    R1 = substract(scale(PP, 2.0), low_gpu)
    S1 = substract(scale(PP, 2.0), high_gpu)
    R2 = substract(summation(PP, high_gpu), low_gpu)
    S2 = summation(substract(PP, high_gpu), low_gpu)
    R3 = summation(high_gpu, scale(substract(PP, low_gpu), 2.0))
    S3 = substract(low_gpu, scale(substract(high_gpu, PP), 2.0))
    out = collections.namedtuple('PPSR', 'PP R1 S1 R2 S2 R3 S3')
    return out(PP=cudf.Series(PP, nan_as_null=False),
               R1=cudf.Series(R1, nan_as_null=False),
               S1=cudf.Series(S1, nan_as_null=False),
               R2=cudf.Series(R2, nan_as_null=False),
               S2=cudf.Series(S2, nan_as_null=False),
               R3=cudf.Series(R3, nan_as_null=False),
               S3=cudf.Series(S3, nan_as_null=False))
예제 #4
0
def ultimate_oscillator(high_arr, low_arr, close_arr):
    """Calculate Ultimate 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
    :return: Ultimate Oscillator in cudf.Series
    """
    TR_l, BP_l = ultimate_osc(high_arr.to_gpu_array(), low_arr.to_gpu_array(),
                              close_arr.to_gpu_array())
    term1 = division(scale(Rolling(7, BP_l).sum(), 4.0),
                     Rolling(7, TR_l).sum())
    term2 = division(scale(Rolling(14, BP_l).sum(), 2.0),
                     Rolling(14, TR_l).sum())
    term3 = division(Rolling(28, BP_l).sum(), Rolling(28, TR_l).sum())
    UltO = summation(summation(term1, term2), term3)
    return cudf.Series(UltO, nan_as_null=False)
예제 #5
0
파일: indicator.py 프로젝트: zxlwrz/gQuant
def bollinger_bands(close_arr, n):
    """Calculate the Bollinger Bands.
    See https://www.investopedia.com/terms/b/bollingerbands.asp for details

    :param close_arr: close price of the bar, expect series from cudf
    :param n: time steps
    :return: b1 b2
    """
    MA = Rolling(n, close_arr).mean()
    MSD = Rolling(n, close_arr).std()
    close_arr_gpu = numba.cuda.device_array_like(close_arr.data.to_gpu_array())
    close_arr_gpu[:] = close_arr.data.to_gpu_array()[:]
    close_arr_gpu[0:n - 1] = math.nan
    MSD_4 = scale(MSD, 4.0)
    b1 = division(MSD_4, MA)
    b2 = division(summation(substract(close_arr_gpu, MA), scale(MSD, 2.0)),
                  MSD_4)
    out = collections.namedtuple('Bollinger', 'b1 b2')
    return out(b1=cudf.Series(b1), b2=cudf.Series(b2))
예제 #6
0
파일: indicator.py 프로젝트: zxlwrz/gQuant
def port_kst_oscillator(asset_indicator, close_arr, r1, r2, r3, r4, n1, n2, n3,
                        n4):
    """Calculate port KST Oscillator for given data.

    :param asset_indicator: the indicator of beginning of the stock
    :param close_arr: close price of the bar, expect series from cudf
    :param r1: r1 time steps
    :param r2: r2 time steps
    :param r3: r3 time steps
    :param r4: r4 time steps
    :param n1: n1 time steps
    :param n2: n2 time steps
    :param n3: n3 time steps
    :param n4: n4 time steps
    :return:  KST Oscillator in cudf.Series
    """
    M1 = diff(close_arr, r1 - 1)
    N1 = shift(close_arr, r1 - 1)
    port_mask_nan(asset_indicator.data.to_gpu_array(), M1, 0, r1 - 1)
    port_mask_nan(asset_indicator.data.to_gpu_array(), N1, 0, r1 - 1)
    M2 = diff(close_arr, r2 - 1)
    N2 = shift(close_arr, r2 - 1)
    port_mask_nan(asset_indicator.data.to_gpu_array(), M2, 0, r2 - 1)
    port_mask_nan(asset_indicator.data.to_gpu_array(), N2, 0, r2 - 1)
    M3 = diff(close_arr, r3 - 1)
    N3 = shift(close_arr, r3 - 1)
    port_mask_nan(asset_indicator.data.to_gpu_array(), M3, 0, r3 - 1)
    port_mask_nan(asset_indicator.data.to_gpu_array(), N3, 0, r3 - 1)
    M4 = diff(close_arr, r4 - 1)
    N4 = shift(close_arr, r4 - 1)
    port_mask_nan(asset_indicator.data.to_gpu_array(), M4, 0, r4 - 1)
    port_mask_nan(asset_indicator.data.to_gpu_array(), N4, 0, r4 - 1)
    term1 = Rolling(n1, division(M1, N1)).sum()
    port_mask_nan(asset_indicator.data.to_gpu_array(), term1, 0, n1 - 1)
    term2 = scale(Rolling(n2, division(M2, N2)).sum(), 2.0)
    port_mask_nan(asset_indicator.data.to_gpu_array(), term2, 0, n2 - 1)
    term3 = scale(Rolling(n3, division(M3, N3)).sum(), 3.0)
    port_mask_nan(asset_indicator.data.to_gpu_array(), term3, 0, n3 - 1)
    term4 = scale(Rolling(n4, division(M4, N4)).sum(), 4.0)
    port_mask_nan(asset_indicator.data.to_gpu_array(), term4, 0, n4 - 1)
    KST = summation(summation(summation(term1, term2), term3), term4)
    return cudf.Series(KST)
예제 #7
0
파일: indicator.py 프로젝트: zxlwrz/gQuant
def port_ultimate_oscillator(asset_indicator, high_arr, low_arr, close_arr):
    """Calculate port Ultimate Oscillator 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
    :return: Ultimate Oscillator in cudf.Series
    """
    TR_l, BP_l = port_ultimate_osc(asset_indicator.data.to_gpu_array(),
                                   high_arr.data.to_gpu_array(),
                                   low_arr.data.to_gpu_array(),
                                   close_arr.data.to_gpu_array())
    term1 = division(scale(Rolling(7, BP_l).sum(), 4.0),
                     Rolling(7, TR_l).sum())
    term2 = division(scale(Rolling(14, BP_l).sum(), 2.0),
                     Rolling(14, TR_l).sum())
    term3 = division(Rolling(28, BP_l).sum(), Rolling(28, TR_l).sum())
    port_mask_nan(asset_indicator.data.to_gpu_array(), term1, 0, 6)
    port_mask_nan(asset_indicator.data.to_gpu_array(), term2, 0, 13)
    port_mask_nan(asset_indicator.data.to_gpu_array(), term3, 0, 27)
    UltO = summation(summation(term1, term2), term3)
    return cudf.Series(UltO)
예제 #8
0
def port_bollinger_bands(asset_indicator, close_arr, n):
    """Calculate the port Bollinger Bands.
    See https://www.investopedia.com/terms/b/bollingerbands.asp for details

    :param asset_indicator: the indicator of beginning of the stock
    :param close_arr: close price of the bar, expect series from cudf
    :param n: time steps
    :return: b1 b2
    """
    MA = Rolling(n, close_arr).mean()
    port_mask_nan(asset_indicator.to_gpu_array(), MA, 0, n - 1)
    MSD = Rolling(n, close_arr).std()
    port_mask_nan(asset_indicator.to_gpu_array(), MSD, 0, n - 1)
    close_arr_gpu = numba.cuda.device_array_like(close_arr.to_gpu_array())
    close_arr_gpu[:] = close_arr.to_gpu_array()[:]
    close_arr_gpu[0:n - 1] = math.nan
    MSD_4 = scale(MSD, 4.0)
    b1 = division(MSD_4, MA)
    b2 = division(summation(substract(close_arr_gpu, MA), scale(MSD, 2.0)),
                  MSD_4)
    out = collections.namedtuple('Bollinger', 'b1 b2')
    return out(b1=cudf.Series(b1, nan_as_null=False),
               b2=cudf.Series(b2, nan_as_null=False))
예제 #9
0
파일: indicator.py 프로젝트: zxlwrz/gQuant
def ease_of_movement(high_arr, low_arr, volume_arr, n):
    """Calculate Ease of Movement 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 volume_arr: volume the bar, expect series from cudf
    :param n: time steps
    :return: Ease of Movement in cudf.Series
    """
    high_arr_gpu = high_arr.data.to_gpu_array()
    low_arr_gpu = low_arr.data.to_gpu_array()

    EoM = division(
        multiply(summation(diff(high_arr_gpu, 1), diff(low_arr_gpu, 1)),
                 substract(high_arr_gpu, low_arr_gpu)),
        scale(volume_arr.data.to_gpu_array(), 2.0))
    Eom_ma = Rolling(n, EoM).mean()
    return cudf.Series(Eom_ma)
예제 #10
0
파일: indicator.py 프로젝트: zxlwrz/gQuant
def port_ease_of_movement(asset_indicator, high_arr, low_arr, volume_arr, n):
    """Calculate port Ease of Movement 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 volume_arr: volume the bar, expect series from cudf
    :param n: time steps
    :return: Ease of Movement in cudf.Series
    """
    high_arr_gpu = high_arr.data.to_gpu_array()
    low_arr_gpu = low_arr.data.to_gpu_array()

    EoM = division(
        multiply(summation(diff(high_arr_gpu, 1), diff(low_arr_gpu, 1)),
                 substract(high_arr_gpu, low_arr_gpu)),
        scale(volume_arr.data.to_gpu_array(), 2.0))
    port_mask_nan(asset_indicator.data.to_gpu_array(), EoM, 0, 1)
    Eom_ma = Rolling(n, EoM).mean()
    port_mask_nan(asset_indicator.data.to_gpu_array(), Eom_ma, 0, n - 1)
    return cudf.Series(Eom_ma)