This commit is contained in:
dsyoon
2022-08-20 01:29:46 +09:00
parent 31394e7694
commit b6dedc9275
2 changed files with 57 additions and 3 deletions

View File

@@ -152,11 +152,16 @@ class Simulation (HTS):
else: else:
if method == "ml": if method == "ml":
LAST_DATA = self.stock2Vector.getLastData(stock_code, today, n=3) LAST_DATA = self.stock2Vector.getLastData(stock_code, today, n=3)
data = self.stock2Vector.getRealTime(stock_code, today, LAST_DATA) result = self.stock2Vector.getRealTime(stock_code, today, LAST_DATA)
X, Y = self.stock2Vector.getVectorData(data) X, Y = self.stock2Vector.getVectorData(result)
predY = self.stockPredictor.predict(X, Y) predY = self.stockPredictor.predict(X, Y)
bsLine = None predY = np.argmax(predY, axis=1)
# 이동평균, RSI, MACD, 일목균형, 볼린저밴드 상/하단을 계산한다.
data = self.buySellChecker.analyze(result)
# 사야 할 시점과 팔아야 할 시점을 체크한다.
bsLine, data = self.buySellChecker.checkTransactionML(data, stock_code, predY, isRealTime=False)
else: else:
LAST_DATA = self.stock2Vector.getLastData(stock_code, today) LAST_DATA = self.stock2Vector.getLastData(stock_code, today)
result = self.stock2Vector.getRealTime(stock_code, today, LAST_DATA) result = self.stock2Vector.getRealTime(stock_code, today, LAST_DATA)

View File

@@ -904,3 +904,52 @@ class BuySellChecker:
bsLine['sell_weight'][i] = sell_weight bsLine['sell_weight'][i] = sell_weight
return bsLine, data return bsLine, data
def checkTransactionML(self, data, stock_code, predY, isRealTime=True):
# 4일치 중에서 앞에 2일은 제거한다.
date = data['date'].dt.date.unique().tolist()
data = data[data['date'].dt.date != date[0]]
data = data[data['date'].dt.date != date[1]]
# 어제 오늘 데이터로 분석
bsLine = {}
size = len(data["close"])
if isRealTime:
# isRealTime=True, 실시간 적용
last_index = size - 1
# Type=False, 시뮬레이션 적용
bsLine['buy'] = [-1 for i in range(size)]
bsLine['buy_weight'] = [-1 for i in range(size)]
bsLine['sell'] = [-1 for i in range(size)]
bsLine['sell_weight'] = [-1 for i in range(size)]
sell, sell_weight, buy, buy_weight = -1, -1, -1, -1
if predY[last_index] == 1:
sell = int((data["open"][last_index] + data["close"][last_index]) / 2)
sell_weight = 1
elif predY[last_index] == 2:
buy = int((data["open"][last_index] + data["close"][last_index]) / 2)
buy_weight = 1
bsLine['buy'] = [buy]
bsLine['buy_weight'] = [buy_weight]
bsLine['sell'] = [sell]
bsLine['sell_weight'] = [sell_weight]
else:
# Type=False, 시뮬레이션 적용
bsLine['buy'] = [-1 for i in range(size)]
bsLine['buy_weight'] = [-1 for i in range(size)]
bsLine['sell'] = [-1 for i in range(size)]
bsLine['sell_weight'] = [-1 for i in range(size)]
for i in range(size):
if predY[i] == 1:
bsLine['sell'][i] = int((data["open"][i] + data["close"][i]) / 2)
bsLine['sell_weight'][i] = 1
elif predY[i] == 2:
bsLine['buy'][i] = int((data["open"][i] + data["close"][i]) / 2)
bsLine['buy_weight'][i] = 1
return bsLine, data