This commit is contained in:
dosangyoon
2022-08-07 17:46:06 +09:00
parent 655eedc421
commit 57a906bc08
5 changed files with 53 additions and 26 deletions

View File

@@ -20,10 +20,14 @@ class Simulation (HTS):
self.RESOURCE_PATH = RESOURCE_PATH
self.buySellChecker = BuySellChecker()
try:
self.stock2Vector = Stock2Vector(RESOURCE_PATH)
self.labelMaker = LabelMaker(RESOURCE_PATH)
self.buySellChecker = BuySellChecker()
self.stockPredictor = StockPredictor(RESOURCE_PATH)
except:
pass
#self.connect()
return
@@ -77,10 +81,10 @@ class Simulation (HTS):
sell_check = go.Scatter(x=data['date'], y=sell_line, mode='markers', name="sell", marker=dict(size=14, color=sell_colors, line_width=0))
upper = go.Scatter(x=data['date'], y=data["upper"], name="upper", line_color='#000000')
lower = go.Scatter(x=data['date'], y=data["lower"], name="lower", line_color='#000000')
avg3 = go.Scatter(x=data['date'], y=data["avg3"], name="avg3", line_color='#1469F4')
avg3 = go.Scatter(x=data['date'], y=data["avg3"], name="avg3", line_color='#8F8203')
avg5 = go.Scatter(x=data['date'], y=data["avg5"], name="avg5", line_color='#089B5B')
avg10 = go.Scatter(x=data['date'], y=data["avg10"], name="avg10", line_color='#ff00ff')
avg20 = go.Scatter(x=data['date'], y=data["avg20"], name="avg20", line_color='#8F8203')
avg20 = go.Scatter(x=data['date'], y=data["avg20"], name="avg20", line_color='#1469F4')
avg30 = go.Scatter(x=data['date'], y=data["avg30"], name="avg30", line_color='#000000')
#avg60 = go.Scatter(x=hts['date'], y=hts["avg60"], name="avg60", line_color='#008000')

View File

@@ -1,4 +1,5 @@
# tensor - numpy - PILImage 변환 (https://qlsenddl-lab.tistory.com/37)
from PIL import Image
import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'
@@ -214,6 +215,8 @@ class VitTrainer:
if __name__ == "__main__":
image = Image.open("img.png")
PROJECT_HOME = os.getcwd()
RESOURCE_PATH = os.path.join(PROJECT_HOME, "resources")
model_path = os.path.join(RESOURCE_PATH, "model")

View File

