def x_tick_labels(self): arr = np.mod(self.index_to_intday, 10000) is_year_firsts = (arr - np_shift(arr, 1, fill_value=0)) < 0 arr = np.mod(self.index_to_intday, 100) is_month_firsts = (arr - np_shift(arr, 1, fill_value=0)) < 0 yposes = self.xs[is_year_firsts] mposes = self.xs[is_month_firsts] self.time_pos_info = yposes, mposes return yposes, mposes
def jump_value(df): # Return 0, negative value, positive value high = df.high.values low = df.low.values prehigh = np_shift(high, 1, 0) prelow = np_shift(low, 1, 0) jump_up = (low - prehigh) jump_up[jump_up <= 0] = 0 jump_down = (high - prelow) jump_down[jump_down >= 0] = 0 return jump_up + jump_down
def day_compare_features(df): o, c, h, l = KlineFeatures.ochl_features(df) po = np_shift(o, 1, 0) pc = np_shift(c, 1, 0) ph = np_shift(h, 1, 0) pl = np_shift(l, 1, 0) hh = np.maximum(h, ph) ll = np.minimum(l, pl) rr = hh - ll + sys.float_info.epsilon f1 = (o - ll) / rr f2 = (c - ll) / rr f3 = (po - ll) / rr f4 = (pc - ll) / rr f5 = (h - ll) / rr f6 = (l - ll) / rr f7 = (ph - ll) / rr f8 = (pl - ll) / rr return f1, f2, f3, f4, f5, f6, f7, f8
def even_count(arr): is_evens = (arr == np_shift(arr, 1, 0)) counts = ArrayIndicator.consecutive_count_of_True(is_evens) return counts
def drop_count(arr): is_drops = arr - np_shift(arr, 1, 0) < 0 counts = ArrayIndicator.consecutive_count_of_True(is_drops) return counts
def rise_count(arr): is_rises = arr - np_shift(arr, 1, 0) > 0 counts = ArrayIndicator.consecutive_count_of_True(is_rises) return counts
def func(df): val = cls.day_compare_features(df) return [np_shift(item, n, 0) for item in val]
def is_close_up(df): close_ = df.close.values close_pre = np_shift(close_, 1, 0) return close_ - close_pre > 0
def even_count_of_previous_days(df): arr = df.close.values is_even = (arr == np_shift(arr, 1, 0)) count = ArrayIndicator.consecutive_count_of_True(is_even) return np_shift(count, 1, 0)
def down_count_of_previous_days(df): arr = df.close.values is_up = arr - np_shift(arr, 1, 0) < 0 count = ArrayIndicator.consecutive_count_of_True(is_up) return np_shift(count, 1, 0)