init
This commit is contained in:
@@ -153,6 +153,53 @@ class Stock2Vector(HTS):
|
||||
|
||||
return df, minmax_df
|
||||
|
||||
def getTrainData(self, stock_code):
|
||||
tableName = 'hts'
|
||||
conn = sqlite3.connect(os.path.join(self.RESOURCE_PATH, "hts.db"))
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute(
|
||||
'SELECT ymd, hms, open, high, low, close, volume, label FROM ' + tableName + ' WHERE CODE=? and (ymd >= ? and ymd <= ?) order by ymd desc, hms ',
|
||||
(stock_code, "20220721", "20220731"))
|
||||
db_result = cursor.fetchall()
|
||||
temp_result = []
|
||||
for rows in db_result:
|
||||
temp_result.append(
|
||||
[rows[0], rows[1], rows[2], rows[3], rows[4], rows[5], rows[6], 0 if rows[7] is None else rows[7]])
|
||||
temp_result.sort(key=lambda x: (x[0], x[1]))
|
||||
|
||||
result = {"check": set(), "time": [], "open": [], "close": [], "high": [], "low": [], "vol": [], "label": []}
|
||||
for rows in temp_result:
|
||||
ymd = rows[0] # hts.날짜
|
||||
hms = rows[1] # hts.시간
|
||||
open = rows[2] # hts.시가
|
||||
high = rows[3] # hts.고가
|
||||
low = rows[4] # hts.저가
|
||||
close = rows[5] # hts.종가
|
||||
vol = rows[6] # hts.거래량
|
||||
label = 0 if rows[7] is None else rows[7] # hts.매매구분
|
||||
|
||||
temp = datetime.strptime(str(ymd) + " " + str(hms).zfill(4) + "00", '%Y%m%d %H%M%S')
|
||||
|
||||
result["time"].append(temp)
|
||||
result["open"].append(int(open))
|
||||
result["close"].append(int(close))
|
||||
result["high"].append(int(high))
|
||||
result["low"].append(int(low))
|
||||
result["vol"].append(int(vol))
|
||||
result["label"].append(int(label))
|
||||
|
||||
return result
|
||||
def preprocessData(self, result):
|
||||
# 분석을 통해서 볼린저밴드 상/하단을 계산한다.
|
||||
df = self.buySellChecker.getVectorFeature(result)
|
||||
minmax_df1 = (df - df.min()) / (df.max() - df.min())
|
||||
minmax_df2 = minmax_df1.drop(["date"], axis="columns")
|
||||
minmax_df = minmax_df2.join(df['date'])
|
||||
|
||||
minmax_df = minmax_df.fillna(0)
|
||||
return df, minmax_df
|
||||
|
||||
def makeTrainData(self, stock_code):
|
||||
result = {"check": set(), "time": [], "open": [], "close": [], "high": [], "low": [], "vol": [], "label": []}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user