diff --git a/HTS_etf_122630.py b/HTS_etf_122630.py index 2b91f80..7df8d11 100644 --- a/HTS_etf_122630.py +++ b/HTS_etf_122630.py @@ -144,7 +144,7 @@ class HTS_etf(HTS): # 미체결 기록을 가져와서 10분 이상 된 매수 주문을 취소 한다. 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: self.cancelOrderList(orderListToCancel) diff --git a/HTS_etf_252670.py b/HTS_etf_252670.py index 1463d70..95337cc 100644 --- a/HTS_etf_252670.py +++ b/HTS_etf_252670.py @@ -145,7 +145,7 @@ class HTS_etf(HTS): # 미체결 기록을 가져와서 10분 이상 된 매수 주문을 취소 한다. 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: self.cancelOrderList(orderListToCancel) diff --git a/Simulation.py b/Simulation.py index e903bff..cb4e952 100644 --- a/Simulation.py +++ b/Simulation.py @@ -37,7 +37,8 @@ class Simulation (HTS): data = data.loc[pd.DatetimeIndex(data.index).day == int(given_day[6:])] buy_line = bsLine['buy'][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', @@ -73,13 +74,25 @@ class Simulation (HTS): buy_colors.append("#0C752E") buy_size.append(10 + (5 * buy_weight_line[i])) + sell_size = [] sell_colors = [] for i in range(len(sell_line)): if sell_line[i] < 0: sell_colors.append("#ffffff") sell_line[i] = nan + sell_size.append(0) else: 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)) @@ -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) #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_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') 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, avg200, buy_check, sell_check] + #candle_data = [candle_stick, avg200, buy_check, sell_check] volume_data = [volume_line] disparity_data = [disparity_avg5, disparity_avg20, disparity_avg30, disparity_avg60, disparity_avg120, disparity_avg200] macd_data = [macd_line, macd_s_line, macd_o_line] @@ -136,20 +149,20 @@ class Simulation (HTS): fig = subplots.make_subplots( rows=6, cols=1, - subplot_titles=("거래량", "이격도", "스토캐스틱", "RSI", "MACD", '캔들'), + subplot_titles=("이격도", "스토캐스틱", "RSI", "MACD", "거래량", '캔들'), #specs=[[{}], [{}], [{}], [{}], [{}], [{}]], shared_xaxes=True, horizontal_spacing=0.03, vertical_spacing=0.01, row_heights=[200, 200, 200, 200, 200, 700] ) - for trace in volume_data: - fig.append_trace(trace, 1, 1) for trace in disparity_data: - fig.append_trace(trace, 2, 1) + fig.append_trace(trace, 1, 1) for trace in stochastic_data: - fig.append_trace(trace, 3, 1) + fig.append_trace(trace, 2, 1) for trace in rsi_data: - fig.append_trace(trace, 4, 1) + fig.append_trace(trace, 3, 1) for trace in macd_data: + fig.append_trace(trace, 4, 1) + for trace in volume_data: fig.append_trace(trace, 5, 1) for trace in candle_data: fig.append_trace(trace, 6, 1) @@ -234,12 +247,12 @@ if __name__ == "__main__": # to check bying stock_codes = { - "252670": ['20231012'], - "122630": ['20231012'], - #"252670": ['20210901','20210902','20210903','20210906'], - #"252670": ['20210901', '20210902', '20210903', '20210906', '20210907', '20210908', '20210909', '20210910', '20210913', '20210914', '20210915', '20210916', '20210917', '20210923', '20210924', '20210927', '20210928', '20210929', '20210930', '20211001', '20211005'], - #"122630": ['20220901', '20220902', '20220905', '20220906'] - #"122630": ['20210901', '20210902', '20210903', '20210906', '20210907', '20210908', '20210909', '20210910', '20210913', '20210914', '20210915', '20210916', '20210917', '20210923', '20210924', '20210927', '20210928', '20210929', '20210930', '20211001', '20211005'], + #"252670": ['20210930'], + #"122630": ['20230930'], + #"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','20231012','20231013'], + #"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','20231012','20231013'], } #simulation.simulate(stock_codes) simulation.simulate(stock_codes) diff --git a/hts/BuySellChecker.py b/hts/BuySellChecker.py index 8b5cf84..694db2c 100644 --- a/hts/BuySellChecker.py +++ b/hts/BuySellChecker.py @@ -221,32 +221,44 @@ class BuySellChecker: def getBuyPriceAndWeight(self, i, data): buy, weight = -1, -1 - # 1) 스토캐스틱 과매도 - slow_k_buy = False - for idx in range(i, i-10, -1): - if data['slow_k'][idx] < 20: - slow_k_buy = True - break + if i < 40: + return buy, weight - # 2) macd 교차 신호 - macd_buy = False - if slow_k_buy: - 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 + max_vol_5 = max(data['volume'].to_list()[i - 4: i + 1]) + max_vol_30 = max(data['volume'].to_list()[i - 24: i - 4]) + if max_vol_30 < max_vol_5: + if data['open'][i-1] < data['close'][i-1] and data['volume'][i-1] < data['volume'][i]: + #if data['open'][i - 1] < data['close'][i - 1] and data['volume'][i - 1] < data['volume'][i]: + + # 1) 스토캐스틱 과매도 + slow_k_buy = False + for idx in range(i, i-10, -1): + if data['slow_k'][idx] < 20: + slow_k_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 + # 2) macd 교차 신호 + macd_buy = False + if slow_k_buy: + 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']) - 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 - + """ + 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