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 __count_quota__(self): result = {} for index, row in self.__similar_stock__.iterrows(): stock = row['ts_code'] data = sd.get_daily_bar(stock, self.__get_data_start_time_point__(), self.prediction_time_point) if not data.empty: data['pct_mark'] = data.apply(self.__mark__, axis=1) x = np.array(data['pct_mark']) result.setdefault(stock, float(len(x[(x != 0)])) / float(len(x))) self.__activity__ = result
def __count_quota__(self): trend_line_result = {} for index, row in self.__similar_stock__.iterrows(): stock = row['ts_code'] time = row['time_point'] e_t = datetime.strptime(time, "%Y%m%d") + timedelta(days=self.__ob_window__) data = sd.get_daily_bar(stock, time, datetime.strftime(e_t, "%Y%m%d")) if not data.empty: x = list(data['close']) trend_line_result.setdefault(stock, x) self.__trend_line__ = trend_line_result
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)
def __count_quota__(self): trend_line_result = {} for index, row in self.__similar_stock__.iterrows(): time = row['end_time_point'] s_t = row['start_time_point'] e_t = datetime.strptime(time, "%Y%m%d") + timedelta(days=self.__ob_window__) data = sd.get_daily_bar(self.ts_code, s_t, datetime.strftime(e_t, "%Y%m%d")) if not data.empty: x = list(data['close']) t = list(data['trade_date']) trend_line_result.setdefault("close", x) trend_line_result.setdefault("timeline", t) self.__trend_line__ = trend_line_result
def __count_quota__(self): first_pct_change = [] second_pct_change = [] third_pct_change = [] for index, row in self.__similar_stock__.iterrows(): stock = row['ts_code'] time = row['time_point'] e_t = datetime.strptime(time, "%Y%m%d") + timedelta(days=30) data = sd.get_daily_bar(stock, time, datetime.strftime(e_t, "%Y%m%d")) if (not data.empty) and len(data)>=3: x = np.array(data['pct_change']) first_pct_change.append(x[0]) second_pct_change.append(x[1]) third_pct_change.append(x[2]) self.__first_pct_change__ = np.array(first_pct_change) self.__second_pct_change__ = np.array(second_pct_change) self.__third_pct_change__ = np.array(third_pct_change)