@@ -151,8 +151,18 @@ class BuySellChecker:
def getBuyCheck(self, data, i, buy, weight):
if data['close'][i]<data['avg3'][i]<data['avg5'][i]<data['avg10'][i]<data['avg20'][i]<data['avg30'][i]:
buy, weight, sell = -1, -1, -1
if data['slow_k'][i] > 40:
buy, weight, sell = -1, -1, -1
high, low = 0, 0
for c in range(1, 10):
if data['lower'][i-c-1] < data['lower'][i-c]:
high += 1
else:
low += 1
if high > low:
buy, weight, sell = -1, -1, -1
return buy, weight
@@ -161,8 +171,8 @@ class BuySellChecker:
def isYangbong(self, data, i):
if data['close'][i] > data['open'][i]:
return True
if data['close'][i] == data['open'][i]:
if data['low'][i] < data['close'][i] == data['high'][i]:
else:
if data['low'][i] < data['close'][i] == data['open'][i] == data['high'][i]:
return True
if data['low'][i] < data['open'][i] == data['close'][i] < data['high'][i]:
return True
@@ -171,8 +181,8 @@ class BuySellChecker:
def isUmbong(self, data, i):
if data['close'][i] < data['open'][i]:
return True
if data['close'][i] == data['open'][i]:
if data['close'][i] == data['low'][i] < data['high'][i]:
else:
if data['low'][i] == data['close'][i] == data['open'][i] < data['high'][i]:
return True
if data['low'][i] < data['open'][i] == data['close'][i] < data['high'][i]:
return True
@@ -237,7 +247,7 @@ class BuySellChecker:
if data["open"][i-2] < data["close"][i-2] and data["open"][i-1] <= data["close"][i-1] and data["open"][i] < data["close"][i]:
umbong = 0
for c in range(13, 3, -1):
if data['close'][i-c] <= data['open'][i-c]:
if (data['close'][i-c] < data['open'][i-c] or data['close'][i-c] == data['open'][i-c] == data['low'][i-c] < data['high'][i-c]):
umbong += 1
if umbong >= 8:
if data["open"][i] < data["open"][i-10]:
@@ -343,6 +353,7 @@ class BuySellChecker:
weight = 10
return self.getBuyCheck(data, i, buy, weight)
"""
# 이동선을 이용한 매매
# 20분선이 30분선에 돌파 후 지지하는지 확인하고 해당 시점이 양봉이면 매수함
@@ -412,7 +423,7 @@ class BuySellChecker:
valid = False
break
if valid:
sell = int((data["open"][i] + data["close"][i])/2)
sell = data["high"][i]
return sell, weight
@@ -424,13 +435,13 @@ class BuySellChecker:
valid = False
break
if valid:
sell = int((data["open"][i] + data["close"][i])/2)
sell = data["high"][i]
return sell, weight
# rsi와 rsis가 75이상에서 slow_k가 slow_d 아래롸 내려온 경우
if data["rsi"][i] >= 70 and data["rsis"][i] >= 70:
if data["rsi"][i-1] > data["rsis"][i-1] and data["rsi"][i] < data["rsis"][i]:
sell = int((data["open"][i] + data["close"][i]) / 2)
sell = data["high"][i]
return sell, weight
@@ -438,11 +449,9 @@ class BuySellChecker:
if data["slow_k"][i] >= 90 and data["slow_d"][i] >= 90:
if data["slow_k"][i-1] > data["slow_d"][i-1] and data["slow_k"][i] < data["slow_d"][i]:
if data["avg3"][i] < data["avg5"][i]:
sell = int((data["open"][i] + data["close"][i]) / 2)
sell = data["high"][i]
if data.index[i].strftime("%H:%M") < "12:00" and data['rsis'][i] < 70:
return -1, -1
return sell, weight
# 양봉 5개 이후 음봉이 나온 경우
@@ -456,7 +465,7 @@ class BuySellChecker:
if data["avg30"][i-1] < data["avg20"][i-1] < data["avg10"][i-1] < data["avg5"][i-1] < data["avg3"][i-1]:
if data["close"][i] < data["open"][i] and data["low"][i] < data["low"][i-1]:
if data["slow_k"][i] >= 95:
sell = data["close"][i]
sell = data["high"][i]
weight = 1
return sell, weight
@@ -466,7 +475,7 @@ class BuySellChecker:
(data["high"][i-3] > data["upper"][i-3] or data["high"][i-3] > data["avg3"][i-3] > data["avg5"][i-3] > data["avg10"][i-3] > data["avg20"][i-3] > data["avg30"][i-3])):
if self.isUmbong(data, i-2) and self.isUmbong(data, i-1) and self.isUmbong(data, i):
if data["slow_k"][i] >= 80:
sell = data["low"][i]
sell = int((data["high"][i] + data["low"][i])/2)
weight = 1
return sell, weight

View File

@@ -284,6 +284,15 @@ class Stock2Vector(HTS):
Y = np.asarray(Y, dtype='int64')
return X, Y
def getVectorData(self, data, type="avg10", VECTOR_SIZE = 32):
X, Y = [], []
df, minmax_df = self.preprocessData(data)
X = np.asarray(X)
Y = np.asarray(Y, dtype='int64')
return X, Y
def getDataset3D(self, data, VECTOR_SIZE = 299):
df, minmax_df = self.preprocessData(data)

View File

@@ -9,9 +9,11 @@ from datasets import Dataset, load_dataset
import torch
import torchvision.transforms as transforms
try:
from transformers import ViTFeatureExtractor, ViTForImageClassification, TrainingArguments, Trainer
from torchvision.transforms import (CenterCrop, Compose, Normalize, RandomHorizontalFlip, RandomResizedCrop, Resize, ToTensor)
except:
pass
from stock.util.Stock2Vector import Stock2Vector