def init(self): self.windows = self.param['window'] self.cols = self.param['col'] self.types = self.param['type'] self.translation_cols = self.param.get('translation') self.scale_cols = self.param.get('scale') self.move_window_mapping = { "mean": lambda c, s, t, w: bn.move_mean(c, w) * s + t, "std": lambda c, s, t, w: bn.move_std(c, w) * s, "var": lambda c, s, t, w: bn.move_var(c, w) * s * s, "min": lambda c, s, t, w: bn.move_min(c, w) * s + t, "max": lambda c, s, t, w: bn.move_max(c, w) * s + t, "rank": lambda c, s, t, w: bn.move_rank(c, w), "sum": lambda c, s, t, w: bn.move_sum(c, w) * s + t * w, "ema": lambda c, s, t, w: F. ema(c, 2.0 / (w + 1), start_indices=self.base.start_indices) * s + t, "rsi": lambda c, s, t, w: F.rsi( c, w, start_indices=self.base.start_indices), "psy": lambda c, s, t, w: F.psy( c, w, start_indices=self.base.start_indices), "bias": lambda c, s, t, w: F.bias( c, w, start_indices=self.base.start_indices) }
def Ts_min(A, n): ''' 计算n天(包括当天)的最小值 n >= 1 ''' if n < 1: #print ("计算n天的最小值,n不得小于1,返回输入") return A result = bk.move_min(A, n, min_count=1, axis=0) result[np.isnan(A)] = np.nan return result
def _wr(arr_h, arr_l, arr_c, arr_o, window, start_indices): high_n = bn.move_max(arr_h,window) low_n = bn.move_min(arr_l,window) res = np.where(high_n - low_n!=0, 100*(high_n - arr_c) / (high_n - low_n), 50) pre_cnt = 0.0 N = arr_c.shape[0] N_GROUP = start_indices.shape[0] j = 0 for i in range(N): if j < N_GROUP and start_indices[j] == i: pre_cnt = 0 j += 1 if pre_cnt < window: res[i] = np.nan pre_cnt += 1 return res
def plot(self, window=100, alpha=0.2, save=False, close_plots=False, pre_fix=""): plt.figure() plt.title(pre_fix + "Mean") p = plt.plot(bn.move_mean(self.reward_hist, window=window))[0] if alpha > 0: plt.plot(self.reward_hist, color=p.get_color(), alpha=alpha) plt.xlim(xmin=0) plt.grid(True) if not save is False: plt.savefig(os.path.join(save, "move_mean.svg")) if not close_plots: plt.show() else: plt.close() plt.figure() plt.title(pre_fix + "Min") plt.plot(bn.move_min(self.reward_hist, window=window)) plt.xlim(xmin=0) plt.grid(True) if not save is False: plt.savefig(os.path.join(save, "move_min.svg")) if not close_plots: plt.show() else: plt.close() plt.figure() plt.title(pre_fix + "Max") plt.plot(bn.move_max(self.reward_hist, window=window)) plt.xlim(xmin=0) plt.grid(True) if not save is False: plt.savefig(os.path.join(save, "move_max.svg")) if not close_plots: plt.show() else: plt.close()
def time_move_min(self, dtype, shape, order, axis, window): bn.move_min(self.arr, window, axis=axis)
def time_move_min(self, dtype, shape, window): bn.move_min(self.arr, window)