103 lines
4.2 KiB
Python
103 lines
4.2 KiB
Python
from hts.BuySellChecker import BuySellChecker
|
|
|
|
class BuySellChecker_251340 (BuySellChecker):
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
return
|
|
|
|
def getBuyPriceAndWeight(self, stock_code, i, data, INFO):
|
|
buy, weight = -1, -1
|
|
|
|
C_MIN_AVG_5_200 = max(data['disparity_avg5'][i], data['disparity_avg20'][i], data['disparity_avg60'][i], data['disparity_avg200'][i]) - min(data['disparity_avg5'][i], data['disparity_avg20'][i], data['disparity_avg60'][i], data['disparity_avg200'][i])
|
|
C_MIN_AVG_5_60 = max(data['disparity_avg5'][i], data['disparity_avg20'][i], data['disparity_avg60'][i]) - min(data['disparity_avg5'][i], data['disparity_avg20'][i], data['disparity_avg60'][i])
|
|
|
|
MIN_AVG_5_200 = 0.002
|
|
MIN_AVG_5_60 = 0.002
|
|
DIFF_200_5 = 0.001
|
|
|
|
if (abs(data['disparity_avg200'][i] - data['disparity_avg5'][i]) < DIFF_200_5 and C_MIN_AVG_5_200 < MIN_AVG_5_200 and C_MIN_AVG_5_60 < MIN_AVG_5_60):
|
|
if data['avg200'][i] < data['avg5'][i]:
|
|
if 180 < i:
|
|
valid = True
|
|
for c in range(5, 181):
|
|
if data['avg200'][-c] < data['avg200'][-c]:
|
|
valid = False
|
|
break
|
|
if valid:
|
|
if max(data['volume'].tolist()[i-10:i]) < data['volume'][i]:
|
|
buy = data['close'][i]
|
|
weight = 1
|
|
if data['open'][i-2] < data['close'][i-2] and data['open'][i-1] < data['close'][i-1] and data['open'][i] < data['close'][i]:
|
|
buy = data['close'][i]
|
|
weight = 1
|
|
|
|
if data['macd'][i-1] < -1000:
|
|
if -1000 < data['macd'][i]:
|
|
buy = data['close'][i]
|
|
weight = 1
|
|
|
|
return buy, weight
|
|
|
|
def getSellPriceAndWeight(self, stock_code, i, data, INFO):
|
|
sell, weight = -1, -1
|
|
|
|
if data['close'][i] < INFO['LOW_PRICE'] < data['close'][i-1]:
|
|
sell = data['close'][i]
|
|
weight = 1
|
|
|
|
if (650 < data['macd'][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]
|
|
|
|
if data['close'][i] < INFO['LIMIT_PRICE']:
|
|
weight = 1
|
|
sell = data['close'][i]
|
|
|
|
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 |