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))
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))
def commodity_channel_index(high_arr, low_arr, close_arr, n): """Calculate Commodity Channel 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 :return: Commodity Channel Index in cudf.Series """ PP = average_price(high_arr.to_gpu_array(), low_arr.to_gpu_array(), close_arr.to_gpu_array()) M = Rolling(n, PP).mean() N = Rolling(n, PP).std() CCI = division(substract(PP, M), N) return cudf.Series(CCI, nan_as_null=False)
def money_flow_index(high_arr, low_arr, close_arr, volume_arr, n): """Calculate Money Flow Index and Ratio 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 n: time steps :return: Money Flow Index in cudf.Series """ PP = average_price(high_arr.to_gpu_array(), low_arr.to_gpu_array(), close_arr.to_gpu_array()) PosMF = money_flow(PP, volume_arr.to_gpu_array()) MFR = division(PosMF, (multiply(PP, volume_arr.to_gpu_array()))) # TotMF MFI = Rolling(n, MFR).mean() return cudf.Series(MFI, nan_as_null=False)
def port_commodity_channel_index(asset_indicator, high_arr, low_arr, close_arr, n): """Calculate port Commodity Channel 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 :return: Commodity Channel Index in cudf.Series """ PP = average_price(high_arr.to_gpu_array(), low_arr.to_gpu_array(), close_arr.to_gpu_array()) M = Rolling(n, PP).mean() port_mask_nan(asset_indicator.to_gpu_array(), M, 0, n - 1) N = Rolling(n, PP).std() port_mask_nan(asset_indicator.to_gpu_array(), N, 0, n - 1) CCI = division(substract(PP, M), N) return cudf.Series(CCI, nan_as_null=False)
def port_money_flow_index(asset_indicator, high_arr, low_arr, close_arr, volume_arr, n): """Calculate port Money Flow Index and Ratio 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 volume_arr: volume the bar, expect series from cudf :param n: time steps :return: Money Flow Index in cudf.Series """ PP = average_price(high_arr.to_gpu_array(), low_arr.to_gpu_array(), close_arr.to_gpu_array()) PosMF = port_money_flow(asset_indicator.to_gpu_array(), PP, volume_arr.to_gpu_array()) MFR = division(PosMF, (multiply(PP, volume_arr.to_gpu_array()))) # TotMF MFI = Rolling(n, MFR).mean() port_mask_nan(asset_indicator.to_gpu_array(), MFI, 0, n - 1) return cudf.Series(MFI, nan_as_null=False)