From 2d4f759ab63d987439acba618ce9926337875503 Mon Sep 17 00:00:00 2001 From: "dosang.yoon" Date: Mon, 24 Jan 2022 01:19:23 +0900 Subject: [PATCH] init --- stockpredictor/analysis/Analyzer.py | 84 +++++++++++++---------------- 1 file changed, 36 insertions(+), 48 deletions(-) diff --git a/stockpredictor/analysis/Analyzer.py b/stockpredictor/analysis/Analyzer.py index 8d2f0de..3642b67 100644 --- a/stockpredictor/analysis/Analyzer.py +++ b/stockpredictor/analysis/Analyzer.py @@ -399,31 +399,26 @@ class Analyzer: return energy - def writeFile(self, fig, state, isbuy, buy_price, bolingerband_score, stochastic_score, positionalEnergy, item_name, item_code): + def writeFile(self, fig, state, buy_price, bolingerband_score, stochastic_score, positionalEnergy, item_name, item_code): if state != "": fileName = self.status_path - fileName = "%s/%d__%s__p(%.2f)__b(%.2f)__s(%.2f)__%d__%s_%s.html" % (fileName, isbuy, state, positionalEnergy, bolingerband_score, stochastic_score, buy_price, item_name.replace(" ", ""), item_code) + fileName = "%s/%s__p(%.2f)__b(%.2f)__s(%.2f)__%d__%s_%s.html" % (fileName, state, positionalEnergy, bolingerband_score, stochastic_score, buy_price, item_name.replace(" ", ""), item_code) po.write_html(fig, file=fileName, auto_open=False) if bolingerband_score < 0.15: fileName = self.bolingerband_path - fileName = "%s/%d__b(%.2f)__p(%.2f)__s(%.2f)__%s__%d__%s_%s.html" % (fileName, isbuy, bolingerband_score, positionalEnergy, stochastic_score, state, buy_price, item_name.replace(" ", ""), item_code) + fileName = "%s/b(%.2f)__p(%.2f)__s(%.2f)__%s__%d__%s_%s.html" % (fileName, bolingerband_score, positionalEnergy, stochastic_score, state, buy_price, item_name.replace(" ", ""), item_code) po.write_html(fig, file=fileName, auto_open=False) if stochastic_score < 15: fileName = self.stochastic_path - fileName = "%s/%d__s(%.2f)__b(%.2f)__p(%.2f)__%s__%d__%s_%s.html" % (fileName, isbuy, stochastic_score, bolingerband_score, positionalEnergy, state, buy_price, item_name.replace(" ", ""), item_code) + fileName = "%s/s(%.2f)__b(%.2f)__p(%.2f)__%s__%d__%s_%s.html" % (fileName, stochastic_score, bolingerband_score, positionalEnergy, state, buy_price, item_name.replace(" ", ""), item_code) po.write_html(fig, file=fileName, auto_open=False) if positionalEnergy < 0.5: fileName = self.positionalEnergy_path - fileName = "%s/%d__p(%.2f)__b(%.2f)__s(%.2f)__%s__%d__%s_%s.html" % (fileName, isbuy, positionalEnergy, bolingerband_score, stochastic_score, state, buy_price, item_name.replace(" ", ""), item_code) - po.write_html(fig, file=fileName, auto_open=False) - - if isbuy > 0: - fileName = self.outPath - fileName = "%s/%d__p(%.2f)__b(%.2f)__s(%.2f)__%s__%d__%s_%s.html" % (fileName, isbuy, positionalEnergy, bolingerband_score, stochastic_score, state, buy_price, item_name.replace(" ", ""), item_code) + fileName = "%s/p(%.2f)__b(%.2f)__s(%.2f)__%s__%d__%s_%s.html" % (fileName, positionalEnergy, bolingerband_score, stochastic_score, state, buy_price, item_name.replace(" ", ""), item_code) po.write_html(fig, file=fileName, auto_open=False) return @@ -520,55 +515,48 @@ class Analyzer: # 종목 상태 체크 분석 state, buy_price = self.analyzeFinalScore(last_index, STOCK, STOCHASTIC) - isbuy = 0 + # 스토케스틱이 20이하이어야 하며, 볼린저밴드 0.3 보다 작으며, 위치에너지도 0.3보다 낮다면, + if stochastic_score < 20 and bolingerband_score < 0.3 and positionalEnergy < 0.3 and len(STOCK) > 5: + state = '1_' + state - # 스토케스틱이 20이하이어야 하며, 볼린저밴드 0.3 보다 작으며, 위치에너지도 0.2보다 낮다면, - if stochastic_score < 20 and bolingerband_score < 0.2 and positionalEnergy < 0.2: - isbuy = 1 + # 종가가 240일선 아래라면 매수한다. + if STOCK[last_index]['close'] < STOCK[last_index]['avg240']: + state = '2_' + state - # 종가가 240일선 아래라면 매수한다. - if STOCK[last_index]['close'] < STOCK[last_index]['avg240']: - isbuy = 2 + # 볼린저밴드 하단에 부딪혔다면, + if (STOCK[last_index - 2]['low'] <= BOLINGERBAND[last_index - 2]['lower'] <= STOCK[last_index - 2]['high'] or + STOCK[last_index - 3]['low'] <= BOLINGERBAND[last_index - 3]['lower'] <= STOCK[last_index - 3]['high']): - if len(STOCK) > 5: - - # 볼린저밴드 하단에 부딪혔다면, - if (STOCK[last_index - 2]['low'] <= BOLINGERBAND[last_index - 2]['lower'] <= STOCK[last_index - 2]['high'] or - STOCK[last_index - 3]['low'] <= BOLINGERBAND[last_index - 3]['lower'] <= STOCK[last_index - 3]['high']): - - # 어제 양봉이거나 - # 음봉이라면 그저깨 종가보다 어제 시가가 높거나 같고 그저깨 시가보다 어제 종가가 높다. - # 음봉이라면 그저깨 시가보다 어제 시가가 높거나 같고 그저깨 종가보다 어제 종가가 높다. - if STOCK[last_index-1]['open'] < STOCK[last_index-1]['close'] or ( - (STOCK[last_index-2]['close'] <= STOCK[last_index-1]['open'] and STOCK[last_index-2]['open'] < STOCK[last_index-1]['close']) or - (STOCK[last_index-2]['open'] <= STOCK[last_index-1]['open'] and STOCK[last_index-2]['close'] < STOCK[last_index-1]['close'])): - # (KOSPI: 2011년 8월 11일) - # 오늘 양봉이어야 한다. - if STOCK[last_index]['open'] < STOCK[last_index]['close']: - isbuy = 3 - # (KOSPI: 2011년 9월 26일) - # 오늘 음봉이라면, 오늘 시가는 어제 종가보다 높아야 하고, 오늘 종가는 어제 시가보다 높아야 한다. - if (STOCK[last_index]['close'] < STOCK[last_index]['open']) and (STOCK[last_index-1]['close'] < STOCK[last_index]['open'] and STOCK[last_index-1]['open'] < STOCK[last_index]['close']): - isbuy = 4 - - if isbuy==4 and stochastic_score < 10 and bolingerband_score < 0.1 and positionalEnergy < 0.1: - isbuy = 5 - - if (STOCHASTIC[last_index]['slow_k'] < 15 and - STOCHASTIC[last_index-1]['slow_k'] < STOCHASTIC[last_index-1]['slow_d'] and - STOCHASTIC[last_index]['slow_d'] < STOCHASTIC[last_index]['slow_k']): - isbuy = 9 + # 어제 양봉이거나 + # 음봉이라면 그저깨 종가보다 어제 시가가 높거나 같고 그저깨 시가보다 어제 종가가 높다. + # 음봉이라면 그저깨 시가보다 어제 시가가 높거나 같고 그저깨 종가보다 어제 종가가 높다. + if STOCK[last_index-1]['open'] < STOCK[last_index-1]['close'] or ( + (STOCK[last_index-2]['close'] <= STOCK[last_index-1]['open'] and STOCK[last_index-2]['open'] < STOCK[last_index-1]['close']) or + (STOCK[last_index-2]['open'] <= STOCK[last_index-1]['open'] and STOCK[last_index-2]['close'] < STOCK[last_index-1]['close'])): + # (KOSPI: 2011년 8월 11일) + # 오늘 양봉이어야 한다. + if STOCK[last_index]['open'] < STOCK[last_index]['close']: + state = '3_' + state + # (KOSPI: 2011년 9월 26일) + # 오늘 음봉이라면, 오늘 시가는 어제 종가보다 높아야 하고, 오늘 종가는 어제 시가보다 높아야 한다. + if (STOCK[last_index]['close'] < STOCK[last_index]['open']) and (STOCK[last_index-1]['close'] < STOCK[last_index]['open'] and STOCK[last_index-1]['open'] < STOCK[last_index]['close']): + state = '4_' + state if (STOCHASTIC[last_index]['slow_k'] < 15 and - STOCHASTIC[last_index - 1]['slow_k'] < STOCHASTIC[last_index - 1]['slow_d'] and + STOCHASTIC[last_index-1]['slow_k'] < STOCHASTIC[last_index-1]['slow_d'] and STOCHASTIC[last_index]['slow_d'] < STOCHASTIC[last_index]['slow_k']): - isbuy = 8 + state = '5_' + state + + if (STOCHASTIC[last_index]['slow_k'] < 15 and + STOCHASTIC[last_index - 1]['slow_k'] < STOCHASTIC[last_index - 1]['slow_d'] and + STOCHASTIC[last_index]['slow_d'] < STOCHASTIC[last_index]['slow_k']): + state = '6_' + state fig = self.draw(stock) title = "%s (%s), %s, buy_price (%d), stochastic(%.2f), bolingerband(%.2f), positionalEnergy(%.2f) 차트" % (item_name, item_code, state, buy_price, stochastic_score, bolingerband_score, positionalEnergy) fig['layout'].update(title=title) - self.writeFile(fig, state, isbuy, buy_price, bolingerband_score, stochastic_score, positionalEnergy, item_name, item_code) + self.writeFile(fig, state, buy_price, bolingerband_score, stochastic_score, positionalEnergy, item_name, item_code) for check_index in range(365): if len(STOCK) > check_index and STOCK[last_index-check_index]['open'] < STOCK[last_index-check_index]['close']: