From cdd2adfd31ce63f342bb05fb321249ab32b5babf Mon Sep 17 00:00:00 2001 From: dsyoon Date: Tue, 24 Jan 2023 20:42:30 +0900 Subject: [PATCH] init --- HTS_daily.py | 1 + hts/BuySellChecker.py | 233 +++++------------------------------------- hts/OrderChecker.py | 14 +++ 3 files changed, 42 insertions(+), 206 deletions(-) diff --git a/HTS_daily.py b/HTS_daily.py index 67dce98..e7486c9 100644 --- a/HTS_daily.py +++ b/HTS_daily.py @@ -141,6 +141,7 @@ class HTS_DAILY (HTS): if bsLine['sell'][last_index] > 0: bs_sell_price = bsLine['sell'][last_index] orderNum = self.getSellingPrice(THIS_TIME, self.stock_code, bs_sell_price) + self.orderChecker.delete(today, stock_code) # 로그 출력 print("SELL", THIS_TIME.strftime('%Y%m%d %H%M%S'), orderNum, stock_code, stock_name, bs_sell_price) diff --git a/hts/BuySellChecker.py b/hts/BuySellChecker.py index f757075..86bd625 100644 --- a/hts/BuySellChecker.py +++ b/hts/BuySellChecker.py @@ -943,68 +943,27 @@ class BuySellChecker: size = len(data["close"]) bsLine['buy'] = [-1 for i in range(size)] - bsLine['buy_weight'] = [-1 for i in range(size)] + bsLine['buy_weight'] = [-1.0 for i in range(size)] bsLine['sell'] = [-1 for i in range(size)] - bsLine['sell_weight'] = [-1 for i in range(size)] + bsLine['sell_weight'] = [-1.0 for i in range(size)] for i in range(size): if isRealTime: if i < size - 1: continue - """ - # 이전에 산 가격보다 지금 5원이상 떨어졌다면 매도 한다. - price = data['close'][i] if data['close'][i] >= data['open'][i] else data['open'][i] - if self.checkBelow5WonFromPreviousBuyPrice(i, data, price): - data['sell'][i] = price - bsLine['sell'][i] = price - bsLine['sell_weight'][i] = 50 - return bsLine, data - """ - - """ - # middle line에 맞다은 적 없이, low line에 붙었거나 아래에 있었던 캔들의 높은 가격을 얻어옴 - buy, buy_weight = self.getBuyPriceAndWeight_Envelope(i, data) - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = buy_weight - return bsLine, data - """ - - - if 0 < data['gradients_avg60'][i] < 0.001: - if data['high'][i] < data['envelope_middle'][i]: - if -0.015 < data['gradients_avg5'][i] and -0.007 < data['gradients_avg20'][i]: - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 10 - if i > 10: - if ( - data['gradients_avg60'][i - 10] > 0 and data['gradients_avg60'][i - 9] > 0 and data['gradients_avg60'][i - 8] > 0 and - data['gradients_avg60'][i - 7] > 0 and data['gradients_avg60'][i - 6] > 0 and data['gradients_avg60'][i - 5] > 0 and - data['gradients_avg60'][i - 4] > 0 and data['gradients_avg60'][i - 3] > 0 and data['gradients_avg60'][i - 2] > 0 and - data['gradients_avg60'][i - 1] > 0 and data['gradients_avg60'][i] < 0 - ): - if data['disparity'][i] < 3: - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 10 - - if i > 10: - if data['disparity_avg60'][i] < 65: - buy = data['low'][i] + if data['avg5'][i-1] < data['avg20'][i-1] and data['avg20'][i] < data['avg5'][i]: + buy = data['close'][i] data['buy'][i] = buy bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 20 + bsLine['buy_weight'][i] = 5.0 if data['slow_k'][i] < 3: - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 10 + sell = data['close'][i] + data['sell'][i] = sell + bsLine['sell'][i] = sell + bsLine['sell_weight'][i] = 100.0 return bsLine, data @@ -1015,9 +974,9 @@ class BuySellChecker: size = len(data["close"]) bsLine['buy'] = [-1 for i in range(size)] - bsLine['buy_weight'] = [-1 for i in range(size)] + bsLine['buy_weight'] = [-1.0 for i in range(size)] bsLine['sell'] = [-1 for i in range(size)] - bsLine['sell_weight'] = [-1 for i in range(size)] + bsLine['sell_weight'] = [-1.0 for i in range(size)] for i in range(size): if isRealTime: @@ -1025,24 +984,17 @@ class BuySellChecker: continue if i > 10: - if data['disparity_avg60'][i] < 60: - buy = data['low'][i] + if data['avg5'][i - 1] < data['avg20'][i - 1] and data['avg20'][i] < data['avg5'][i]: + buy = data['close'][i] data['buy'][i] = buy bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 15 + bsLine['buy_weight'][i] = 5.0 - if data['macd'][i] < -1000: - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 15 - - if data['slow_k'][i] < 7: - if data['slow_d'][i] < data['slow_k'][i]: - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 5 + if data['slow_k'][i] < 3: + sell = data['close'][i] + data['sell'][i] = sell + bsLine['sell'][i] = sell + bsLine['sell_weight'][i] = 100.0 return bsLine, data @@ -1071,154 +1023,23 @@ class BuySellChecker: bsLine['sell'] = [-1 for i in range(size)] bsLine['sell_weight'] = [-1 for i in range(size)] - gap_interval = analyzed_day - gap_state = False for i in range(size): if isRealTime: if i < size - 1: continue if i > 10: - # 만약 전일 저가와 오늘 종의 차이가 1만원이 넘으면 향후 60일은 분석하지 않는다. - if data['high'][i] < int(data['low'][i-1] * 0.7): - gap_state = True - gap_interval -= 1 - continue - if gap_state: - if gap_interval <= 0: - gap_state = False - gap_interval = 60 - else: - gap_interval -= 1 - continue - - if data['disparity'][i] < 2: - check = True - for l in range(i-3, i): - if ( - data['gradients_avg60'][l-1] > data['gradients_avg60'][l] or - data['gradients_avg20'][l-1] > data['gradients_avg20'][l] or - data['gradients_low'][l-1] > data['gradients_low'][l] or - data['disparity_avg5'][l-1] > data['disparity_avg5'][l] or - data['disparity'][l-1] < data['disparity'][l] - ): - check = False - break - if check and 99 < sum(data['disparity_avg5'][i-4:i+1])/5 < 100 and 99 < sum(data['disparity_avg60'][i-4:i+1])/5 < 100: - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 20 - - check = True - for l in range(i - 2, i): - if ( - data['gradients_avg60'][l - 1] > data['gradients_avg60'][l] or - data['gradients_low'][l - 1] > data['gradients_low'][l] - ): - check = False - break - if ( - check and - -0.0011 < data['gradients_low'][i] < 0 and -0.007 < data['gradients_avg5'][i] < 0.001 and - -0.0012 < data['gradients_avg60'][i] < 0 and - 98.90 < data['disparity_avg5'][i] < 101 - ): - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 20 - - check = True - for l in range(i - 6, i): - if ( - data['gradients_avg60'][l - 1] < data['gradients_avg60'][l] or - data['gradients_avg20'][l - 1] < data['gradients_avg20'][l] or - data['gradients_low'][l - 1] < data['gradients_low'][l] or - -0.039 < data['gradients_low'][l - 1] < -0.35 or - -0.05 < data['gradients_avg20'][l - 1] < -0.30 or - -0.40 < data['gradients_avg60'][l - 1] < -0.30 - ): - check = False - break - if check and 99 < min (data['disparity_avg5'][i - 6:i]) < max (data['disparity_avg5'][i - 6:i]) < 101: - buy = data['low'][i] + if data['avg5'][i - 1] < data['avg20'][i - 1] and data['avg20'][i] < data['avg5'][i]: + buy = data['close'][i] data['buy'][i] = buy bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 20 - - check = True - for l in range(i - 3, i): - if ( - data['gradients_low'][l - 1] < data['gradients_low'][l] or - data['gradients_avg60'][l - 1] < data['gradients_avg60'][l] or - data['gradients_avg20'][l - 1] < data['gradients_avg20'][l] or - 0.01 < data['gradients_low'][l - 1] < 0.21 or - -0.09 < data['gradients_avg20'][l - 1] < -0.002 or - 0.01 < data['gradients_avg60'][l - 1] < 0.021 - ): - check = False - break - if check: - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 20 - - - if (data['disparity'][i] < 5 and 99.0 < data['disparity_avg60'][i] < 99.1 and - -0.009 < data['gradients_avg60'][i] < -0.008 and 0.015 < data['gradients_avg20'][i] < 0.016 and - -0.006 < data['gradients_avg5'][i] < -0.005 and -0.009 < data['gradients_low'][i] < -0.008): - check = True - for l in range(i-5, i): - if ( - data['gradients_avg60'][l-1] > data['gradients_avg60'][l] or - data['gradients_low'][l-1] > data['gradients_low'][l] or - data['disparity'][l - 1] < data['disparity'][l] - ): - check = False - break - if check: - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 20 - - if data['macd'][i] < -4000: - if data['macd'][i-1] < data['macd'][i]: - if not self.notBuy(data, i) and data['slow_k'][i] < 30: - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 20 - - # macd 이전에 없던 바닥인 경우 상승할 찰나 매수 - if data['macds'][i-1] < min(data['macds'][:i-1]): - if data['macds'][i-1] < data['macds'][i]: - if not self.notBuy(data, i) and data['slow_k'][i] < 30: - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 20 - - if ( - 98 < data['disparity_avg5'][i] < 100 and data['disparity_avg20'][i] < 93.5 and data['disparity_avg60'][i] < 89 and - -0.014 < data['gradients_avg60'][i] < -0.013 and -0.03 < data['gradients_avg20'][i] < -0.02 and -0.014 < data['gradients_low'][i] < -0.013 and - data['slow_k'][i] < 11 - ): - if not self.notBuy(data, i): - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 20 - - - if data['slow_k'][i]<20 and data['slow_k'][i-1] < data['slow_d'][i-1] and data['slow_d'][i] < data['slow_k'][i]: - buy = data['low'][i] - data['buy'][i] = buy - bsLine['buy'][i] = buy - bsLine['buy_weight'][i] = 30 + bsLine['buy_weight'][i] = 3.0 + if data['slow_k'][i] < 3: + sell = data['close'][i] + data['sell'][i] = sell + bsLine['sell'][i] = sell + bsLine['sell_weight'][i] = 100.0 return bsLine, data diff --git a/hts/OrderChecker.py b/hts/OrderChecker.py index 3d1bced..ad86ca9 100644 --- a/hts/OrderChecker.py +++ b/hts/OrderChecker.py @@ -37,6 +37,7 @@ class OrderChecker: def add(self, ymd, stock_code, type, orderNum, count, price): if self.exist(stock_code): return False + # 새로운 주문을 추가한다. self.order_df = self.order_df.append({"stock_code": stock_code, "type": type, "orderNum": orderNum, "count": count, "price": price, "datetime": datetime.now()}, ignore_index=True) @@ -45,3 +46,16 @@ class OrderChecker: self.order_df.to_csv(saveFileName) return True + + def delete(self, ymd, stock_code): + if not self.exist(stock_code): + return False + + # 매도 주문을 삭제한다. + self.order_df = self.order_df.loc[(self.order_df["stock_code"] != stock_code)] + + # 파일로 기록한다. + saveFileName = os.path.join(self.RESOURCE_PATH, "order", ymd + ".csv") + self.order_df.to_csv(saveFileName) + + return True \ No newline at end of file