from hts.BuySellChecker import BuySellChecker class BuySellChecker_233740 (BuySellChecker): def __init__(self): super().__init__() return def getBuyPriceAndWeight(self, stock_code, i, data, INFO): buy, weight, type = -1, -1, "" """ #매수전략 #0: 기준선 위에서 골든크로스 if (0 < data['macd'][i] and 0 < data['macds'][i]): if (data['macd'][i-1] < data['macds'][i-1] and data['macds'][i] < data['macd'][i]): canBuy = False for c in range(1, 11): if data['macd'][i - c] < 0: canBuy = True break if canBuy: weight = 1 buy = data['close'][i] type = 'method0' """ # 매수전략 #1: 깊은 하락 if (data['macd'][i]<-1000) and (data['macdo'][i-1] <= 0 and 0 < data['macdo'][i]): if data['close'][i] < data['avg200'][i]: weight = 0.5 buy = data['close'][i] type = 'method1' # 매수전략 #2: RSI 과매도 이후 골든크로스 if (data['macd'][i - 1] < data['macds'][i - 1] and data['macds'][i] < data['macd'][i]): canBuy = False for c in range(1, 11): if data['rsi'][i-c] < 10: canBuy = True break if canBuy: weight = 3 buy = data['close'][i] type = 'method2' # 매수전략 #3: 다이버전스 if (data['macd'][i - 1] < data['macds'][i - 1] and data['macds'][i] < data['macd'][i]): canBuy = False index = 0 for c in range(1, 41): if data['macd'][i-c-1] < data['macds'][i-c-1] and data['macds'][i-c] < data['macd'][i-c]: canBuy = True index = c break if canBuy and data['rsi'][i-index] < 30: if (data['macd'][i-index] < data['macd'][i] and min(data['open'][i], data['close'][i]) < min(data['open'][i-index], data['close'][i-index])): weight = 2 buy = data['close'][i] type = 'method3' return buy, weight def getSellPriceAndWeight(self, stock_code, i, data, INFO): sell, weight, type = -1, -1, "" # 매수전략 #1: 높은 상승 if (650 < data['macd'][i] or 600 < data['macds'][i]) and (0 < data['macdo'][i-1] and data['macdo'][i] <= 0): #if data['macds'][i-1] < data['macd'][i-1] and data['macd'][i] < data['macds'][i]: weight = 1 sell = data['close'][i] type = 'method1' # 매수전략 #2: RSI 과매수에서 데드크로스 if (data['macds'][i - 1] < data['macd'][i - 1] and data['macd'][i] < data['macds'][i]): if 80 < data['rsi'][i]: weight = 1 sell = data['close'][i] type = 'method2' return sell, weight def checkTransaction(self, stock_code, data, INFO, isRealTime=True): # 어제 오늘 데이터로 분석 bsLine = {} if data is not None and 'close' in data.columns: size = len(data["close"]) if isRealTime: # isRealTime=True, 실시간 적용 last_index = size - 1 buy, buy_weight = self.getBuyPriceAndWeight(stock_code, last_index, data, INFO) sell, sell_weight = self.getSellPriceAndWeight(stock_code, last_index, data, INFO) bsLine['buy'] = [buy] bsLine['buy_weight'] = [buy_weight] bsLine['sell'] = [sell] bsLine['sell_weight'] = [sell_weight] else: # Type=False, 시뮬레이션 적용 bsLine['buy'] = [-1 for i in range(size)] bsLine['buy_weight'] = [-1 for i in range(size)] bsLine['sell'] = [-1 for i in range(size)] bsLine['sell_weight'] = [-1 for i in range(size)] for last_index in range(size): buy, buy_weight = self.getBuyPriceAndWeight(stock_code, last_index, data, INFO) sell, sell_weight = self.getSellPriceAndWeight(stock_code, last_index, data, INFO) # sell, sell_weight = -1, -1 bsLine['buy'][last_index] = buy bsLine['buy_weight'][last_index] = buy_weight bsLine['sell'][last_index] = sell bsLine['sell_weight'][last_index] = sell_weight else: bsLine['buy'] = [-1] bsLine['buy_weight'] = [-1] bsLine['sell'] = [-1] bsLine['sell_weight'] = [-1] return bsLine