Пример #1
0
    def allScaler(self):
        if self.list_x is not None:
            return self.list_x, self.list_y, self.scaler_x, self.scaler_y, self.train_map

        df = stock_sql.getStockFrame()
        df.sort_values(by=["symbol"], inplace=True, ignore_index=True)
        arr = np.array(df)
        data_new_x, data_new_y, list_index, self.train_map = self.getDataWithIndexMultiple(
            arr, self.only_untrain)
        data_new_x = np.concatenate(data_new_x, axis=0)
        data_new_y = np.concatenate(data_new_y, axis=0)
        self.scaler_x, self.scaler_y = MinMaxScaler(), MinMaxScaler()
        data_new_x, data_new_y = self.scaler_x.fit_transform(
            data_new_x), self.scaler_y.fit_transform(data_new_y)
        self.list_x, self.list_y = {}, {}
        list_symbols = list(self.train_map.keys())
        for i in range(len(list_index)):
            data_a, data_b = data_new_x[:list_index[
                i]], data_new_y[:list_index[i]]
            data_new_x, data_new_y = data_new_x[list_index[i]:], data_new_y[
                list_index[i]:]
            self.list_x[list_symbols[i]] = data_a
            self.list_y[list_symbols[i]] = data_b

        return self.list_x, self.list_y, self.scaler_x, self.scaler_y, self.train_map
Пример #2
0
 def test(self):
     print("+++++++++++++++++++++++")
     self.verify = True
     self.only_untrain = True
     df = stock_sql.getStockFrame()
     df.sort_values(by=["symbol"], inplace=True, ignore_index=True)
     stock_list = np.array(df)
     for info in stock_list:
         data = self.getTrainData(stockInfo(symbol=info[0]))
         data_x, data_y = data[0], data[1]
         for i in range(len(data_x)):
             print(data_x[i][self.SEQUENCE_LEN - 1])
             print(data_y[i])
Пример #3
0
    def dataGenerator(self, index: int = 0):
        df = stock_sql.getStockFrame()
        df.sort_values(by=["symbol"], inplace=True, ignore_index=True)
        # 截取index以后的数据
        stock_array = np.array(df)[index:]
        batch_array = stock_sql.arr_split(stock_array, self.batch_size)

        for s_array in batch_array:
            # 多进程
            list_x, list_y = self.dataConcat(s_array)
            # list_x,list_y =dataConcat(s_array,only_untrain)
            if len(list_x[0]) == 0 or len(list_y) == 0: continue
            data_x = []
            for i in range(self.tuple_x):
                data_x.append(np.concatenate(list_x[i], axis=0))
            data_y = np.concatenate(list_y, axis=0)
            yield data_x, data_y, s_array
Пример #4
0
 def getExVec(self):
     df = stock_sql.getStockFrame(
         headers=["symbol", "name", "area", "industry"])
     df.sort_values(by=["symbol"], inplace=True, ignore_index=True)
     df.fillna(" ", inplace=True)
     area_vec = OneHotEncoder(sparse=False).fit_transform(df[["area"]])
     indu_vec = OneHotEncoder(sparse=False).fit_transform(df[["industry"]])
     # data = pd.read_csv("data/stock_basic.csv", dtype=object)
     # aa = OneHotEncoder().fit_transform(data[["所在地域"]])
     data_area = {}
     data_indu = {}
     symbols = np.array(df[["symbol"]])
     # areas =np.array(df[["area"]]).reshape(-1)
     # data_t={}
     for i in range(len(symbols)):
         data_area[symbols[i][0]] = area_vec[i]
         data_indu[symbols[i][0]] = indu_vec[i]
     return data_area, data_indu, area_vec.shape, indu_vec.shape
Пример #5
0
 def upDownrate(self):
     stock_sql.ClearRecordData()
     df = stock_sql.getStockFrame()
     stockList = np.array(df)
     fitConunt = {}
     for i in range(prepare.RREDICT_LEN + 1):
         fitConunt[str(i)] = 0
     for stock in stockList[0:]:
         realData, predictData = self.trainMode.predict(stockInfo(symbol=stock[0]))
         if realData.shape[0] != prepare.RREDICT_LEN:
             continue
         closeColnum = prepare.getTrianColnum(stockInfo(symbol=stock[0]))
         real_up, pred_up, count, total = upDownfit(closeColnum, realData, predictData)
         print("symbol:" + str(stock[0]) + "  name:" + str(stock[1]) + "  fit:" + str(count))
         fitConunt[str(count)] += 1
     x = [i for i in range(prepare.RREDICT_LEN + 1)]
     y = [fitConunt[str(d)] for d in range(prepare.RREDICT_LEN + 1)]
     plt.plot(x, y)
     plt.show()
     print(fitConunt)
Пример #6
0
    def upDownrate(self):

        df = stock_sql.getStockFrame()
        stockList = np.array(df)
        fitConunt = {}
        for i in range(prepare.RREDICT_LEN + 1):
            fitConunt[str(i)] = 0
        for stock in stockList[0:]:
            realData, predictData = self.trainMode.predict(stockInfo(symbol=stock[0]))
            predictData= [np.argmax(predictData[i]) for i in range(len(predictData))]
            predictData =np.array(predictData).reshape((-1,1))
            if realData.shape[0] != prepare.RREDICT_LEN:
                continue
            count= self.fitCount(realData,predictData)
            print("symbol:" + str(stock[0]) + "  name:" + str(stock[1]) + "  fit:" + str(count))
            fitConunt[str(count)] += 1
        x = [i for i in range(prepare.RREDICT_LEN + 1)]
        y = [fitConunt[str(d)] for d in range(prepare.RREDICT_LEN + 1)]
        plt.plot(x, y)
        plt.show()
        print(fitConunt)
Пример #7
0
    def RRrate(self):
        stock_sql.ClearRecordData()
        df = stock_sql.getStockFrame()
        stockList = np.array(df)
        fitConunt = {}

        for stock in stockList[0:]:
            realData, predictData = trainning. logisticsTrain().predict(stockInfo(symbol=stock[0]))
            if len(realData) is 0:
                continue
            r2 = r2_socre(realData, predictData, 0)
            if r2 in fitConunt.keys():
                fitConunt[r2] += 1
            else:
                fitConunt[r2] = 0
            print("symbol:" + str(stock[0]) + "  name:" + str(stock[1]) + "  fit:" + str(r2))

        x = list(fitConunt.keys())
        x.sort()
        y = [fitConunt[d] for d in x]
        x = [math.tanh(d) for d in x]
        plt.plot(x, y)
        plt.show()
        print(fitConunt)
Пример #8
0
def getList():
    print("getList called")
    data = stock_sql.getStockFrame()
    return data.to_json(orient='records', force_ascii=False)