diff --git a/stockpredictor/analysis/Analyzer.py b/stockpredictor/analysis/Analyzer.py index 28853c0..df4137d 100644 --- a/stockpredictor/analysis/Analyzer.py +++ b/stockpredictor/analysis/Analyzer.py @@ -380,7 +380,7 @@ class Analyzer: if ((item_code in self.fnguide and not self.fnguide[item_code]) or (item_code == "KOSPI" or item_code == "KOSDAK") or result[3] == ''): rowid += 1 # 다음 종목을 가져옴 - cursor.execute('SELECT CODE, NAME, PRICE, STOCHASTIC FROM ' + self.tableName + ' WHERE rowid=?', (rowid,)) + cursor.execute('SELECT CODE, NAME, PRICE, STOCHASTIC, BOLINGERBAND FROM ' + self.tableName + ' WHERE rowid=?', (rowid,)) result = cursor.fetchone() continue @@ -389,65 +389,48 @@ class Analyzer: result_3 = result[3].replace("NaN", "0") if result[3]==None: rowid += 1 - cursor.execute('SELECT CODE, NAME, PRICE, STOCHASTIC FROM ' + self.tableName + ' WHERE rowid=?', (rowid,)) + cursor.execute('SELECT CODE, NAME, PRICE, STOCHASTIC, BOLINGERBAND FROM ' + self.tableName + ' WHERE rowid=?', (rowid,)) result = cursor.fetchone() continue - stock = {"CODE": result[0], "NAME": result[1], "PRICE": json.loads(result[2]), "STOCHASTIC": json.loads(result_3)} + stock = {"CODE": result[0], "NAME": result[1], "PRICE": json.loads(result[2]), "STOCHASTIC": json.loads(result_3), "BOLINGERBAND": json.loads(result[4])} last_index = self.get_last_index(stock) STOCK = stock['PRICE'] STOCHASTIC = stock['STOCHASTIC'] + BOLINGERBAND = stock['BOLINGERBAND'] stochastic_score = STOCHASTIC[last_index]['slow_k'] - if stochastic_score < 50: + + # upper: 20, lower: 10 + # 14 = (14-10) / (20-10) = 0.4 + # 18 = (18-10) / (20-10) = 0.8 + # 5 = (5-10) / (20-10) = -0.5 + if BOLINGERBAND[last_index]['upper'] == BOLINGERBAND[last_index]['lower']: + bolingerband_score = 0 + else: + bolingerband_score = round(((STOCK[last_index]['close']-BOLINGERBAND[last_index]['lower'])/(BOLINGERBAND[last_index]['upper']-BOLINGERBAND[last_index]['lower'])), 2) + + + if stochastic_score < 50 and bolingerband_score < 0.5: # 종목 상태 체크 분석 state, buy_price = self.analyzeFinalScore(last_index, STOCK, STOCHASTIC) if state != "": fig = self.draw(stock) - title = "%s (%s), %s, buy_price (%d), stochastic(%.3f) 차트" % (item_name, item_code, state, buy_price, stochastic_score) + title = "%s (%s), %s, buy_price (%d), stochastic(%.3f), bolingerband(%.3f) 차트" % (item_name, item_code, state, buy_price, stochastic_score, bolingerband_score) fig['layout'].update(title=title) - fileName = "%s/%s__%.3f__%s_%s.html" % (outPath, state, stochastic_score, item_name.replace(" ", ""), item_code) + fileName = "%s/%s__%.3f__%.3f__%s_%s.html" % (outPath, state, stochastic_score, bolingerband_score, item_name.replace(" ", ""), item_code) po.write_html(fig, file=fileName, auto_open=False) else: if STOCK[last_index]['volume'] > 1000000: fig = self.draw(stock) - title = "%s (%s) buy_price (%d), stochastic(%.3f) 차트"%(item_name, item_code, buy_price, stochastic_score) + title = "%s (%s) buy_price (%d), stochastic(%.3f), bolingerband(%.3f) 차트"%(item_name, item_code, buy_price, stochastic_score, bolingerband_score) fig['layout'].update(title=title) - fileName = "%s/%.3f__%s_%s.html"%(tmp_path, stochastic_score, item_name.replace(" ", ""), item_code) + fileName = "%s/%.3f__%.3f__%s_%s.html"%(tmp_path, bolingerband_score, stochastic_score, item_name.replace(" ", ""), item_code) po.write_html(fig, file=fileName, auto_open=False) - """ - try: - stock = {"CODE": result[0], "NAME": result[1], "PRICE": json.loads(result[2]), "STOCHASTIC": json.loads(result_3)} - last_index = self.get_last_index(stock) - STOCK = stock['PRICE'] - STOCHASTIC = stock['STOCHASTIC'] - - stochastic_score = STOCHASTIC[last_index]['slow_k'] - if stochastic_score < 50: - - # 종목 상태 체크 분석 - state, buy_price = self.analyzeFinalScore(last_index, STOCK, STOCHASTIC) - - if state != "": - fig = self.draw(stock) - title = "%s (%s), %s, buy_price (%d), stochastic(%.3f) 차트" % (item_name, item_code, state, buy_price, stochastic_score) - fig['layout'].update(title=title) - fileName = "%s/%s__%.3f__%s_%s.html" % (outPath, state, stochastic_score, item_name.replace(" ", ""), item_code) - po.write_html(fig, file=fileName, auto_open=False) - else: - if STOCK[last_index]['volume'] > 1000000: - fig = self.draw(stock) - title = "%s (%s) buy_price (%d), stochastic(%.3f) 차트"%(item_name, item_code, buy_price, stochastic_score) - fig['layout'].update(title=title) - fileName = "%s/%.3f__%s_%s.html"%(tmp_path, stochastic_score, item_name.replace(" ", ""), item_code) - po.write_html(fig, file=fileName, auto_open=False) - except: - print ("error") - """ rowid += 1 cursor.execute('SELECT * FROM ' + self.tableName + ' WHERE rowid=?', (rowid,)) result = cursor.fetchone() @@ -508,7 +491,9 @@ if __name__ == "__main__": analyzer.analyzeStochastic() """ - analyzer.analyze() + ####### + # analyzer.analyze() + ####### day = datetime.today().strftime("%Y%m%d")