This commit is contained in:
dsyoon
2023-02-11 16:54:05 +09:00
parent 08a606bee1
commit 5c646b3a2f
4 changed files with 84 additions and 16 deletions

View File

@@ -83,10 +83,9 @@ class StockStatus (HTS):
return False
def fetchLastData(self, cursor, stock_code, limit=350):
if cursor is None:
return
stock = {"CODE": stock_code, "NAME": "", "PRICE": []}
if cursor is None:
return stock
sql = 'SELECT ymd, close, diff, open, high, low, volume FROM stock where CODE=? order by ymd desc '
sql += ' limit ' + str(limit)
@@ -558,3 +557,75 @@ class StockStatus (HTS):
po.write_html(fig, file=fileName, auto_open=False)
return
def getCompanyInfo(self):
self.cursor_stock.execute('SELECT distinct code, name FROM stock order by code')
all_stocks = self.cursor_stock.fetchall()
valid_company = set()
self.cursor_stock.execute(
'select CODE, NAME, max(ymd) as ymd from fnguide where type != "E" group by 1 order by total_assets desc')
items = self.cursor_stock.fetchall()
for item in items:
valid_company.add(item[0])
return all_stocks, valid_company
def findCandidates(self, outPath):
dir_name = os.path.join(outPath, "99_daily_auto_trading")
if os.path.isdir(dir_name):
os.rmdir(dir_name)
os.mkdir(dir_name)
today = datetime.today().strftime('%Y%m%d')
stockTableName = 'stock'
conn = sqlite3.connect(os.path.join(self.RESOURCE_PATH, self.dbFileName))
cursor = conn.cursor()
cursor.execute('SELECT distinct code, name FROM ' + stockTableName + ' order by code')
items = cursor.fetchall()
analyzed_day = 120
for idx, item in enumerate(items):
stock_code = item[0]
stock_name = item[1]
if stock_name.find('스팩') >= 0:
continue
print(idx, stock_code, stock_name, ", CODE: ", stock_code, ", NAME: ", stock_name)
stock = self.fetchLastData(cursor, stock_code, limit=350)
data = self.analyze(stock, analyzed_day)
# 분석일 데이터만 활용한다 (이전 데이터는 제거)
data.drop(data.index[:len(data) - analyzed_day], inplace=True)
# print logs
# for i in range(len(data.index)):
# print (i, data.index[i], data['macd'][i], data['slow_k'][i], data['gradients_low'][i], data['gradients_avg5'][i], data['gradients_avg20'][i], data['gradients_avg60'][i], data['disparity_avg5'][i], data['disparity_avg20'][i], data['disparity_avg60'][i], data['disparity'][i], data['disparity_type'][i])
bsLine, data = self.buySellChecker.checkTransactionWithEnvelope(data, stock_code, 120, isRealTime=False)
# 그래프를 그린다.
if len(data.index) > 10 and bsLine['buy'][len(bsLine['buy'])-1] > 0:
self.writeFile(dir_name, stock_code, stock_name, today, data, bsLine)
cursor.close()
conn.close()
return
if __name__ == "__main__":
PROJECT_HOME = os.path.join(os.path.dirname(os.path.join(os.path.dirname(os.path.join(os.path.dirname(__file__))))))
RESOURCE_PATH = os.path.join(PROJECT_HOME, "resources")
outPath = os.path.join(PROJECT_HOME, "resources", "analysis")
if not os.path.isdir(outPath):
os.mkdir(outPath)
day = datetime.today().strftime("%Y%m%d")
outPath = os.path.join(outPath, day)
if os.path.isdir(outPath):
shutil.rmtree(outPath)
os.mkdir(outPath)
stockStatus = StockStatus(RESOURCE_PATH)
stockStatus.findCandidates(outPath)