This commit is contained in:
dsyoon
2023-11-16 01:26:52 +09:00
parent 076bcb1dfa
commit 7006be45fa
6 changed files with 164 additions and 1275 deletions

View File

@@ -9,29 +9,18 @@ from hts.HTS import HTS
from stock.util.Stock2Vector import Stock2Vector
from stock.util.LabelChecker import LabelChecker
from hts.BuySellChecker_122630 import BuySellChecker_122630
from hts.BuySellChecker_233740 import BuySellChecker_233740
from hts.BuySellChecker_251340 import BuySellChecker_251340
from hts.BuySellChecker_252670 import BuySellChecker_252670
from hts.BuySellChecker import BuySellChecker
class Simulation (HTS):
stock2Vector = None
buySellChecker = None
def __init__(self, RESOURCE_PATH, stock_code):
def __init__(self, RESOURCE_PATH):
super().__init__(RESOURCE_PATH)
self.RESOURCE_PATH = RESOURCE_PATH
self.buySellChecker = None
if stock_code == '122630':
self.buySellChecker = BuySellChecker_122630()
elif stock_code == '233740':
self.buySellChecker = BuySellChecker_233740()
elif stock_code == '251340':
self.buySellChecker = BuySellChecker_251340()
elif stock_code == '252670':
self.buySellChecker = BuySellChecker_252670()
self.buySellChecker = BuySellChecker()
try:
self.stock2Vector = Stock2Vector(RESOURCE_PATH)
@@ -230,25 +219,6 @@ class Simulation (HTS):
return result
def getLIMITInfo(self, stock_code, ymd, dbfile_name="stock.db"):
conn = sqlite3.connect(os.path.join(self.RESOURCE_PATH, dbfile_name))
cursor = conn.cursor()
cursor.execute('select ymd, open, close, high, low, volume from stock where code=? order by ymd desc limit ?', (stock_code, 100, ))
db_result = cursor.fetchall()
cursor.close()
conn.close()
match = False
LIMIT_PRICE = []
for i, rows in enumerate(db_result):
if rows[0].replace('.', '') <= ymd:
match = True
if match:
LIMIT_PRICE.append(rows[2])
return {'LIMIT_PRICE': sum(LIMIT_PRICE[:20])/len(LIMIT_PRICE[:20])}
def simulate(self, stock, analyzed_day=1000):
stock_code = stock['code']
for ymd in stock['ymd']:
@@ -275,11 +245,9 @@ class Simulation (HTS):
# 사야 할 시점과 팔아야 할 시점을 체크한다.
#bsLine = self.buySellChecker.checkTransaction(stock_code, data, data_5, data_30, isRealTime=False)
INFO = self.getLIMITInfo(stock_code, ymd)
# 어제 데이터는 지운다.
#data = data.loc[pd.DatetimeIndex(data.index).day == int(given_day[6:])]
bsLine = self.buySellChecker.checkTransaction(stock_code, data, INFO, isRealTime=False)
bsLine = self.buySellChecker.checkTransaction(data, isRealTime=False)
# 그래프를 그린다.
self.draw(stock_code, ymd, data, bsLine)
@@ -291,23 +259,15 @@ if __name__ == "__main__":
RESOURCE_PATH = os.path.join(PROJECT_HOME, "resources")
#day_list = ['20231016', '20231017', '20231018', '20231019', '20231020', '20231023', '20231024', '20231025', '20231026', '20231027', '20231030', '20231031', '20231101', '20231102']
day_list = ['20231102']
day_list = ['20231113']
stocks = [
{'code': '252670', 'name': 'KODEX 200선물인버스2X', 'ymd': day_list},
{'code': '122630', 'name': 'KODEX 레버리지', 'ymd': day_list},
{'code': '233740', 'name': 'KODEX 코스닥150레버리지', 'ymd': day_list},
{'code': '251340', 'name': 'KODEX 코스닥150선물인버스', 'ymd': day_list}
]
# to check bying
stock = {'code': '252670', 'name': 'KODEX 200선물인버스2X', 'ymd': day_list}
simulation = Simulation(RESOURCE_PATH, stock['code'])
for stock in stocks:
simulation = Simulation(RESOURCE_PATH)
simulation.simulate(stock)
#stock = {'code': '122630', 'name': 'KODEX 레버리지', 'ymd': day_list}
#simulation = Simulation(RESOURCE_PATH, stock['code'])
#simulation.simulate(stock)
#stock = {'code': '233740', 'name': 'KODEX 코스닥150레버리지', 'ymd': day_list}
#simulation = Simulation(RESOURCE_PATH, stock['code'])
#simulation.simulate(stock)
#stock = {'code': '251340', 'name': 'KODEX 코스닥150선물인버스', 'ymd': day_list}
#simulation = Simulation(RESOURCE_PATH, stock['code'])
#simulation.simulate(stock)
print ("done...")

