From 3485cafd85eaa44635cc401f3182d3b46502d1a5 Mon Sep 17 00:00:00 2001 From: dosangyoon Date: Fri, 19 Aug 2022 22:46:47 +0900 Subject: [PATCH] init --- stock/util/Stock2Vector.py | 84 +++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/stock/util/Stock2Vector.py b/stock/util/Stock2Vector.py index 4b58d69..4457bae 100644 --- a/stock/util/Stock2Vector.py +++ b/stock/util/Stock2Vector.py @@ -285,8 +285,8 @@ class Stock2Vector(HTS): Y = np.asarray(Y, dtype='int64') return X, Y - def getVectorData(self, data, VECTOR_SIZE = 32, H_VECTOR_SIZE = 32, W_VECTOR_SIZE = 200): - return self.getVectorData_2(data, H_VECTOR_SIZE, W_VECTOR_SIZE) + def getVectorData(self, data, VECTOR_SIZE = 32): + return self.getVectorData_2(data, VECTOR_SIZE) def getVectorData_1(self, data, VECTOR_SIZE): df = self.buySellChecker.analyze(data) @@ -329,7 +329,7 @@ class Stock2Vector(HTS): batch_Y = np.asarray(batch_Y, dtype='int64') return batch_X, batch_Y - def getVectorData_2(self, data, H_VECTOR_SIZE = 32, W_VECTOR_SIZE = 200): + def getVectorData_2(self, data, VECTOR_SIZE = 32): df = self.buySellChecker.analyze(data) macd = df['macd'].tolist() @@ -368,40 +368,50 @@ class Stock2Vector(HTS): size = len(label) batch_X, batch_Y = [], [] - for i in range(W_VECTOR_SIZE - 1, size): - X = np.zeros((H_VECTOR_SIZE, W_VECTOR_SIZE)) - X[0] = macd[i - W_VECTOR_SIZE + 1: i + 1] - X[1] = diff_avg27[i - W_VECTOR_SIZE + 1: i + 1] - X[2] = diff_avg3_avg27[i - W_VECTOR_SIZE + 1: i + 1] - X[3] = diff_avg3_avg54[i - W_VECTOR_SIZE + 1: i + 1] - X[4] = diff_avg6_avg27[i - W_VECTOR_SIZE + 1: i + 1] - X[5] = diff_avg6_avg54[i - W_VECTOR_SIZE + 1: i + 1] - X[6] = diff_avg9_avg27[i - W_VECTOR_SIZE + 1: i + 1] - X[7] = diff_avg9_avg54[i - W_VECTOR_SIZE + 1: i + 1] - X[8] = diff_avg12_avg27[i - W_VECTOR_SIZE + 1: i + 1] - X[9] = diff_avg12_avg54[i - W_VECTOR_SIZE + 1: i + 1] - X[10] = diff_change_lead1[i - W_VECTOR_SIZE + 1: i + 1] - X[11] = diff_open_lead1[i - W_VECTOR_SIZE + 1: i + 1] - X[12] = diff_close_lead1[i - W_VECTOR_SIZE + 1: i + 1] - X[13] = diff_high_lead1[i - W_VECTOR_SIZE + 1: i + 1] - X[14] = diff_low_lead1[i - W_VECTOR_SIZE + 1: i + 1] - X[15] = rsi[i - W_VECTOR_SIZE + 1: i + 1] - X[16] = rsis[i - W_VECTOR_SIZE + 1: i + 1] - X[17] = diff_avg54[i - W_VECTOR_SIZE + 1: i + 1] - X[18] = diff_change_base[i - W_VECTOR_SIZE + 1: i + 1] - X[19] = diff_base_lead1[i - W_VECTOR_SIZE + 1: i + 1] - X[20] = diff_open_base[i - W_VECTOR_SIZE + 1: i + 1] - X[21] = diff_close_base[i - W_VECTOR_SIZE + 1: i + 1] - X[22] = diff_high_base[i - W_VECTOR_SIZE + 1: i + 1] - X[23] = diff_low_base[i - W_VECTOR_SIZE + 1: i + 1] - X[24] = abs_avg_1[i - W_VECTOR_SIZE + 1: i + 1] - X[25] = abs_avg_2[i - W_VECTOR_SIZE + 1: i + 1] - X[26] = abs_avg_3[i - W_VECTOR_SIZE + 1: i + 1] - X[27] = abs_avg_4[i - W_VECTOR_SIZE + 1: i + 1] - X[28] = abs_avg_5[i - W_VECTOR_SIZE + 1: i + 1] - X[29] = diff_upper_lower[i - W_VECTOR_SIZE + 1: i + 1] - X[30] = diff_open_lower[i - W_VECTOR_SIZE + 1: i + 1] - X[31] = diff_close_upper[i - W_VECTOR_SIZE + 1: i + 1] + CHANNEL_SIZE = 4 + for i in range(VECTOR_SIZE*CHANNEL_SIZE-1, size): + X = np.zeros((CHANNEL_SIZE, VECTOR_SIZE, VECTOR_SIZE)) + s, e = i, i + for c in range(0, 4): + if c == 0 : + s = i - VECTOR_SIZE*CHANNEL_SIZE + 1 + e += VECTOR_SIZE + else: + s = e + e += + VECTOR_SIZE + + X[c, 0] = macd[s: e] + X[c, 1] = diff_avg27[s: e] + X[c, 2] = diff_avg3_avg27[s: e] + X[c, 3] = diff_avg3_avg54[s: e] + X[c, 4] = diff_avg6_avg27[s: e] + X[c, 5] = diff_avg6_avg54[s: e] + X[c, 6] = diff_avg9_avg27[s: e] + X[c, 7] = diff_avg9_avg54[s: e] + X[c, 8] = diff_avg12_avg27[s: e] + X[c, 9] = diff_avg12_avg54[s: e] + X[c, 10] = diff_change_lead1[s: e] + X[c, 11] = diff_open_lead1[s: e] + X[c, 12] = diff_close_lead1[s: e] + X[c, 13] = diff_high_lead1[s: e] + X[c, 14] = diff_low_lead1[s: e] + X[c, 15] = rsi[s: e] + X[c, 16] = rsis[s: e] + X[c, 17] = diff_avg54[s: e] + X[c, 18] = diff_change_base[s: e] + X[c, 19] = diff_base_lead1[s: e] + X[c, 20] = diff_open_base[s: e] + X[c, 21] = diff_close_base[s: e] + X[c, 22] = diff_high_base[s: e] + X[c, 23] = diff_low_base[s: e] + X[c, 24] = abs_avg_1[s: e] + X[c, 25] = abs_avg_2[s: e] + X[c, 26] = abs_avg_3[s: e] + X[c, 27] = abs_avg_4[s: e] + X[c, 28] = abs_avg_5[s: e] + X[c, 29] = diff_upper_lower[s: e] + X[c, 30] = diff_open_lower[s: e] + X[c, 31] = diff_close_upper[s: e] batch_X.append(X) batch_Y.append(label[i])