This commit is contained in:
dosangyoon
2022-07-31 17:07:29 +09:00
parent cddcdf4f35
commit 5b5e2196c1
8 changed files with 502 additions and 62 deletions

View File

@@ -1,25 +1,22 @@
from math import nan
from datetime import datetime, timedelta
import copy
import pandas as pd
import plotly.graph_objects as go
from plotly import subplots
import sqlite3
import os
from hts.HTS import HTS
from stock.util.Stock2Vector import Stock2Vector
from hts.BuySellChecker import BuySellChecker
class Simulation (HTS):
stock2Vector = None
buySellChecker = None
stock_code = None
def __init__(self, RESOURCE_PATH, stock_code):
def __init__(self, RESOURCE_PATH):
super().__init__(RESOURCE_PATH)
self.stock2Vector = Stock2Vector(RESOURCE_PATH)
self.buySellChecker = BuySellChecker()
self.stock_code = stock_code
self.RESOURCE_PATH = RESOURCE_PATH
#self.connect()
return
@@ -129,30 +126,19 @@ class Simulation (HTS):
return
def getRealTime(self, stock_code, today, LAST_DATA=None):
if LAST_DATA is not None:
result = copy.deepcopy(LAST_DATA)
else:
result = {"check": set(), "time": [], "open": [], "close": [], "high": [], "low": [], "vol": []}
def simulate(self, stock_code, today):
LAST_DATA = self.stock2Vector.getLastData(stock_code, today)
self.getDBData(stock_code, today, result)
return result
def simulate(self, today):
LAST_DATA = self.getLastData(self.stock_code, today)
result = self.getRealTime(self.stock_code, today, LAST_DATA)
result = self.stock2Vector.getRealTime(stock_code, today, LAST_DATA)
# 규칙 기반의 분석을 통해서 볼린저밴드 상/하단을 계산한다.
data = self.buySellChecker.analyzeByRule(result)
# 사야 할 시점과 팔아야 할 시점을 체크한다.
bsLine, data = self.buySellChecker.checkTransaction(data, self.stock_code, False)
bsLine, data = self.buySellChecker.checkTransaction(data, stock_code, False)
# 그래프를 그린다.
self.draw(self.stock_code, today, data, bsLine)
self.draw(stock_code, today, data, bsLine)
return
@@ -165,13 +151,13 @@ if __name__ == "__main__":
stock_codes = {
# 252670
# 122630
"122630": ['20220725'],
"122630": ['20220729'],
}
for stock_code in stock_codes:
simulation = Simulation(RESOURCE_PATH, stock_code)
simulation = Simulation(RESOURCE_PATH)
for given_day in stock_codes[stock_code]:
simulation.simulate(given_day)
simulation.simulate(stock_code, given_day)
print ("done...")