init
This commit is contained in:
@@ -245,17 +245,129 @@ class BuySellChecker:
|
|||||||
buy = data["Low"][i]
|
buy = data["Low"][i]
|
||||||
weight = 1
|
weight = 1
|
||||||
|
|
||||||
|
|
||||||
return buy, weight, sell
|
return buy, weight, sell
|
||||||
|
|
||||||
def getPriceAndWeight2(self, data, i):
|
def getPriceAndWeight2(self, data, i):
|
||||||
buy, weight, sell = -1, -1, -1
|
buy, weight, sell = -1, -1, -1
|
||||||
|
|
||||||
if data["slow_k"][i] < 25:
|
################
|
||||||
buy = data["Low"][i]
|
### sell 분석 ###
|
||||||
if data["slow_k"][i] > 90:
|
################
|
||||||
|
# 1. 볼린져밴드 상단이 최고와 종가 사이 아래에 있는 경우 매도한다.
|
||||||
|
if (data["High"][i] - data["Close"][i]) / 2 + data["Close"][i] > data["upper"][i]:
|
||||||
sell = data["High"][i]
|
sell = data["High"][i]
|
||||||
|
|
||||||
|
if data["slow_k"][i] >= 85:
|
||||||
|
if data["slow_d"][i - 1] < data["slow_k"][i - 1] and data["slow_k"][i] < data["slow_d"][i]:
|
||||||
|
sell = data["High"][i]
|
||||||
|
|
||||||
|
# 3. 2시 이후에는 최고가가 볼린져밴드 상단 위에 있으면 매도한다.
|
||||||
|
if i > 300 and data["High"][i] > data["upper"][i]:
|
||||||
|
sell = data["High"][i]
|
||||||
|
|
||||||
|
##########################
|
||||||
|
### STOCHASTIC buy 분석 ###
|
||||||
|
##########################
|
||||||
|
if i < 40:
|
||||||
|
pre_slow = data["slow_k"][i - 1] / data["slow_d"][i - 1] - 1
|
||||||
|
now_slow = data["slow_k"][i] / data["slow_d"][i] - 1
|
||||||
|
if pre_slow < 0 and 0 < now_slow:
|
||||||
|
if data["slow_k"][i] <= 20:
|
||||||
|
if (data["Close"][i] - data["lower"][i]) / (data["upper"][i] - data["lower"][i]) < 0.1:
|
||||||
|
if data["slow_k"][i - 1] < data["slow_d"][i - 1] and data["slow_d"][i] < data["slow_k"][i]:
|
||||||
|
if data["Close"][i] < data["avg5"][i]:
|
||||||
|
buy = data["Close"][i]
|
||||||
|
else:
|
||||||
|
buy = data["Low"][i]
|
||||||
|
else:
|
||||||
|
pre_slow = data["slow_k"][i - 1] / data["slow_d"][i - 1] - 1
|
||||||
|
now_slow = data["slow_k"][i] / data["slow_d"][i] - 1
|
||||||
|
if pre_slow < 0 and pre_slow < now_slow and -0.15 < now_slow:
|
||||||
|
if data["slow_k"][i] <= 20:
|
||||||
|
if (data["Close"][i] - data["lower"][i]) / (data["upper"][i] - data["lower"][i]) < 0.35:
|
||||||
|
if data["slow_k"][i - 1] < data["slow_d"][i - 1] and data["slow_d"][i] < data["slow_k"][i]:
|
||||||
|
if data["Close"][i] < data["avg5"][i]:
|
||||||
|
buy = data["Close"][i]
|
||||||
|
else:
|
||||||
|
buy = data["Low"][i]
|
||||||
|
|
||||||
|
#############################
|
||||||
|
### STOCHASTIC weight 분석 ###
|
||||||
|
#############################
|
||||||
|
if data["slow_k"][i] in (0, 1, 2, 3):
|
||||||
|
weight = 1
|
||||||
|
if data["slow_k"][i] in (4, 5, 6, 7, 8):
|
||||||
|
weight = 1
|
||||||
|
elif data["slow_k"][i] in (9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20):
|
||||||
|
weight = 1
|
||||||
|
elif data["slow_k"][i] in (21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35):
|
||||||
|
weight = 1
|
||||||
|
|
||||||
|
return buy, weight, sell
|
||||||
|
|
||||||
|
def getPriceAndWeight3(self, data, i):
|
||||||
|
buy, weight, sell = -1, -1, -1
|
||||||
|
|
||||||
|
################
|
||||||
|
### sell 분석 ###
|
||||||
|
################
|
||||||
|
# 1. 볼린져밴드 상단이 최고와 종가 사이 아래에 있는 경우 매도한다.
|
||||||
|
if (data["High"][i] - data["Close"][i]) / 2 + data["Close"][i] > data["upper"][i]:
|
||||||
|
sell = data["High"][i]
|
||||||
|
|
||||||
|
if data["slow_k"][i] >= 85:
|
||||||
|
if data["slow_d"][i - 1] < data["slow_k"][i - 1] and data["slow_k"][i] < data["slow_d"][i]:
|
||||||
|
sell = data["High"][i]
|
||||||
|
|
||||||
|
# 3. 2시 이후에는 최고가가 볼린져밴드 상단 위에 있으면 매도한다.
|
||||||
|
if i > 300 and data["High"][i] > data["upper"][i]:
|
||||||
|
sell = data["High"][i]
|
||||||
|
|
||||||
|
##########################
|
||||||
|
### STOCHASTIC buy 분석 ###
|
||||||
|
##########################
|
||||||
|
if i < 40:
|
||||||
|
pre_slow = data["slow_k"][i - 1] / data["slow_d"][i - 1] - 1
|
||||||
|
now_slow = data["slow_k"][i] / data["slow_d"][i] - 1
|
||||||
|
if data["slow_d"][i - 2] > data["slow_d"][i - 1] and data["slow_d"][i - 1] < data["slow_d"][i]:
|
||||||
|
if abs(data["slow_d"][i]-data["slow_k"][i]) < abs(data["slow_d"][i-1]-data["slow_k"][i-1]):
|
||||||
|
if now_slow < 0.15:
|
||||||
|
if data["Close"][i] < data["avg5"][i]:
|
||||||
|
buy = data["Close"][i]
|
||||||
|
else:
|
||||||
|
buy = data["Low"][i]
|
||||||
|
if data["slow_k"][i-1] < data["slow_d"][i-1] and data["slow_d"][i] < data["slow_k"][i]:
|
||||||
|
if abs(now_slow) < 0.001:
|
||||||
|
if now_slow < 0.15:
|
||||||
|
if data["Close"][i] < data["avg5"][i]:
|
||||||
|
buy = data["Close"][i]
|
||||||
|
else:
|
||||||
|
buy = data["Low"][i]
|
||||||
|
else:
|
||||||
|
if i > 60:
|
||||||
|
print (1)
|
||||||
|
pre_slow = data["slow_k"][i - 1] / data["slow_d"][i - 1] - 1
|
||||||
|
now_slow = data["slow_k"][i] / data["slow_d"][i] - 1
|
||||||
|
if pre_slow < 0 and pre_slow < now_slow and -0.15 < now_slow:
|
||||||
|
if data["slow_k"][i] <= 20:
|
||||||
|
if (data["Close"][i] - data["lower"][i]) / (data["upper"][i] - data["lower"][i]) < 0.35:
|
||||||
|
if data["Close"][i] < data["avg5"][i]:
|
||||||
|
buy = data["Close"][i]
|
||||||
|
else:
|
||||||
|
buy = data["Low"][i]
|
||||||
|
|
||||||
|
#############################
|
||||||
|
### STOCHASTIC weight 분석 ###
|
||||||
|
#############################
|
||||||
|
if data["slow_k"][i] in (0, 1, 2, 3):
|
||||||
|
weight = 1
|
||||||
|
if data["slow_k"][i] in (4, 5, 6, 7, 8):
|
||||||
|
weight = 1
|
||||||
|
elif data["slow_k"][i] in (9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20):
|
||||||
|
weight = 1
|
||||||
|
elif data["slow_k"][i] in (21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35):
|
||||||
|
weight = 1
|
||||||
|
|
||||||
return buy, weight, sell
|
return buy, weight, sell
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -547,7 +547,7 @@ class HTS_252670:
|
|||||||
|
|
||||||
def buyRealTime(self, stock_code, GIVEN_DAY):
|
def buyRealTime(self, stock_code, GIVEN_DAY):
|
||||||
orderChecker = OrderChecker(stock_code)
|
orderChecker = OrderChecker(stock_code)
|
||||||
BASE_COUNT = 200
|
BASE_COUNT = 400
|
||||||
|
|
||||||
timecheckList = pd.read_csv("timecheck.csv").values.tolist()
|
timecheckList = pd.read_csv("timecheck.csv").values.tolist()
|
||||||
timecheck = {GIVEN_DAY + " " + str(second).zfill(6):False for second, check in timecheckList}
|
timecheck = {GIVEN_DAY + " " + str(second).zfill(6):False for second, check in timecheckList}
|
||||||
|
|||||||
@@ -173,7 +173,8 @@ if __name__ == "__main__":
|
|||||||
given_days = ['20210901','20210902','20210903','20210906','20210907','20210908','20210909','20210910','20210913',
|
given_days = ['20210901','20210902','20210903','20210906','20210907','20210908','20210909','20210910','20210913',
|
||||||
'20210914','20210915','20210916','20210917','20210923','20210924','20210927','20210928','20210929',
|
'20210914','20210915','20210916','20210917','20210923','20210924','20210927','20210928','20210929',
|
||||||
'20210930','20211001','20211005','20211006','20211007','20211008','20211012','20211013','20211014',
|
'20210930','20211001','20211005','20211006','20211007','20211008','20211012','20211013','20211014',
|
||||||
'20211018', '20211019','20211020','20211021']
|
'20211018', '20211019','20211020','20211021','20211022']
|
||||||
|
|
||||||
simulation = Simulation()
|
simulation = Simulation()
|
||||||
|
|
||||||
given_days = sorted(given_days, reverse=True)
|
given_days = sorted(given_days, reverse=True)
|
||||||
|
|||||||
@@ -518,29 +518,22 @@ class Analyzer:
|
|||||||
isbuy = 0
|
isbuy = 0
|
||||||
|
|
||||||
# 스토케스틱이 20이하이어야 하며, 볼린저밴드 0.3 보다 작으며, 위치에너지도 0.2보다 낮다면,
|
# 스토케스틱이 20이하이어야 하며, 볼린저밴드 0.3 보다 작으며, 위치에너지도 0.2보다 낮다면,
|
||||||
if stochastic_score < 30 and bolingerband_score < 0.3 and positionalEnergy < 0.5:
|
if stochastic_score < 30 and bolingerband_score < 0.3 and positionalEnergy < 0.3:
|
||||||
isbuy = 1
|
isbuy = 1
|
||||||
|
|
||||||
# 위치에너지가 낮거나 240일선 아래에 있는 상태에서 상태값을 갖는 경우 매수한다.
|
|
||||||
if state != "":
|
|
||||||
isbuy = 2
|
|
||||||
|
|
||||||
# 종가가 240일선 아래라면 매수한다.
|
# 종가가 240일선 아래라면 매수한다.
|
||||||
if STOCK[last_index]['close'] < STOCK[last_index]['avg240']:
|
if STOCK[last_index]['close'] < STOCK[last_index]['avg240']:
|
||||||
if state == "":
|
if state == "":
|
||||||
isbuy = 3
|
isbuy = 2
|
||||||
else:
|
else:
|
||||||
isbuy = 4
|
isbuy = 3
|
||||||
|
|
||||||
if len(STOCK) > 5:
|
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'] or
|
|
||||||
STOCK[last_index-4]['low'] <= BOLINGERBAND[last_index-4]['lower'] <= STOCK[last_index-4]['high']):
|
|
||||||
"""
|
|
||||||
if (STOCK[last_index - 2]['low'] <= BOLINGERBAND[last_index - 2]['lower'] <= STOCK[last_index - 2]['high'] or
|
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']):
|
STOCK[last_index - 3]['low'] <= BOLINGERBAND[last_index - 3]['lower'] <= STOCK[last_index - 3]['high']):
|
||||||
|
|
||||||
# 어제 양봉이거나
|
# 어제 양봉이거나
|
||||||
# 음봉이라면 그저깨 종가보다 어제 시가가 높거나 같고 그저깨 시가보다 어제 종가가 높다.
|
# 음봉이라면 그저깨 종가보다 어제 시가가 높거나 같고 그저깨 시가보다 어제 종가가 높다.
|
||||||
# 음봉이라면 그저깨 시가보다 어제 시가가 높거나 같고 그저깨 종가보다 어제 종가가 높다.
|
# 음봉이라면 그저깨 시가보다 어제 시가가 높거나 같고 그저깨 종가보다 어제 종가가 높다.
|
||||||
@@ -550,15 +543,25 @@ class Analyzer:
|
|||||||
# (KOSPI: 2011년 8월 11일)
|
# (KOSPI: 2011년 8월 11일)
|
||||||
# 오늘 양봉이어야 한다.
|
# 오늘 양봉이어야 한다.
|
||||||
if STOCK[last_index]['open'] < STOCK[last_index]['close']:
|
if STOCK[last_index]['open'] < STOCK[last_index]['close']:
|
||||||
isbuy = 5
|
isbuy = 4
|
||||||
# (KOSPI: 2011년 9월 26일)
|
# (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']):
|
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 = 5
|
isbuy = 5
|
||||||
|
|
||||||
if isbuy==4 and stochastic_score < 30 and bolingerband_score < 0.3 and positionalEnergy < 0.5:
|
if isbuy==5 and stochastic_score < 10 and bolingerband_score < 0.1 and positionalEnergy < 0.1:
|
||||||
|
isbuy = 6
|
||||||
|
|
||||||
|
if (STOCHASTIC[last_index]['slow_k'] < 30 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
|
isbuy = 9
|
||||||
|
|
||||||
|
if (STOCHASTIC[last_index]['slow_k'] < 30 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
|
||||||
|
|
||||||
fig = self.draw(stock)
|
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)
|
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)
|
fig['layout'].update(title=title)
|
||||||
|
|||||||
Reference in New Issue
Block a user