def predict(self): result = [] for code in self.data: volume, chg_p, vma5 = Stock.get_col().index( "volume"), Stock.get_col().index( "chg_p"), Stock.get_col().index("vma5") data_array = np.array(self.data[code]) try: chg_p_array, vma5_array, volume_array = np.float32( data_array[:, chg_p]), np.float32( data_array[:, vma5]), np.float32(data_array[:, volume]) training_data = [] for v in volume_array: training_data.append([v]) training_label = [["down", "up"][int(x > 5.0)] for x in chg_p_array] trend, percent = classify0([vma5_array[-1]], np.array(training_data), training_label, 5) if trend == "up": result.append((code, percent)) except: trace_log() pass sorted_result = sorted(result, key=operator.itemgetter(1), reverse=True) return sorted_result
def predict(self): result = {} for code in self.data: date, close, chg_p = Stock.get_col().index("date"), Stock.get_col().index("close"), Stock.get_col().index("chg_p") try: last_date = self.data[code][-1][0] if last_date != time.strftime("%Y-%m-%d", time.localtime()): continue except: continue data_array = np.array(self.data[code]) try: close_array, chg_p_array = np.float32(data_array[:,close]), np.float32(data_array[:,chg_p]) def gold_predict(close_array): close_array = close_array[-10:] max_close = max(close_array) min_close = min(close_array) if close_array[-1] < max_close and max_close == close_array[-2]: if (max_close - min_close)/min_close > 0.1 : ratio = (max_close - close_array[-1]) / (max_close - min_close) if ratio < (0.382+0.010) and ratio > (0.382-0.010): result[code] = 2*max_close-close_array[-1] return True return False top_5_close_array = close_array[-5:] if not gold_predict(top_5_close_array): top_10_close_array = close_array[-10:] gold_predict(top_10_close_array) except: trace_log() pass return result.items()
def verify(self): up5 = 0 up1 = 0 up9 = 0 up = [] chg_p = Stock.get_col().index("chg_p") for code in self.up_code: data_array = np.array(self.data[code]) try: chg_p_array = np.float32(data_array[:, chg_p]) if chg_p_array[-1] >= 1.0: up1 += 1 up.append((code, chg_p_array[-1])) if chg_p_array[-1] >= 5.0: up5 += 1 if chg_p_array[-1] >= 9.0: up9 += 1 except: logging.error("%s failed" % code) trace_log() print "up5 = %.2f, up1 = %.2f, up9 = %.2f" % ( float(up5) / float(len(self.up_code)), float(up1) / float(len(self.up_code)), float(up9) / float(len(self.up_code))) print up
def predict(self): result = {} for code in self.data: volume, chg_p, vma5, ma5, close, high = Stock.get_col().index( "volume"), Stock.get_col().index("chg_p"), Stock.get_col( ).index("vma5"), Stock.get_col().index("ma5"), Stock.get_col( ).index("close"), Stock.get_col().index("high") try: last_date = self.data[code][-1][0] if last_date != time.strftime("%Y-%m-%d", time.localtime()): continue except: continue data_array = np.array(self.data[code]) try: chg_p_array, vma5_array, volume_array, ma5_array, close_array, high_array = np.float32( data_array[:, chg_p]), np.float32( data_array[:, vma5]), np.float32( data_array[:, volume]), np.float32( data_array[:, ma5]), np.float32( data_array[:, close]), np.float32( data_array[:, high]) # 判断跳空 jumped = False for i in range(-1, -10, -1): if high_array[i] < close_array[i - 1]: jumped = True break if jumped and chg_p_array[-1] > 3.0: down_number = 0 for c in chg_p_array[-10:]: if c < 0.0: down_number += 1 result[code] = down_number except: trace_log() pass sorted_result = sorted(result.iteritems(), key=operator.itemgetter(1), reverse=True) return sorted_result