def PRANGE(df, n, max_price='High', min_price='Low'): """ %Range """ max_list = jhta.MAX(df, n, max_price) min_list = jhta.MIN(df, n, min_price) prange_list = [] i = 0 while i < len(df[max_price]): if i + 1 < n: prange = float('NaN') else: prange = (max_list[i] - min_list[i]) / ( (max_list[i] + min_list[i]) / 2) * 100 prange_list.append(prange) i += 1 return prange_list
def PRANGE(df, n, max_price='High', min_price='Low'): """ %Range Returns: list of floats = jhta.PRANGE(df, n, max_price='High', min_price='Low') Source: book: An Introduction to Algorithmic Trading """ max_list = jhta.MAX(df, n, max_price) min_list = jhta.MIN(df, n, min_price) prange_list = [] for i in range(len(df[max_price])): if i + 1 < n: prange = float('NaN') else: prange = (max_list[i] - min_list[i]) / ( (max_list[i] + min_list[i]) / 2) * 100 prange_list.append(prange) return prange_list
def INFO(df, price='Close'): """ Print df Information """ print('{:_<28}:{:_>22}'.format('DF PRICE COLUMN', price)) print('{:_<28}:{:_>22d}'.format('LEN', len(df[price]))) print('{:_<28}:{:_>28.5f}'.format('MIN', jhta.MIN(df, len(df[price]), price)[-1])) print('{:_<28}:{:_>28.5f}'.format('MAX', jhta.MAX(df, len(df[price]), price)[-1])) print('{:_<28}:{:_>28.5f}'.format('SUM', jhta.SUM(df, len(df[price]), price)[-1])) print('{:_<28}:{:_>28.5f}'.format('MEAN', jhta.MEAN(df, len(df[price]), price)[-1])) # print ('{:_<28}:{:_>28.5f}'.format('HARMONIC_MEAN', jhta.HARMONIC_MEAN(df, len(df[price]), price)[-1])) print('{:_<28}:{:_>28.5f}'.format( 'MEDIAN', jhta.MEDIAN(df, len(df[price]), price)[-1])) print('{:_<28}:{:_>28.5f}'.format( 'MEDIAN_LOW', jhta.MEDIAN_LOW(df, len(df[price]), price)[-1])) print('{:_<28}:{:_>28.5f}'.format( 'MEDIAN_HIGH', jhta.MEDIAN_HIGH(df, len(df[price]), price)[-1])) print('{:_<28}:{:_>28.5f}'.format( 'MEDIAN_GROUPED', jhta.MEDIAN_GROUPED(df, len(df[price]), price)[-1])) # print ('{:_<28}:{:_>28.5f}'.format('MODE', jhta.MODE(df, len(df[price]), price)[-1])) print('{:_<28}:{:_>28.5f}'.format( 'PSTDEV', jhta.PSTDEV(df, len(df[price]), price)[-1])) print('{:_<28}:{:_>28.5f}'.format( 'PVARIANCE', jhta.PVARIANCE(df, len(df[price]), price)[-1])) print('{:_<28}:{:_>28.5f}'.format( 'STDEV', jhta.STDEV(df, len(df[price]), price)[-1])) print('{:_<28}:{:_>28.5f}'.format( 'VARIANCE', jhta.VARIANCE(df, len(df[price]), price)[-1]))
def NORMALIZE(df, price_max='High', price_min='Low', price='Close'): """ Normalize Returns: list of floats = jhta.NORMALIZE(df, price_max='High', price_min='Low', price='Close') Source: https://machinelearningmastery.com/normalize-standardize-time-series-data-python/ """ normalize_list = [] start = None for i in range(len(df[price])): if df[price_max][i] != df[price_max][i] or df[price_min][i] != df[price_min][i] or df[price][i] != df[price][i] or i < 1: normalize = float('NaN') else: if start is None: start = i x_max = df[price_max][start:] norm_max = jhta.MAX({'x': x_max}, len(x_max), 'x')[-1] x_min = df[price_min][start:] norm_min = jhta.MIN({'x': x_min}, len(x_min), 'x')[-1] normalize = (df[price][i] - norm_min) / (norm_max - norm_min) normalize_list.append(normalize) return normalize_list
def NORMALIZE(df, price_max='High', price_min='Low', price='Close'): """ Normalize """ normalize_list = [] i = 0 start = None while i < len(df[price]): if df[price_max][i] != df[price_max][i] or df[price_min][i] != df[ price_min][i] or df[price][i] != df[price][i] or i < 1: normalize = float('NaN') else: if start is None: start = i x_max = df[price_max][start:] norm_max = jhta.MAX({'x': x_max}, len(x_max), 'x')[-1] x_min = df[price_min][start:] norm_min = jhta.MIN({'x': x_min}, len(x_min), 'x')[-1] normalize = (df[price][i] - norm_min) / (norm_max - norm_min) normalize_list.append(normalize) i += 1 return normalize_list