From 9c2523b192f4b9c6f864b39f93b05df41a0cb2e0 Mon Sep 17 00:00:00 2001 From: dsyoon Date: Sat, 31 Dec 2022 12:40:06 +0900 Subject: [PATCH] init --- stock/analysis/AnalyzerSqlite.py | 96 +++++++++++++++++--------------- 1 file changed, 50 insertions(+), 46 deletions(-) diff --git a/stock/analysis/AnalyzerSqlite.py b/stock/analysis/AnalyzerSqlite.py index 3df7a56..a54ac83 100644 --- a/stock/analysis/AnalyzerSqlite.py +++ b/stock/analysis/AnalyzerSqlite.py @@ -285,7 +285,7 @@ class AnalyzerSqlite: return - def writeFile(self, type, CODE, NAME, top, stock, state, final_status_count=-1): + def writeFile(self, dir_code, dir_name, CODE, NAME, top, stock, state, final_status_count): # 3년 이내 한번이라도 영업이익이 났는지 체크를 함 fnguide = None if CODE in self.fnguide: @@ -302,11 +302,14 @@ class AnalyzerSqlite: title = "%s (%s), %d, %s 차트 (URL1, URL2)" % (NAME, CODE, stock['close'][0], type, CODE, CODE) fig['layout'].update(title=title) - fileName = self.outPath + "/" + str(type) - if final_status_count == -1: - fileName = "%s/%s_%s_%s_%s.html" % (fileName, top, NAME.replace(" ", ""), CODE, state) - else: + fileName = self.outPath + "/" + dir_code+"_"+dir_name + + if dir_code == "0": fileName = "%s/%s_%s_%s_%s_%s.html" % (fileName, str(final_status_count), top, NAME.replace(" ", ""), CODE, state) + elif dir_code == "25": # 낙폭과대 + fileName = "%s/%s_%s_%s_%s.html" % (fileName, state, NAME.replace(" ", ""), CODE, top) + else: + fileName = "%s/%s_%s_%s_%s.html" % (fileName, top, NAME.replace(" ", ""), CODE, state) po.write_html(fig, file=fileName, auto_open=False) return @@ -466,37 +469,37 @@ class AnalyzerSqlite: if (stock_monthly['avg6'][1] is not None and stock_monthly['avg36'][1] is not None and stock_monthly['avg6'][0] is not None and stock_monthly['avg36'][0] is not None): if stock_monthly['avg6'][1] <= stock_monthly['avg36'][1] and stock_monthly['avg6'][0] > stock_monthly['avg36'][0]: - type = "monthly_6월선_36월선_상향돌파" - final_status += " " + type + dir_code = "1" + dir_name = "monthly_6월선_36월선_상향돌파" final_status_count += 1 - self.writeFile(type, CODE, NAME, top, stock_monthly, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_monthly, status) # 종가가 20주선을 상향 돌파함 if len(stock_monthly['close']) > 2: if stock_monthly['close'][1] is not None and stock_monthly['avg12'][1] is not None and stock_monthly['close'][0] is not None and stock_monthly['avg12'][0] is not None: if stock_monthly['close'][1] <= stock_monthly['avg12'][1] and stock_monthly['close'][0] > stock_monthly['avg12'][0]: - type = "monthly_종가_12월선_상향돌파" - final_status += " " + type + dir_code = "2" + dir_name = "monthly_종가_12월선_상향돌파" final_status_count += 1 - self.writeFile(type, CODE, NAME, top, stock_monthly, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_monthly, status) # MACD가 0 이하인 경우 if len(stock_monthly['close']) > 1: if stock_monthly['macd'][0] is not None: if stock_monthly['macd'][0] <= -300: - type = "monthly_macd_-300이하" - final_status += " " + type + dir_code = "3" + dir_name = "monthly_macd_-300이하" final_status_count += 1 - self.writeFile(type, CODE, NAME, top, stock_monthly, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_monthly, status) # RSI가 20 이하인 경우 if len(stock_monthly['close']) > 1: if stock_monthly['rsi'][0] is not None: if stock_monthly['rsi'][0] <= 20: - type = "monthly_rsi_20이하" - final_status += " " + type + dir_code = "4" + dir_name = "monthly_rsi_20이하" final_status_count += 1 - self.writeFile(type, CODE, NAME, top, stock_monthly, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_monthly, status) if len(stock_monthly['volume']) > 5: # BB 하단에 부딪힘 @@ -504,10 +507,10 @@ class AnalyzerSqlite: if stock_monthly['bolingerband_lower'][c_index+1] is None: break if stock_monthly['close'][c_index] <= (stock_monthly['bolingerband_lower'][c_index+1]): - type = "monthly_BB하단_내려옴" - final_status += " " + type + dir_code = "5" + dir_name = "monthly_BB하단_내려옴" final_status_count += 1 - self.writeFile(type, CODE, NAME, top, stock_monthly, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_monthly, status) break @@ -526,28 +529,28 @@ class AnalyzerSqlite: if (stock_weekly['avg4'][1] is not None and stock_weekly['avg48'][1] is not None and stock_weekly['avg4'][0] is not None and stock_weekly['avg48'][0] is not None): if stock_weekly['avg4'][1] <= stock_weekly['avg48'][1] and stock_weekly['avg4'][0] > stock_weekly['avg48'][0]: - type = "weekly_4주선_48주선_상향돌파" - final_status += " " + type + dir_code = "11" + dir_name = "weekly_4주선_48주선_상향돌파" final_status_count += 1 - self.writeFile(type, CODE, NAME, top, stock_weekly, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_weekly, status) # 종가가 20주선을 상향 돌파함 if len(stock_weekly['close']) > 2: if stock_weekly['close'][1] is not None and stock_weekly['avg12'][1] is not None and stock_weekly['close'][0] is not None and stock_weekly['avg12'][0] is not None: if stock_weekly['close'][1] <= stock_weekly['avg12'][1] and stock_weekly['close'][0] > stock_weekly['avg12'][0]: - type = "weekly_종가_12주선_상향돌파" - final_status += " " + type + dir_code = "12" + dir_name = "weekly_종가_12주선_상향돌파" final_status_count += 1 - self.writeFile(type, CODE, NAME, top, stock_weekly, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_weekly, status) # RSI가 15 이하인 경우 if len(stock_monthly['close']) > 1: if stock_weekly['rsi'][0] is not None: if stock_weekly['rsi'][0] <= 15: - type = "weekly_rsi_15이하" - final_status += " " + type + dir_code = "13" + dir_name = "weekly_rsi_15이하" final_status_count += 1 - self.writeFile(type, CODE, NAME, top, stock_weekly, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_weekly, status) @@ -558,38 +561,38 @@ class AnalyzerSqlite: # RSI가 10 이하인 경우 if stock_daily['macd'][0] is not None: if stock_daily['macd'][0] <= -500: - type = "daily_macd_-500이하" - final_status += " " + type + dir_code = "21" + dir_name = "daily_macd_-500이하" final_status_count += 1 - self.writeFile(type, CODE, NAME, top, stock_daily, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_daily, status) # 2년 중 최대 거래량인 경우 c_index = 520 if len(stock_daily['volume']) < c_index: c_index = len(stock_daily['volume']) if max(stock_daily['volume'][1:c_index]) < stock_daily['volume'][0]: - type = "daily_이전에_없던_거래량" - final_status += " " + type + dir_code = "22" + dir_name = "daily_이전에_없던_거래량" final_status_count += 1 - self.writeFile(type, CODE, NAME, top, stock_daily, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_daily, status) # daily_이격도 if (98 1: if stock_monthly['rsi'][0] is not None and stock_weekly['rsi'][0] is not None and stock_daily['rsi'][0] is not None: if stock_monthly['rsi'][0] <= 30 and stock_weekly['rsi'][0] <= 20 and stock_daily['rsi'][0] <= 10: - type = "daily_weekly_monthly_rsi_10_20_30이하" - final_status += " " + type + dir_code = "24" + dir_name = "daily_weekly_monthly_rsi_10_20_30이하" final_status_count += 1 - self.writeFile(type, CODE, NAME, top, stock_daily, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_daily, status) # daily_낙폭과대 (50% 이상 하락) c_index = 52*5 @@ -601,15 +604,16 @@ class AnalyzerSqlite: location = (max(stock_daily['close'][1:c_index]) - stock_daily['close'][0]) / max(stock_daily['close'][1:c_index]) if location > 0.5: - type = "daily_낙폭과대" - final_status += " " + type + dir_code = "25" + dir_name = "daily_낙폭과대" final_status_count += 1 status = "{:.2f}".format(location) + "_" + status - self.writeFile(type, CODE, NAME, top, stock_daily, status) + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_daily, status) if final_status_count >= 5: - type = "final" - self.writeFile(type, CODE, NAME, top, stock_daily, final_status, final_status_count) + dir_code = "0" + dir_name = "final" + self.writeFile(dir_code, dir_name, CODE, NAME, top, stock_daily, final_status, final_status_count) return def get_moving_average(self, stock):