def pred(self, daybefore, sample_size, sign_name, cache_size=1024): sign_num = alphatree.getSignNum(daybefore, sample_size, c_char_p(sign_name)) alpha_cache = (c_float * sign_num)() alphatree.predAlphaGBDF(daybefore, sample_size, c_char_p(sign_name), alpha_cache, cache_size) return np.array([alpha_cache[i] for i in range(sign_num)])
def get_trend(self, sign_name, elements, daybefore, sample_size, column, max_std_scale): element_cache = self.decode_features(elements) pic_size = (column * len(elements) * 3 * alphatree.getSignNum( daybefore, sample_size, c_char_p(sign_name.encode('utf-8')))) pic_cache = (c_float * pic_size)() alphatree.getTrendPic(self.picid, c_char_p(sign_name.encode('utf-8')), element_cache, len(elements), daybefore, sample_size, pic_cache, column, c_float(max_std_scale)) # trend = np.zeros((pic_size,)) # for i in range(pic_size): # trend[i] = pic_cache[i] trend = np.array(pic_cache) return trend.reshape([-1, column, len(elements) * 3, 1])
def pred(self, sign_name, daybefore, sample_size): sign_num = alphatree.getSignNum(daybefore, sample_size, c_char_p(sign_name.encode())) alpha_cache = (c_float * sign_num)() min_open_value_cache = (c_float * sign_num)() if self.is_open_buy else None max_open_value_cache = (c_float * sign_num)() if self.is_open_buy else None alphatree.predAlphaFilter(c_char_p(sign_name.encode()), daybefore, sample_size, alpha_cache, min_open_value_cache, max_open_value_cache) #res = np.array([alpha_cache[i] for i in range(sign_num)]) if self.is_open_buy: return np.array(alpha_cache), np.array( min_open_value_cache), np.array(max_open_value_cache) return np.array(alpha_cache)
def get_k_line(self, sign_name, open_elements, high_elements, low_elements, close_elements, daybefore, sample_size, column, max_std_scale): open_cache = self.decode_features(open_elements) high_cache = self.decode_features(high_elements) low_cache = self.decode_features(low_elements) close_cache = self.decode_features(close_elements) pic_size = (column * len(open_elements) * 3 * alphatree.getSignNum( daybefore, sample_size, c_char_p(sign_name.encode('utf-8')))) pic_cache = (c_float * pic_size)() alphatree.getKLinePic(self.picid, c_char_p(sign_name.encode('utf-8')), open_cache, high_cache, low_cache, close_cache, len(open_elements), daybefore, sample_size, pic_cache, column, c_float(max_std_scale)) # kline = np.zeros((pic_size,)) # for i in range(pic_size): # kline[i] = pic_cache[i] kline = np.array(pic_cache) return kline.reshape([-1, column, len(open_elements) * 3, 1])
def testRead(self, daybefore, sample_size, feature_num, target, sign_name, cache_size=2048): sign_num = alphatree.getSignNum(daybefore, sample_size, c_char_p(sign_name)) target_cache = (c_float * sign_num)() feature_cache = (c_float * (sign_num * feature_num))() data_num = alphatree.testReadGBDT(daybefore, sample_size, c_char_p(target), c_char_p(sign_name), feature_cache, target_cache, cache_size) assert data_num == sign_num t = [target_cache[i] for i in range(sign_num)] f = [] for i in range(sign_num): for j in range(feature_num): f.append(feature_cache[i * feature_num + j]) #f = [[feature_cache[i * feature_num + j] for j in range(feature_num)] for i in range(sign_num)] return np.array(f), np.array(t)