This commit is contained in:
dsyoon
2023-01-15 14:56:34 +09:00
parent 5821f7bfa5
commit 11593dd324
8 changed files with 752 additions and 798 deletions

View File

@@ -1,4 +1,3 @@
import numpy as np
from math import nan
import pandas as pd
import plotly.graph_objects as go
@@ -9,6 +8,7 @@ from hts.HTS import HTS
from stock.util.Stock2Vector import Stock2Vector
from stock.util.LabelChecker import LabelChecker
from stock.util.StockPredictor import StockPredictor
from stock.analysis.DailyStatus import DailyStatus
from hts.BuySellChecker import BuySellChecker
class Simulation (HTS):
@@ -163,36 +163,24 @@ class Simulation (HTS):
return
def simulate(self, stock_code, today, method="rule"):
def simulate(self, stock_codes:dict=None):
if method == "answer":
#self.labelMaker.makeCandidate(stock_code, today, view=True)
self.labelChecker.showLabels(stock_code, today)
if stock_codes is not None:
for stock_code in stock_codes:
for given_day in stock_codes[stock_code]:
LAST_DATA = self.stock2Vector.getLastData(stock_code, given_day)
result = self.stock2Vector.getRealTime(stock_code, given_day, LAST_DATA)
# 이동평균, RSI, MACD, 일목균형, 볼린저밴드 상/하단을 계산한다.
data = self.buySellChecker.analyze(result)
# 사야 할 시점과 팔아야 할 시점을 체크한다.
bsLine, data = self.buySellChecker.checkTransaction(data, stock_code, isRealTime=False)
# 그래프를 그린다.
self.draw(stock_code, given_day, data, bsLine)
else:
if method == "ml":
LAST_DATA = self.stock2Vector.getLastData(stock_code, today, n=3)
result = self.stock2Vector.getRealTime(stock_code, today, LAST_DATA)
X, Y = self.stock2Vector.getVectorData(result)
predY = self.stockPredictor.predict(X, Y)
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:
LAST_DATA = self.stock2Vector.getLastData(stock_code, today)
result = self.stock2Vector.getRealTime(stock_code, today, LAST_DATA)
# 이동평균, RSI, MACD, 일목균형, 볼린저밴드 상/하단을 계산한다.
data = self.buySellChecker.analyze(result)
# 사야 할 시점과 팔아야 할 시점을 체크한다.
bsLine, data = self.buySellChecker.checkTransaction(data, stock_code, isRealTime=False)
if data is not None:
# 그래프를 그린다.
self.draw(stock_code, today, data, bsLine)
dailyStatus = DailyStatus(self.RESOURCE_PATH)
dailyStatus.checkEnvelope()
return
@@ -201,6 +189,8 @@ if __name__ == "__main__":
PROJECT_HOME = os.getcwd()
RESOURCE_PATH = os.path.join(PROJECT_HOME, "resources")
simulation = Simulation(RESOURCE_PATH)
# to check bying
stock_codes = {
"252670": [
@@ -208,24 +198,7 @@ if __name__ == "__main__":
'20220908','20220913','20220914','20220915','20220916'
]
}
"""
# 122630
"252670": [
'20220801', '20220802', '20220803', '20220804', '20220805',
'20220808', '20220809', '20220810', '20220811', '20220812',
'20220816', '20220817', '20220818', '20220819', '20220822',
'20220823', '20220824', '20220825', '20220826', '20220829',
'20220830', '20220831',
'20220901', '20220902', '20220905', '20220906','20220907',
'20220908'
],
"""
method = "rule" # "rule", "ml", "answer"
for stock_code in stock_codes:
simulation = Simulation(RESOURCE_PATH)
for given_day in stock_codes[stock_code]:
simulation.simulate(stock_code, given_day, method=method)
#simulation.simulate(stock_codes)
simulation.simulate()
print ("done...")