View File

@@ -1,6 +1,5 @@
import pandas as pd
from datetime import datetime
from stock.analysis.Common import Common
from stock.analysis.Stochastic import Stochastic
from stock.analysis.RSI import RSI
@@ -28,258 +27,167 @@ class BuySellChecker:
return
def isYangbong(self, data, i):
if data['close'][i] > data['open'][i]:
return True
else:
if data['low'][i] < data['close'][i] == data['open'][i] == data['high'][i]:
return True
if data['low'][i] < data['open'][i] == data['close'][i] < data['high'][i]:
return True
return False
def isUmbong(self, data, i):
if data['close'][i] < data['open'][i]:
return True
else:
if data['low'][i] == data['close'][i] == data['open'][i] < data['high'][i]:
return True
if data['low'][i] < data['open'][i] == data['close'][i] < data['high'][i]:
return True
return False
# 지난 1시간 30분 동안 12분 선이 20분 선위에 20분 이상 있었는지 체크
def check_12_over_20_for_30(self, data, i, default=90):
if i - default < 381:
return False
check_12_over_20_for_30 = False
for c in range(i - default, i - 20):
if data['avg20'][c] < data['avg20'][i]:
value = [1 if data['avg20'][d] < data['avg12'][d] else 0 for d in range(c, c + 20)]
if len(value) == 20 and sum(value) == 20:
check_12_over_20_for_30 = True
break
return check_12_over_20_for_30
# 지난 1시간 동안 3, 6, 9, 12분 선이 10분 이상 20분 선 아래 있었는지 체크
def check_under_20_for_10(self, data, i, within=60, during=10):
if i - within < 381:
return False
check_under_20_for_10 = False
for c in range(i - within, i - during):
value = [
1 if max(data['avg3'][d], data['avg6'][d], data['avg9'][d], data['avg12'][d]) < data['avg20'][d] else 0
for d in range(c, c + during)]
if len(value) == during and sum(value) == during:
check_under_20_for_10 = True
break
return check_under_20_for_10
def max_min_avg(self, data, i):
return max(data['avg3'][i], data['avg6'][i], data['avg9'][i], data['avg12'][i], data['avg20'][i]) - min(
data['avg3'][i], data['avg6'][i], data['avg9'][i], data['avg12'][i], data['avg20'][i])
def check_inverse_arrangement_before(self, data, i, within=30, during=5):
if i - within < 381:
return False
inverse_arrangement = False
for c in range(i - within, i - during):
value = [
1 if data['avg3'][d] < data['avg6'][d] < data['avg9'][d] < data['avg12'][d] < data['avg20'][d] else 0
for d in range(c, c + during)]
if len(value) == during and sum(value) == during - 1:
inverse_arrangement = True
break
return inverse_arrangement
def checkUpDirection(self, data, i):
# 0: 무추세, -1: 하락 추세, 1: 상승 추세
close = data['close'][i]
# up_count = sum([1 if data['high'][c] < close else 0 for c in range(i-20, i)])
# down_count = sum([1 if close < data['low'][c] else 0 for c in range(i - 20, i)])
lagging_change = sum([1 if data['laggingSpan'][c] < data['changeLine'][c] else 0 for c in range(i - 20, i)])
change_lagging = sum([1 if data['laggingSpan'][c] > data['changeLine'][c] else 0 for c in range(i - 20, i)])
if lagging_change > 10:
return 1
if change_lagging == 20:
return -1
return 0
def isAvg200UP(self, data, idx, until=10, limit=0.9):
even, up, down = 0, 0, 0
for i in range(idx, idx - (until + 1), -1):
if data['avg200'][i] < data['close'][i]:
up += 1
if data['avg200'][i] > data['close'][i]:
down += 1
else:
even += 1
if up * (1 - limit) > down:
return True
return False
def getBuyPriceAndWeight(self, i, data):
buy, weight, type = -1, -1, ""
"""
def getBuyPriceAndWeight_122630(self, i, data):
buy, weight = -1, -1
if i > 200:
if (
(
min(data['avg200'][i-53: i-48]) > min(data['avg200'][i-48: i-43]) >
min(data['avg200'][i-43: i-38]) > min(data['avg200'][i-38: i-33]) >
min(data['avg200'][i-33: i-28]) > min(data['avg200'][i-28: i-23]) >
min(data['avg200'][i-23: i-18]) > min(data['avg200'][i-18: i-13]) >
min(data['avg200'][i-13: i-8]) > min(data['avg200'][i-8: i-3]) >
data['avg200'][i-3]
) and
data['avg200'][i-3] < min(data['avg200'][i-2:i])
):
if data['close'][i] < data['close'][i-30]:
# 매수전략 #1: 다이버전스
if data['macd'][i] < 0 and data['open'][i] < data['close'][i]:
if 0 < len(data['rsi'].tolist()[i - 10:i - 5]):
if min(data['rsi'].tolist()[i - 10:i - 5]) < data['rsi'][i - 1]:
if data['low'][i - 1] < min(data['low'].tolist()[i - 10:i - 5]):
weight = 1
buy = data['close'][i]
weight = 0.2
if (
(
min(data['avg200'][i-103: i-93]) >= min(data['avg200'][i-93: i-83]) >=
min(data['avg200'][i-83: i-73]) >= min(data['avg200'][i-73: i-63]) >=
min(data['avg200'][i-63: i-53]) >= min(data['avg200'][i-53: i-43]) >=
min(data['avg200'][i-43: i-33]) >= min(data['avg200'][i-33: i-23]) >
min(data['avg200'][i-23: i-13]) > min(data['avg200'][i-13: i-3]) >
data['avg200'][i-3]
) and
(
max(data['avg200'][i - 103: i - 93]) - min(data['avg200'][i - 93: i - 83]) >
max(data['avg200'][i - 83: i - 73]) - min(data['avg200'][i - 73: i - 63]) >
max(data['avg200'][i - 63: i - 53]) - min(data['avg200'][i - 53: i - 43]) >
max(data['avg200'][i - 43: i - 33]) - min(data['avg200'][i - 33: i - 23]) >
max(data['avg200'][i - 23: i - 13]) - min(data['avg200'][i - 13: i - 3])
) and
data['avg200'][i-3] < min(data['avg200'][i-2:i])
):
if 25 < max(data['macd'][i-50: i-20]) and data['close'][i] < data['close'][i - 30]:
if data['slow_k'][i - 1] < data['slow_k'][i] and data['slow_k'][i] < 50 and data['macd'][i-1] < data['macd'][i]:
buy = data['close'][i]
weight = 0.2
if 25 < max(data['macd'][i-50: i-20]) and min(data['macd'][i-20: i]) < -30 and 0 < data['macd'][i] < 3:
if data['slow_k'][i - 1] < data['slow_k'][i] and data['slow_k'][i] < 50 and data['macd'][i-1] < data['macd'][i]:
buy = data['close'][i]+5
weight = 0.2
if 25 < max(data['macd'][i-50: i-20]) and data['macd'][i] < -20 and data['macd'][i-1] < data['macd'][i]:
if data['slow_k'][i - 1] < data['slow_k'][i] and data['slow_k'][i] < 50 and data['macd'][i-1] < data['macd'][i]:
buy = data['close'][i]+5
weight = 0.2
if 0.00988 < data['disparity_avg5'][i] - data['disparity_avg200'][i]:
if 25 < max(data['macd'][i-50: i-20]) and data['slow_k'][i - 1] < data['slow_k'][i] and data['slow_k'][i] < 50 and data['macd'][i-1] < data['macd'][i]:
buy = data['close'][i] + 10
weight = 0.2
return buy, weight
def getBuyPriceAndWeight_252670(self, i, data):
buy, weight = -1, -1
if i > 50:
up, down = 0, 0
for idx in range(i, i - (300 + 1), -1):
if data['avg200'][idx-1] < data['avg200'][idx]:
up += 1
if data['avg200'][idx-1] > data['avg200'][idx]:
down += 1
if up < down:
if max(data['avg200'][i-20:i])+0.05 < data['avg200'][i]:
buy = data['close'][i]
weight = 0.3
up, down = 0, 0
for idx in range(i, i - (10 + 1), -1):
if data['close'][idx-1] < data['close'][idx]:
up += 1
elif data['close'][idx - 1] > data['close'][idx]:
down += 1
if down < up:
buy, weight = -1, -1
if data['close'][i] < data['avg200'][i] or data['avg200'][i] + 10 < data['close'][i]:
buy, weight = -1, -1
if 2 < data['macd'][i]:
buy, weight = -1, -1
return buy, weight
def getBuyPriceAndWeight(self, stock_code, i, data):
buy, weight = -1, -1
if i > 50:
if stock_code == '233740':
if data['macd'][i-2] < 0 and 0 < data['macd'][i-1] and 0 < data['macd'][i]:
if data['volume'][i - 2] < data['volume'][i - 1] < data['volume'][i]:
if min(data['macd'][i-30:i].tolist()) < -50:
buy, weight = data['close'][i], 1
if min(data['macd'][i-5:i].tolist()) < min(data['macd'][i-15:i-10].tolist()) < -50:
if -50 < max(data['macd'][i-15:i-7].tolist()):
buy, weight = data['close'][i], 1
elif stock_code == '122630':
if data['macd'][i - 2] < 0 and 0 < data['macd'][i - 1] and 0 < data['macd'][i]:
if data['volume'][i - 2] < data['volume'][i - 1] < data['volume'][i]:
if min(data['macd'][i - 30:i].tolist()) < -25:
buy, weight = data['close'][i], 1
if min(data['macd'][i-5:i].tolist()) < min(data['macd'][i - 15:i - 10].tolist()) < -30:
if -20 < max(data['macd'][i - 15:i - 7].tolist()):
buy, weight = data['close'][i], 1
elif stock_code == '252670':
if min(data['macd'][i - 40:i - 20].tolist()) < -5 < data['macd'][i]:
if data['close'][i] < min(data['close'][i - 40:i - 20].tolist()):
buy, weight = data['close'][i], 1
elif stock_code == '251340':
if min(data['macd'][i-40:i-20].tolist()) < -20 < data['macd'][i]:
if data['close'][i] < min(data['close'][i-40:i-20].tolist()):
buy, weight = data['close'][i], 1
return buy, weight
def getSellPriceAndWeight(self, stock_code, i, data):
sell, weight = -1, -1
# 1) 스토캐스틱 과매수
slow_k_sell = False
for idx in range(i, i-10, -1):
if data['slow_k'][idx] > 80:
slow_k_sell = True
break
# 2) macd 교차 신호
macd_sell = False
if slow_k_sell:
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_sell = True
break
# 3) RSI 지수가 50위로 올라갈 때
if macd_sell:
if data['rsi'][i-1] > 60 and data['rsi'][i] < 60:
sell, weight = data['close'][i], 1
return sell, weight
type = 'Divergence'
"""
high_barrier = 70
low_barrier = 30
Buy_Price=[]
Sell_Price=[]
number=[]
temp01 = []
temp01_id = []
temp02 = []
temp01_id = []
temp01_min_price = []
temp02_min_price = []
temp01_min_rsi = []
temp02_min_rsi = []
n_id=[]
i_id=[]
flag=1
n = 0
# https://superhky.tistory.com/441
find = False
for c in range(i-40, i-1):
if data['rsi'][i-1] > low_barrier and data['rsi'][i] < low_barrier:
for k in range(c, i):
if data['rsi'][k-1] < low_barrier and data['rsi'][k] > low_barrier:
temp01 = data['rsi'].iloc[c:k]
temp01_id = temp01.argmin() + c
temp01_min_rsi = data['rsi'][temp01_id]
temp01_min_price = data['close'][temp01_id]
for m in range(k, i):
if data['rsi'][m-1] < low_barrier and data['rsi'][m] < low_barrier:
for n in range(m, i):
if data['rsi]'][n-1] < low_barrier and data['rsi'][n] < low_barrier:
temp02 = data['rsi'].iloc[m:n]
temp02_id = temp02.argmin() + m
temp02_min_rsi = data['rsi'][temp02_id]
temp02_min_price = data['close'][temp02_id]
if temp01_min_rsi < temp02_min_rsi and temp01_min_price > temp02_min_price and flag == 1:
if c == i-1:
weight = 1
buy = data['close'][i]
type = 'Divergence'
find = True
break
if find: break
if find: break
if find: break
"""
# 매수전략 #3: stochastic + rsi + macd
check = False
if data['slow_k'][i - 1] < data['slow_k'][i] and data['slow_d'][i] < data['slow_k'][i]:
# 과매도 체크
index = -1
for c in range(i - 40, i):
if data['slow_k'][i] < 20:
index = c
check = True
if check:
# 과매도 후 과매수 였는지 체크
check = False
for d in range(index, i):
if 80 < data['slow_k'][d]:
check = True
break
if not check:
# 과매도 후 과매수가 아니라면
if data['rsi'][i - 1] < 50 and 50 < data['rsi'][i]:
if data['macds'][i] < data['macd'][i] < 0:
weight = 1
buy = data['close'][i]
type = 'S+R+M'
"""
return buy, weight, type
def getSellPriceAndWeight(self, i, data):
sell, weight, type = -1, -1, ""
max_value = max(data['macd'].tolist()) * 0.8
if (max_value < data['macd'][i] or 1.9 < 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 70 < data['rsi'][i]:
weight = 1
sell = data['close'][i]
type = 'method2'
return sell, weight, type
def checkTransaction(self, data, 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, buy_type = self.getBuyPriceAndWeight(last_index, data)
sell, sell_weight, sell_type = self.getSellPriceAndWeight(last_index, data)
bsLine['buy'] = [buy]
bsLine['buy_weight'] = [buy_weight]
bsLine['buy_type'] = [buy_type]
bsLine['sell'] = [sell]
bsLine['sell_weight'] = [sell_weight]
bsLine['sell_type'] = [sell_type]
else:
# Type=False, 시뮬레이션 적용
bsLine['buy'] = [-1 for i in range(size)]
bsLine['buy_weight'] = [-1 for i in range(size)]
bsLine['buy_type'] = ['' for i in range(size)]
bsLine['sell'] = [-1 for i in range(size)]
bsLine['sell_weight'] = [-1 for i in range(size)]
bsLine['sell_type'] = ['' for i in range(size)]
for last_index in range(size):
buy, buy_weight, buy_type = self.getBuyPriceAndWeight(last_index, data)
sell, sell_weight, sell_type = self.getSellPriceAndWeight(last_index, data)
bsLine['buy'][last_index] = buy
bsLine['buy_weight'][last_index] = buy_weight
bsLine['buy_type'][last_index] = buy_type
bsLine['sell'][last_index] = sell
bsLine['sell_weight'][last_index] = sell_weight
bsLine['sell_type'][last_index] = sell_type
else:
bsLine['buy'] = [-1]
bsLine['buy_weight'] = [-1]
bsLine['buy_type'] = ['']
bsLine['sell'] = [-1]
bsLine['sell_weight'] = [-1]
bsLine['sell_type'] = ['']
return bsLine
def analyze(self, result):
# 기본 캔들 정보
@@ -388,474 +296,3 @@ class BuySellChecker:
data = data.fillna(-1)
return data
"""
def checkTransaction(self, stock_code, data, data_5=None, data_30=None, isRealTime=True):
# 어제 오늘 데이터로 분석
bsLine = {}
size = len(data["close"])
if isRealTime:
# isRealTime=True, 실시간 적용
last_index = size - 1
buy, buy_weight = self.getBuyPriceAndWeight(stock_code, last_index, data)
#sell, sell_weight = self.getSellPriceAndWeight(stock_code, last_index, data)
sell, sell_weight = -1, -1
if data.index[last_index].strftime('%H:%M:%S') > datetime.strptime(datetime.today().strftime("%Y-%m-%d 15:10:00"), "%Y-%m-%d %H:%M:%S").strftime('%H:%M:%S'):
buy, buy_weight = -1, -1
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)
sell, sell_weight = self.getSellPriceAndWeight(stock_code, last_index, data)
bsLine['buy'][last_index] = buy
bsLine['buy_weight'][last_index] = buy_weight
bsLine['sell'][last_index] = sell
bsLine['sell_weight'][last_index] = sell_weight
return bsLine
"""
# middle line에 맞다은 적 없이, low line에 붙었거나 아래에 있었던 캔들의 높은 가격을 얻어옴
def getPrice_UnderLowWithoutMiddle(self, last_index, data):
if data['high'][last_index] < data['envelope_middle'][last_index]:
for i in range(last_index - 1, 0, -1):
if data['high'][i] > data['envelope_middle'][i]:
return -1, -1
if data['low'][i] < data['envelope_lower'][i]:
return i, max(data['open'][i], data['close'][i])
return -1, -1
def getBuyPriceAndWeight_Envelope(self, i, data):
buy, weight = -1, -1
"""
# middle line에 맞다은 적 없이, low line에 붙었거나 아래에 있었던 캔들의 높은 가격을 얻어옴
index, price = self.getPrice_UnderLowWithoutMiddle(i, data)
if price > -1:
# 해당 가격보다 높은 가격이면 매수한다
if price < data['close'][i]:
buy = data['close'][i]
weight = 10
"""
if i > 100:
if -0.004 < data['gradient1'][i] < 0.001:
# if data['high'][i] < data['envelope_middle'][i]:
if data['slow_k'][i] < 20:
buy = data['close'][i]
weight = 10
"""
if i > 100:
if min(data['gradient1'][i-5:i]) < -0.009 and -0.009 < data['gradient1'][i]:
if data['high'][i] < data['envelope_middle'][i]:
buy = data['close'][i]
weight = 10
"""
return buy, weight
def getSellPriceAndWeight_Envelope(self, data, i):
sell, weight, type = -1, -1, -1
if data.index[i].strftime("%Y.%m.%d") == "2022.12.01":
print(1)
# upper lined에서 처리
if data['close'][i - 1] < data['envelope_upper'][i - 1] and data['envelope_upper'][i] < data['close'][i]:
if data['slow_d'][i - 1] <= data['slow_k'][i - 1] and data['slow_k'][i] <= data['slow_d'][i]:
sell = data["close"][i]
weight = 1
type = 1
if data['envelope_upper'][i - 1] < data['close'][i - 1] and data['envelope_upper'][i] < data['close'][i]:
if data['slow_d'][i - 1] <= data['slow_k'][i - 1] and data['slow_k'][i] <= data['slow_d'][i]:
sell = data["close"][i]
weight = 1
type = 2
if data['envelope_upper'][i - 1] < data['close'][i - 1] and data['envelope_upper'][i] < data['close'][i]:
if data['slow_d'][i - 1] + 2 <= data['slow_k'][i - 1] and data['slow_d'][i] + 1 == data['slow_k'][i]:
sell = data["close"][i]
weight = 1
type = 3
if data['envelope_upper'][i] < data['high'][i] and data['open'][i] < data['close'][i]:
if data['close'][i] - data['open'][i] < data['high'][i] - data['close'][i]:
sell = data["close"][i]
weight = 1
type = 4
return sell, weight, type
# 팔아야 할 시점을 체크하기 위함
# 이전에 산 가격보다 지금 5원이상 떨어졌다면 매도 한다.
def checkBelow5WonFromPreviousBuyPrice(self, last_index, data, price):
for i in range(last_index - 1, 0, -1):
if data['sell'][i] != -1:
return False
if data['buy'][i] != -1:
if data['buy'][i] - price > 5:
return True
return
def checkWithEnvelope_252670(self, data, isRealTime=False):
bsLine = {}
size = len(data["close"])
bsLine['buy'] = [-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.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] = 20.0
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] = 20.0
if data['disparity_avg60'][i] < 65:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 15.0
if data['slow_k'][i] < 3:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 10.0
if not (data['avg120'][i - 1] < data['avg60'][i - 1] < data['avg20'][i - 1] < data['avg5'][i - 1]) and (data['avg120'][i] < data['avg60'][i] < data['avg20'][i] < data['avg5'][i]):
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 20.0
return bsLine, data
def checkWithEnvelope_122630(self, data, isRealTime=False):
bsLine = {}
size = len(data["close"])
bsLine['buy'] = [-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.0 for i in range(size)]
for i in range(size):
if isRealTime:
if i < size - 1:
continue
if i > 10:
if data['disparity_avg60'][i] < 60:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 20.0
if data['macd'][i] < -1000:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 20.0
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] = 10.0
if not (data['avg120'][i - 1] < data['avg60'][i - 1] < data['avg20'][i - 1] < data['avg5'][i - 1]) and (data['avg120'][i] < data['avg60'][i] < data['avg20'][i] < data['avg5'][i]):
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 25.0
return bsLine, data
def notBuy(self, data, i):
if i > 5:
check = True
for l in range(i - 4, i + 1):
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]
):
check = False
break
if not check:
return False
return True
def checkWithEnvelope(self, data, analyzed_day=120, isRealTime=False):
bsLine = {}
size = len(data["close"])
bsLine['buy'] = [-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.0 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:
if data['slow_k'][i] < 30:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 3.0
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
):
if data['slow_k'][i] < 30:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 5.0
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:
if data['slow_k'][i] < 30:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 5.0
"""
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:
if data['slow_k'][i] < 30:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 5.0
"""
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:
if data['slow_k'][i] < 10:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 5.0
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:
if data['slow_k'][i] < 30:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 5.0
# 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] = 5.0
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):
if data['slow_k'][i] < 30:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 5.0
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]:
if data['slow_k'][i] < 30:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 7.0
if not (data['avg120'][i - 1] < data['avg60'][i - 1] < data['avg20'][i - 1] < data['avg5'][i - 1]) and (data['avg120'][i] < data['avg60'][i] < data['avg20'][i] < data['avg5'][i]):
if data['slow_k'][i] < 30:
buy = data['low'][i]
data['buy'][i] = buy
bsLine['buy'][i] = buy
bsLine['buy_weight'][i] = 10.0
if data['slow_k'][i] > 75:
if (data['slow_d'][i-1] < data['slow_k'][i-1] and data['slow_k'][i] < data['slow_d'][i]):
sell = data['close'][i]
weight = 100
data['sell'][i] = sell
bsLine['sell'][i] = sell
bsLine['sell_weight'][i] = weight
if data['slow_k'][i] > 85:
if data['slow_k'][i] < data['slow_d'][i]:
sell = data['close'][i]
weight = 100
data['sell'][i] = sell
bsLine['sell'][i] = sell
bsLine['sell_weight'][i] = weight
return bsLine, data
def checkTransactionWithEnvelope(self, data, stock_code, analyzed_day, isRealTime=False):
if isRealTime:
if stock_code == "252670":
bsLine, data = self.checkWithEnvelope_252670(data, isRealTime)
elif stock_code == "122630":
bsLine, data = self.checkWithEnvelope_122630(data, isRealTime)
else:
bsLine, data = self.checkWithEnvelope(data, analyzed_day, isRealTime)
else:
# 사야 할 시점과 팔아야 할 시점을 체크한다.
if stock_code == "252670":
bsLine, data = self.checkWithEnvelope_252670(data, isRealTime)
elif stock_code == "122630":
bsLine, data = self.checkWithEnvelope_122630(data, isRealTime)
else:
bsLine, data = self.checkWithEnvelope(data, analyzed_day, isRealTime)
return bsLine, data

View File

@@ -1,128 +0,0 @@
from hts.BuySellChecker import BuySellChecker
class BuySellChecker_122630 (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 (350 < data['macd'][i] or 300 < 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

View File

@@ -1,127 +0,0 @@
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

View File

@@ -1,127 +0,0 @@
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, 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

View File

@@ -1,126 +0,0 @@
from hts.BuySellChecker import BuySellChecker
class BuySellChecker_252670 (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