init
This commit is contained in:
@@ -364,20 +364,84 @@ class Analyzer:
|
||||
status += eveningstar_status
|
||||
---------------------------------"""
|
||||
|
||||
# 위치에너지
|
||||
positional_egergy_status = self.common.checkPotentialEnergy(STOCK, i)
|
||||
if positional_egergy_status != "":
|
||||
status += positional_egergy_status
|
||||
|
||||
|
||||
return status, buy_price
|
||||
|
||||
def getPositionalEnergy(self, stock, i):
|
||||
# 350일 중 가장 찾은 금액과 가장 높았던 금액 중 현재가의 위치 계산
|
||||
|
||||
top = stock[i]['close']
|
||||
bottom = stock[i]['close']
|
||||
price = stock[i]['close']
|
||||
|
||||
if len(stock) > 350:
|
||||
for i in range(2, 350):
|
||||
if top < stock[-i]["close"]:
|
||||
top = stock[-i]["close"]
|
||||
|
||||
if stock[-i]["close"] < bottom:
|
||||
bottom = stock[-i]["close"]
|
||||
|
||||
if top - bottom == 0:
|
||||
energy = 100
|
||||
else:
|
||||
energy = (price - bottom) / (top - bottom)
|
||||
|
||||
return round(energy, 2)
|
||||
|
||||
def writeFile(self, fig, state, bolingerband_score, stochastic_score, positionalEnergy, item_name, item_code):
|
||||
|
||||
count = 0
|
||||
if bolingerband_score < 0.15:
|
||||
fileName = self.bolingerband_path
|
||||
fileName = "%s/b(%.2f)__p(%.2f)__s(%.2f)__%s__%s_%s.html" % (fileName, bolingerband_score, positionalEnergy, stochastic_score, state, item_name.replace(" ", ""), item_code)
|
||||
po.write_html(fig, file=fileName, auto_open=False)
|
||||
count += 1
|
||||
|
||||
if stochastic_score < 15:
|
||||
fileName = self.stochastic_path
|
||||
fileName = "%s/s(%.2f)__b(%.2f)__p(%.2f)__%s__%s_%s.html" % (fileName, stochastic_score, bolingerband_score, positionalEnergy, state, item_name.replace(" ", ""), item_code)
|
||||
po.write_html(fig, file=fileName, auto_open=False)
|
||||
|
||||
if positionalEnergy < 0.15:
|
||||
fileName = self.positionalEnergy_path
|
||||
fileName = "%s/p(%.2f)__b(%.2f)__s(%.2f)__%s__%s_%s.html" % (fileName, positionalEnergy, bolingerband_score, stochastic_score, state, item_name.replace(" ", ""), item_code)
|
||||
po.write_html(fig, file=fileName, auto_open=False)
|
||||
count += 1
|
||||
|
||||
if count > 1:
|
||||
fileName = self.outPath
|
||||
fileName = "%s/p(%.2f)__b(%.2f)__s(%.2f)__%s__%s_%s.html" % (fileName, positionalEnergy, bolingerband_score, stochastic_score, state, item_name.replace(" ", ""), item_code)
|
||||
po.write_html(fig, file=fileName, auto_open=False)
|
||||
|
||||
return
|
||||
|
||||
def makeDirectory(self, outPath):
|
||||
self.outPath = outPath
|
||||
if os.path.isdir(outPath):
|
||||
shutil.rmtree(outPath)
|
||||
os.mkdir(outPath)
|
||||
|
||||
self.stochastic_path = outPath + "/stochastic"
|
||||
if os.path.isdir(self.stochastic_path):
|
||||
os.rmdir(self.stochastic_path)
|
||||
os.mkdir(self.stochastic_path)
|
||||
|
||||
self.bolingerband_path = outPath + "/bolingerband"
|
||||
if os.path.isdir(self.bolingerband_path):
|
||||
os.rmdir(self.bolingerband_path)
|
||||
os.mkdir(self.bolingerband_path)
|
||||
|
||||
self.positionalEnergy_path = outPath + "/positionalEnergy"
|
||||
if os.path.isdir(self.positionalEnergy_path):
|
||||
os.rmdir(self.positionalEnergy_path)
|
||||
os.mkdir(self.positionalEnergy_path)
|
||||
|
||||
return
|
||||
|
||||
# 그래프 출력
|
||||
def analyzeToHtml(self, outPath):
|
||||
tmp_path = outPath + "/tmp"
|
||||
if os.path.isdir(tmp_path):
|
||||
os.rmdir(tmp_path)
|
||||
os.mkdir(tmp_path)
|
||||
self.makeDirectory(outPath)
|
||||
|
||||
conn = sqlite3.connect(self.inFileName)
|
||||
cursor = conn.cursor()
|
||||
@@ -425,24 +489,17 @@ class Analyzer:
|
||||
else:
|
||||
bolingerband_score = round(((STOCK[last_index]['close']-BOLINGERBAND[last_index]['lower'])/(BOLINGERBAND[last_index]['upper']-BOLINGERBAND[last_index]['lower'])), 2)
|
||||
|
||||
if stochastic_score < 10 or bolingerband_score < 0.2:
|
||||
positionalEnergy = self.getPositionalEnergy(STOCK, last_index)
|
||||
if stochastic_score < 30 or bolingerband_score < 0.3:
|
||||
if STOCK[last_index]['volume'] > 100000:
|
||||
# 종목 상태 체크 분석
|
||||
state, buy_price = self.analyzeFinalScore(last_index, STOCK, STOCHASTIC)
|
||||
|
||||
# 종목 상태 체크 분석
|
||||
state, buy_price = self.analyzeFinalScore(last_index, STOCK, STOCHASTIC)
|
||||
|
||||
if state != "":
|
||||
fig = self.draw(stock)
|
||||
title = "%s (%s), %s, buy_price (%d), stochastic(%.2f), bolingerband(%.2f) 차트" % (item_name, item_code, state, buy_price, stochastic_score, bolingerband_score)
|
||||
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)
|
||||
fileName = "%s/%s__b(%.2f)__s(%.2f)__%s_%s.html" % (outPath, state, bolingerband_score, 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(%.2f), bolingerband(%.2f) 차트"%(item_name, item_code, buy_price, stochastic_score, bolingerband_score)
|
||||
fig['layout'].update(title=title)
|
||||
fileName = "%s/b(%.2f)__s(%.2f)__%s_%s.html"%(tmp_path, bolingerband_score, stochastic_score, item_name.replace(" ", ""), item_code)
|
||||
po.write_html(fig, file=fileName, auto_open=False)
|
||||
|
||||
self.writeFile(fig, state, bolingerband_score, stochastic_score, positionalEnergy, item_name, item_code)
|
||||
|
||||
rowid += 1
|
||||
cursor.execute('SELECT * FROM ' + self.tableName + ' WHERE rowid=?', (rowid,))
|
||||
|
||||
@@ -519,27 +519,6 @@ class Common:
|
||||
return "arrange_"
|
||||
return ""
|
||||
|
||||
def checkPotentialEnergy(self, stock, i):
|
||||
# 350일 중 가장 찾은 금액과 가장 높았던 금액 중 현재가의 위치 계산
|
||||
|
||||
top = stock[i]['close']
|
||||
bottom = stock[i]['close']
|
||||
price = stock[i]['close']
|
||||
|
||||
if len(stock) > 350:
|
||||
for i in range(2, 350):
|
||||
if top < stock[-i]["close"]:
|
||||
top = stock[-i]["close"]
|
||||
|
||||
if stock[-i]["close"] < bottom:
|
||||
bottom = stock[-i]["close"]
|
||||
|
||||
if top - bottom > 0:
|
||||
energy = (price - bottom) / (top - bottom)
|
||||
if energy < 0.2:
|
||||
return "p(" + str(round(energy, 2)) + ")_"
|
||||
return ""
|
||||
|
||||
def checkHigherUmbong(self, stock, i):
|
||||
# 음봉인데 어제보다 종가가 더 높은 경우
|
||||
# 이 경우 정배열 상태인지도 함께 체크를 한다.
|
||||
|
||||
Reference in New Issue
Block a user