def __getSimilarStock__(self): result_dis = [] result_dt = [] result_ts = [] stock_list = sd.get_similar_industry_stock(self.ts_code) x_data = sd.get_daily_bar(self.ts_code, self.__getx_data_start_time_point__(), self.prediction_time_point) if x_data.empty: self.__error__ = True return None else: x = np.array(x_data['pct_change']) ob_length = len(x) for index, row in stock_list.iterrows(): stock = row['ts_code'] if stock != self.ts_code: y_data = sd.get_daily_bar(stock, self.__gety_data_start_time_point__(), self.__gety_data_end_time_point__()) if not y_data.empty: time_point_list = np.array(y_data['trade_date']) y = np.array(y_data['pct_change']) for i in range(0, int(len(y) / ob_length)): y_t = y[i * ob_length:(i + 1) * ob_length] distance, path = similarity_calculation(x, y_t, dist=euclidean) result_dis.append(distance) result_dt.append(time_point_list[(i + 1) * ob_length - 1]) result_ts.append(stock) result = pd.DataFrame({'ts_code': result_ts, 'distance': result_dis, 'time_point': result_dt}) return result.sort_values(by='distance', axis=0, ascending=True)
def __getSimilarStock__(self): result_dis = [] result_sdt = [] result_edt = [] x_data = sd.get_daily_bar(self.ts_code, self.__getx_data_start_time_point__(), self.prediction_time_point) if x_data.empty: self.__error__ = True return None else: x = np.array(x_data['pct_change']) ob_length = len(x) y_data = sd.get_daily_bar(self.ts_code, self.__gety_data_start_time_point__(), self.__gety_data_end_time_point__()) if not y_data.empty: time_point_list = np.array(y_data['trade_date']) y = np.array(y_data['pct_change']) for i in range(0, len(y) - ob_length + 1): y_t = y[i:i + ob_length] distance, path = similarity_calculation(x, y_t, dist=euclidean) result_dis.append(distance) result_sdt.append(time_point_list[i]) result_edt.append(time_point_list[i + ob_length - 1]) result = pd.DataFrame( {'distance': result_dis, 'start_time_point': result_sdt, 'end_time_point': result_edt}) return result.sort_values(by='distance', axis=0, ascending=True)
def __getSimilarStock__(self): result_dis = [] result_ts = [] stock_list = sd.get_similar_industry_stock(self.ts_code) x_data = sd.get_daily_bar(self.ts_code, self.__get_data_start_time_point__(), self.prediction_time_point) if x_data.empty: self.__error__ = True return None else: x = np.array(x_data['pct_change']) for index, row in stock_list.iterrows(): stock = row['ts_code'] if stock != self.ts_code: y_data = sd.get_daily_bar(stock, self.__get_data_start_time_point__(), self.prediction_time_point) if not y_data.empty: y = np.array(y_data['pct_change']) distance, path = similarity_calculation(x, y, dist=euclidean) result_dis.append(distance) result_ts.append(stock) result = pd.DataFrame({'ts_code': result_ts, 'distance': result_dis}) return result.sort_values(by='distance', axis=0, ascending=True)