init
This commit is contained in:
@@ -144,7 +144,7 @@ class HTS_etf(HTS):
|
|||||||
|
|
||||||
# 미체결 기록을 가져와서 10분 이상 된 매수 주문을 취소 한다.
|
# 미체결 기록을 가져와서 10분 이상 된 매수 주문을 취소 한다.
|
||||||
ORDER_LIST = self.requestOrderList()
|
ORDER_LIST = self.requestOrderList()
|
||||||
orderListToCancel = self.orderChecker.cancel(today, "A" + stock_code, ORDER_LIST, mins=10)
|
orderListToCancel = self.orderChecker.cancel(today, "A" + stock_code, ORDER_LIST, mins=30)
|
||||||
if len(orderListToCancel) > 0:
|
if len(orderListToCancel) > 0:
|
||||||
self.cancelOrderList(orderListToCancel)
|
self.cancelOrderList(orderListToCancel)
|
||||||
|
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ class HTS_etf(HTS):
|
|||||||
|
|
||||||
# 미체결 기록을 가져와서 10분 이상 된 매수 주문을 취소 한다.
|
# 미체결 기록을 가져와서 10분 이상 된 매수 주문을 취소 한다.
|
||||||
ORDER_LIST = self.requestOrderList()
|
ORDER_LIST = self.requestOrderList()
|
||||||
orderListToCancel = self.orderChecker.cancel(today, "A" + stock_code, ORDER_LIST, mins=10)
|
orderListToCancel = self.orderChecker.cancel(today, "A" + stock_code, ORDER_LIST, mins=30)
|
||||||
if len(orderListToCancel) > 0:
|
if len(orderListToCancel) > 0:
|
||||||
self.cancelOrderList(orderListToCancel)
|
self.cancelOrderList(orderListToCancel)
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ class Simulation (HTS):
|
|||||||
data = data.loc[pd.DatetimeIndex(data.index).day == int(given_day[6:])]
|
data = data.loc[pd.DatetimeIndex(data.index).day == int(given_day[6:])]
|
||||||
buy_line = bsLine['buy'][len(bsLine['buy'])-len(data):]
|
buy_line = bsLine['buy'][len(bsLine['buy'])-len(data):]
|
||||||
buy_weight_line = bsLine['buy_weight'][len(bsLine['buy'])-len(data):]
|
buy_weight_line = bsLine['buy_weight'][len(bsLine['buy'])-len(data):]
|
||||||
sell_line = bsLine['sell'][len(bsLine['buy'])-len(data):]
|
sell_line = bsLine['sell'][len(bsLine['sell'])-len(data):]
|
||||||
|
sell_weight_line = bsLine['sell_weight'][len(bsLine['sell']) - len(data):]
|
||||||
|
|
||||||
# 그래프 설정을 위한 변수를 생성한다.
|
# 그래프 설정을 위한 변수를 생성한다.
|
||||||
data = data.astype({'open': 'int',
|
data = data.astype({'open': 'int',
|
||||||
@@ -73,13 +74,25 @@ class Simulation (HTS):
|
|||||||
buy_colors.append("#0C752E")
|
buy_colors.append("#0C752E")
|
||||||
buy_size.append(10 + (5 * buy_weight_line[i]))
|
buy_size.append(10 + (5 * buy_weight_line[i]))
|
||||||
|
|
||||||
|
sell_size = []
|
||||||
sell_colors = []
|
sell_colors = []
|
||||||
for i in range(len(sell_line)):
|
for i in range(len(sell_line)):
|
||||||
if sell_line[i] < 0:
|
if sell_line[i] < 0:
|
||||||
sell_colors.append("#ffffff")
|
sell_colors.append("#ffffff")
|
||||||
sell_line[i] = nan
|
sell_line[i] = nan
|
||||||
|
sell_size.append(0)
|
||||||
else:
|
else:
|
||||||
sell_colors.append("#00ced1")
|
sell_colors.append("#00ced1")
|
||||||
|
sell_size.append(10 + (5 * sell_weight_line[i]))
|
||||||
|
|
||||||
|
volume_colors = []
|
||||||
|
for i in range(len(buy_line)):
|
||||||
|
if data['open'][i] > data['close'][i]:
|
||||||
|
volume_colors.append("#0000FF")
|
||||||
|
elif data['open'][i] < data['close'][i]:
|
||||||
|
volume_colors.append("#FF0000")
|
||||||
|
else:
|
||||||
|
volume_colors.append("#000000")
|
||||||
|
|
||||||
# 그래프를 설정한다.
|
# 그래프를 설정한다.
|
||||||
buy_check = go.Scatter(x=data['date'], y=buy_line, mode='markers', name="buy", marker=dict(size=buy_size, color=buy_colors, line_width=0))
|
buy_check = go.Scatter(x=data['date'], y=buy_line, mode='markers', name="buy", marker=dict(size=buy_size, color=buy_colors, line_width=0))
|
||||||
@@ -98,7 +111,7 @@ class Simulation (HTS):
|
|||||||
|
|
||||||
candle_stick = go.Candlestick(x=data['date'], open=data['open'], high=data['high'], low=data['low'], close=data['close'], increasing_line_color='red', decreasing_line_color='blue', showlegend=False)
|
candle_stick = go.Candlestick(x=data['date'], open=data['open'], high=data['high'], low=data['low'], close=data['close'], increasing_line_color='red', decreasing_line_color='blue', showlegend=False)
|
||||||
#volume_line = go.Scatter(x=data['date'], y=data["volume"], mode='lines', name='volume')
|
#volume_line = go.Scatter(x=data['date'], y=data["volume"], mode='lines', name='volume')
|
||||||
volume_line = go.Bar(x=data['date'], y=data["volume"], marker_color='red', name='volume')
|
volume_line = go.Bar(x=data['date'], y=data["volume"], marker_color=volume_colors, name='volume')
|
||||||
|
|
||||||
disparity_avg5 = go.Scatter(x=data['date'], y=data["disparity_avg5"], name="disparity_avg5", line_color='#F81191')
|
disparity_avg5 = go.Scatter(x=data['date'], y=data["disparity_avg5"], name="disparity_avg5", line_color='#F81191')
|
||||||
disparity_avg20 = go.Scatter(x=data['date'], y=data["disparity_avg20"], name="disparity_avg20", line_color='#097F19')
|
disparity_avg20 = go.Scatter(x=data['date'], y=data["disparity_avg20"], name="disparity_avg20", line_color='#097F19')
|
||||||
@@ -118,9 +131,9 @@ class Simulation (HTS):
|
|||||||
rsi_line = go.Scatter(x=data['date'], y=data["rsi"], line=dict(color='red', width=2), name='rsi')
|
rsi_line = go.Scatter(x=data['date'], y=data["rsi"], line=dict(color='red', width=2), name='rsi')
|
||||||
rsis_line = go.Scatter(x=data['date'], y=data["rsis"], line=dict(dash='dashdot', color='black', width=2), name='rsis')
|
rsis_line = go.Scatter(x=data['date'], y=data["rsis"], line=dict(dash='dashdot', color='black', width=2), name='rsis')
|
||||||
|
|
||||||
candle_data = [candle_stick, upper, lower, avg5, avg20, avg30, avg60, avg120, avg200, buy_check, sell_check, laggingSpan, changeLine, baseLine]
|
#candle_data = [candle_stick, upper, lower, avg5, avg20, avg30, avg60, avg120, avg200, buy_check, sell_check, laggingSpan, changeLine, baseLine]
|
||||||
candle_data = [candle_stick, avg5, avg20, avg30, avg60, avg200, buy_check, sell_check]
|
candle_data = [candle_stick, avg5, avg20, avg30, avg60, avg200, buy_check, sell_check]
|
||||||
candle_data = [candle_stick, avg200, buy_check, sell_check]
|
#candle_data = [candle_stick, avg200, buy_check, sell_check]
|
||||||
volume_data = [volume_line]
|
volume_data = [volume_line]
|
||||||
disparity_data = [disparity_avg5, disparity_avg20, disparity_avg30, disparity_avg60, disparity_avg120, disparity_avg200]
|
disparity_data = [disparity_avg5, disparity_avg20, disparity_avg30, disparity_avg60, disparity_avg120, disparity_avg200]
|
||||||
macd_data = [macd_line, macd_s_line, macd_o_line]
|
macd_data = [macd_line, macd_s_line, macd_o_line]
|
||||||
@@ -136,20 +149,20 @@ class Simulation (HTS):
|
|||||||
|
|
||||||
fig = subplots.make_subplots(
|
fig = subplots.make_subplots(
|
||||||
rows=6, cols=1,
|
rows=6, cols=1,
|
||||||
subplot_titles=("거래량", "이격도", "스토캐스틱", "RSI", "MACD", '캔들'),
|
subplot_titles=("이격도", "스토캐스틱", "RSI", "MACD", "거래량", '캔들'),
|
||||||
#specs=[[{}], [{}], [{}], [{}], [{}], [{}]],
|
#specs=[[{}], [{}], [{}], [{}], [{}], [{}]],
|
||||||
shared_xaxes=True, horizontal_spacing=0.03, vertical_spacing=0.01,
|
shared_xaxes=True, horizontal_spacing=0.03, vertical_spacing=0.01,
|
||||||
row_heights=[200, 200, 200, 200, 200, 700]
|
row_heights=[200, 200, 200, 200, 200, 700]
|
||||||
)
|
)
|
||||||
for trace in volume_data:
|
|
||||||
fig.append_trace(trace, 1, 1)
|
|
||||||
for trace in disparity_data:
|
for trace in disparity_data:
|
||||||
fig.append_trace(trace, 2, 1)
|
fig.append_trace(trace, 1, 1)
|
||||||
for trace in stochastic_data:
|
for trace in stochastic_data:
|
||||||
fig.append_trace(trace, 3, 1)
|
fig.append_trace(trace, 2, 1)
|
||||||
for trace in rsi_data:
|
for trace in rsi_data:
|
||||||
fig.append_trace(trace, 4, 1)
|
fig.append_trace(trace, 3, 1)
|
||||||
for trace in macd_data:
|
for trace in macd_data:
|
||||||
|
fig.append_trace(trace, 4, 1)
|
||||||
|
for trace in volume_data:
|
||||||
fig.append_trace(trace, 5, 1)
|
fig.append_trace(trace, 5, 1)
|
||||||
for trace in candle_data:
|
for trace in candle_data:
|
||||||
fig.append_trace(trace, 6, 1)
|
fig.append_trace(trace, 6, 1)
|
||||||
@@ -234,12 +247,12 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# to check bying
|
# to check bying
|
||||||
stock_codes = {
|
stock_codes = {
|
||||||
"252670": ['20231012'],
|
#"252670": ['20210930'],
|
||||||
"122630": ['20231012'],
|
#"122630": ['20230930'],
|
||||||
#"252670": ['20210901','20210902','20210903','20210906'],
|
#"252670": ['20210903','20210910','20210913'],
|
||||||
#"252670": ['20210901', '20210902', '20210903', '20210906', '20210907', '20210908', '20210909', '20210910', '20210913', '20210914', '20210915', '20210916', '20210917', '20210923', '20210924', '20210927', '20210928', '20210929', '20210930', '20211001', '20211005'],
|
"252670": ['20210901', '20210902', '20210903', '20210906', '20210907', '20210908', '20210909', '20210910', '20210913', '20210914', '20210915', '20210916', '20210917', '20210923', '20210924', '20210927', '20210928', '20210929', '20210930', '20211001', '20211005','20231012','20231013'],
|
||||||
#"122630": ['20220901', '20220902', '20220905', '20220906']
|
#"122630": ['20210901','20210902','20210903','20210906','20231012','20231013']
|
||||||
#"122630": ['20210901', '20210902', '20210903', '20210906', '20210907', '20210908', '20210909', '20210910', '20210913', '20210914', '20210915', '20210916', '20210917', '20210923', '20210924', '20210927', '20210928', '20210929', '20210930', '20211001', '20211005'],
|
#"122630": ['20210901', '20210902', '20210903', '20210906', '20210907', '20210908', '20210909', '20210910', '20210913', '20210914', '20210915', '20210916', '20210917', '20210923', '20210924', '20210927', '20210928', '20210929', '20210930', '20211001', '20211005','20231012','20231013'],
|
||||||
}
|
}
|
||||||
#simulation.simulate(stock_codes)
|
#simulation.simulate(stock_codes)
|
||||||
simulation.simulate(stock_codes)
|
simulation.simulate(stock_codes)
|
||||||
|
|||||||
@@ -221,32 +221,44 @@ class BuySellChecker:
|
|||||||
def getBuyPriceAndWeight(self, i, data):
|
def getBuyPriceAndWeight(self, i, data):
|
||||||
buy, weight = -1, -1
|
buy, weight = -1, -1
|
||||||
|
|
||||||
# 1) 스토캐스틱 과매도
|
if i < 40:
|
||||||
slow_k_buy = False
|
return buy, weight
|
||||||
for idx in range(i, i-10, -1):
|
|
||||||
if data['slow_k'][idx] < 20:
|
|
||||||
slow_k_buy = True
|
|
||||||
break
|
|
||||||
|
|
||||||
# 2) macd 교차 신호
|
max_vol_5 = max(data['volume'].to_list()[i - 4: i + 1])
|
||||||
macd_buy = False
|
max_vol_30 = max(data['volume'].to_list()[i - 24: i - 4])
|
||||||
if slow_k_buy:
|
if max_vol_30 < max_vol_5:
|
||||||
for idx in range(i, i-10, -1):
|
if data['open'][i-1] < data['close'][i-1] and data['volume'][i-1] < data['volume'][i]:
|
||||||
if data['macd'][idx - 1] < 0 and data['macds'][idx - 1] < 0 and data['macd'][idx] < 0 and data['macds'][idx] < 0:
|
#if data['open'][i - 1] < data['close'][i - 1] and data['volume'][i - 1] < data['volume'][i]:
|
||||||
if data['macd'][idx-1] < data['macds'][idx-1] and data['macd'][idx] > data['macds'][idx]:
|
|
||||||
macd_buy = True
|
# 1) 스토캐스틱 과매도
|
||||||
|
slow_k_buy = False
|
||||||
|
for idx in range(i, i-10, -1):
|
||||||
|
if data['slow_k'][idx] < 20:
|
||||||
|
slow_k_buy = True
|
||||||
break
|
break
|
||||||
|
|
||||||
# 3) RSI 지수가 50위로 올라갈 때
|
# 2) macd 교차 신호
|
||||||
if macd_buy:
|
macd_buy = False
|
||||||
if data['rsi'][i-1] < 40 and data['rsi'][i] > 40:
|
if slow_k_buy:
|
||||||
buy, weight = data['close'][i] , 1
|
for idx in range(i, i-10, -1):
|
||||||
|
if data['macd'][idx - 1] < 0 and data['macds'][idx - 1] < 0 and data['macd'][idx] < 0 and data['macds'][idx] < 0:
|
||||||
|
if data['macd'][idx-1] < data['macds'][idx-1] and data['macd'][idx] > data['macds'][idx]:
|
||||||
|
macd_buy = True
|
||||||
|
break
|
||||||
|
|
||||||
|
# 3) RSI 지수가 50위로 올라갈 때
|
||||||
|
if macd_buy:
|
||||||
|
if data['rsi'][i-1] < 40 and data['rsi'][i] > 40:
|
||||||
|
buy, weight = data['close'][i] , 1
|
||||||
|
|
||||||
|
"""
|
||||||
min_macd = min(data['macd'])
|
min_macd = min(data['macd'])
|
||||||
if i > 30 and data['macd'][i] < min_macd + (-min_macd * 0.5):
|
if i > 30 and data['macd'][i] < min_macd + (-min_macd * 0.4):
|
||||||
buy, weight = data['close'][i], 1
|
buy, weight = data['close'][i], 1
|
||||||
|
"""
|
||||||
|
if data['macd'][i] < -4:
|
||||||
|
if data['open'][i - 1] < data['close'][i - 1] and data['volume'][i - 1] < data['volume'][i]:
|
||||||
|
buy, weight = data['close'][i], 1
|
||||||
return buy, weight
|
return buy, weight
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user