init
This commit is contained in:
1008
AnalyzerSqlite.py
Normal file
1008
AnalyzerSqlite.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -4,39 +4,39 @@ from stock.analysis.MovingAverage import MovingAverage
|
||||
class Common:
|
||||
|
||||
# 상향
|
||||
def getDirection(self, stock, idx, until=10):
|
||||
def getDirection(self, data, idx, until=10):
|
||||
up, down = 0, 0
|
||||
for i in range(idx, idx-(until+1), -1):
|
||||
if stock[i - 1] < stock[i]:
|
||||
if data[i - 1] < data[i]:
|
||||
up += 1
|
||||
if stock[i - 1] > stock[i]:
|
||||
if data[i - 1] > data[i]:
|
||||
down += 1
|
||||
|
||||
if down < up:
|
||||
if stock[idx - 3] < stock[idx]:
|
||||
if data[idx - 3] < data[idx]:
|
||||
return 'UP'
|
||||
elif up < down:
|
||||
if stock[idx - 3] > stock[idx]:
|
||||
if data[idx - 3] > data[idx]:
|
||||
return 'DOWN'
|
||||
return 'EVEN'
|
||||
|
||||
# 상향 돌파
|
||||
def checkUpwardBreakthrough(self, type1, type2, stock):
|
||||
if (type1 in stock[0] and type1 in stock[1] and type1 in stock[2] and
|
||||
type2 in stock[0] and type2 in stock[1] and type2 in stock[2]):
|
||||
def checkUpwardBreakthrough(self, type1, type2, data):
|
||||
if (type1 in data[0] and type1 in data[1] and type1 in data[2] and
|
||||
type2 in data[0] and type2 in data[1] and type2 in data[2]):
|
||||
|
||||
if ((stock[0][type1] < stock[1][type1] < stock[2][type1]) and
|
||||
(stock[0][type1] < stock[0][type2] and stock[2][type1] > stock[2][type2])):
|
||||
if ((data[0][type1] < data[1][type1] < data[2][type1]) and
|
||||
(data[0][type1] < data[0][type2] and data[2][type1] > data[2][type2])):
|
||||
return True
|
||||
return False
|
||||
|
||||
# 하향 돌파
|
||||
def checkDownwardBreakthrough(self, type1, type2, stock):
|
||||
if (type1 in stock[0] and type1 in stock[1] and type1 in stock[2] and
|
||||
type2 in stock[0] and type2 in stock[1] and type2 in stock[2]):
|
||||
def checkDownwardBreakthrough(self, type1, type2, data):
|
||||
if (type1 in data[0] and type1 in data[1] and type1 in data[2] and
|
||||
type2 in data[0] and type2 in data[1] and type2 in data[2]):
|
||||
|
||||
if ((stock[0][type1] > stock[1][type1] > stock[2][type1]) and
|
||||
(stock[0][type1] > stock[0][type2] and stock[2][type1] < stock[2][type2])):
|
||||
if ((data[0][type1] > data[1][type1] > data[2][type1]) and
|
||||
(data[0][type1] > data[0][type2] and data[2][type1] < data[2][type2])):
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -488,8 +488,8 @@ class Common:
|
||||
return False
|
||||
|
||||
def check_env_lower_rsi(self, stock):
|
||||
if stock['close'][-2] < stock['envelope_lower'][-2] and stock['envelope_lower'][-1] < stock['close'][-1]:
|
||||
if stock['rsi'][-1] < 50:
|
||||
if stock['close'][1] < stock['envelope_lower'][1] and stock['envelope_lower'][0] < stock['close'][0]:
|
||||
if stock['rsi'][0] < 50:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -521,9 +521,9 @@ class Common:
|
||||
def check_volume(self, stock):
|
||||
c_index = 200
|
||||
|
||||
max_volume = max(stock['volume'][-c_index:-1])
|
||||
if 0 < max_volume*2 < stock['volume'][-1] and stock['close'][-2] < stock['close'][-1]:
|
||||
log = "{:.2f}".format(stock['volume'][-1]/max_volume)
|
||||
max_volume = max(stock['volume'][1:c_index+1])
|
||||
if 0 < max_volume*2 < stock['volume'][0] and stock['close'][1] < stock['close'][0]:
|
||||
log = "{:.2f}".format(stock['volume'][0]/max_volume)
|
||||
return True, log
|
||||
|
||||
return False, ""
|
||||
@@ -569,28 +569,74 @@ class Common:
|
||||
check = False
|
||||
if len(stock['trend']) < 10:
|
||||
return check
|
||||
for i in range(10):
|
||||
if stock['rsi'][i] is None:
|
||||
return check
|
||||
for i in range(10):
|
||||
if stock['slow_k'][i] is None:
|
||||
return check
|
||||
|
||||
i = len(stock['ymd']) - 1
|
||||
check = False
|
||||
|
||||
if 130 < i:
|
||||
for c in range(5):
|
||||
# 추세가 상승 중일 때 매수의 관점 (소추세가 하락해 있을 때 매수의 기회)
|
||||
if np.average(stock['avg60'][i - c - 3:i - c]) < stock['avg60'][i - c]:
|
||||
if stock['avg60'][i - c] < stock['avg20'][i - c]:
|
||||
if stock['slow_d'][i - c] is not None and stock['slow_k'][i - c] is not None and stock['slow_k'][i - c - 1] is not None and stock['slow_k'][i - c] is not None and stock['slow_k'][i - c] is not None:
|
||||
if stock['slow_d'][i - c] < stock['slow_k'][i - c] and stock['slow_k'][i - c - 1] < stock['slow_k'][i - c] and stock['slow_k'][i - c] < 50:
|
||||
if stock['close'][i - c] < stock['last_middle'][i - c] - (stock['last_middle'][i - c] - stock['last_min'][i - c]) * 0.5:
|
||||
check = True
|
||||
if (stock['close'][1] is None or stock['close'][0] is None or stock['rsi'][1] is None or stock['rsi'][0] is None):
|
||||
return check
|
||||
|
||||
rise_rate = param['bull'][0] / (param['bull'][0]+param['bear'][0]+param['bull'][0])
|
||||
if (
|
||||
(stock['macd'][1] < stock['macd'][0] and stock['rsi'][0] < 80) or
|
||||
(stock['rsi'][1] < stock['rsi'][0] and np.min(stock['rsi'][:3]) < 35) or
|
||||
(stock['rsi'][0] < 35) or
|
||||
0.7 <= rise_rate
|
||||
):
|
||||
# avg300 상승
|
||||
if stock['avg300'][1] < stock['avg300'][0]:
|
||||
# avg5 < trend
|
||||
if stock['avg5'][0] < stock['trend'][0]:
|
||||
# avg5 이전 3개 봉 위
|
||||
if np.max(stock['avg5'][:3]) < stock['avg5'][0]:
|
||||
buy_type = "trend"
|
||||
check = True
|
||||
|
||||
# 상승 추세일 때
|
||||
if (stock['macd'][1] < stock['macd'][0] and stock['macds'][0] < stock['macd'][0] or
|
||||
stock['rsi'][1] < stock['rsi'][0]):
|
||||
|
||||
# rsi가 50을 상향 돌파할 때
|
||||
if 0.9 <= rise_rate and np.max(stock['rsi'][:5]) < 50 and 50 < stock['rsi'][0]:
|
||||
buy_type = "rsi"
|
||||
check = True
|
||||
|
||||
# golden & 거래량
|
||||
if stock['avg120'][0] < stock['avg60'][0] < stock['avg20'][0] < stock['avg5'][0]:
|
||||
buy_type = "golden"
|
||||
check = True
|
||||
|
||||
# rsi가 30보다 작은 후에 상승일 때
|
||||
if np.min(stock['rsi'][:5]) < 30:
|
||||
if stock['rsi'][1] < stock['rsi'][0]:
|
||||
buy_type = "rsi"
|
||||
check = True
|
||||
|
||||
if not(stock['rsi'][1] < stock['rsi'][0] and stock['rsis'][0] < stock['rsi'][0]):
|
||||
check = False
|
||||
|
||||
# 거래량은 6시간 중 가장 많은 것보다 1.5배 이상 많고, 종가는 3시간 중에서 가장 높을 때
|
||||
if np.max(stock['volume'][i - c - 120:i - c - 2]) * 1.5 < stock['volume'][i - c] and np.max(stock['close'][i - c - 20: i - c]) < stock['close'][i - c]:
|
||||
if stock['open'][i - c - 1] < stock['close'][i - c - 1] and stock['close'][i - c - 1] - stock['open'][i - c - 1] < stock['close'][i - c] - stock['open'][i - c]:
|
||||
# 양봉이고 몸통이 3/4 이상일 때
|
||||
if stock['open'][i - c] < stock['close'][i - c] and stock['high'][i - c] - stock['close'][i - c] < (stock['close'][i - c] - stock['open'][i - c]) * 0.25:
|
||||
check = True
|
||||
return check
|
||||
|
||||
def buy_stock_candidate(self, param, stock):
|
||||
check = False
|
||||
if len(stock['trend']) < 10:
|
||||
return check
|
||||
|
||||
if stock['upper'][0] < stock['high'][0]:
|
||||
# 볼린저 밴드 width 로 매수 시점
|
||||
for i in range(10):
|
||||
if stock['width'][i+1] < 20 and 20 < stock['width'][i]:
|
||||
check = True
|
||||
break
|
||||
# 볼린저 밴드 %B와 MFI로 매수 시점
|
||||
if 80 < stock['pb'][i+1] and 80 < stock['mfi'][i]:
|
||||
check = True
|
||||
|
||||
return check
|
||||
|
||||
# 낙폭 과대 체크
|
||||
def check_excessive_drop(self, stock):
|
||||
@@ -609,9 +655,9 @@ class Common:
|
||||
return False
|
||||
|
||||
def check_under_BB_Low(self, stock):
|
||||
if stock['lower'][-1] is not None and stock['lower'][-2] is not None:
|
||||
if stock['lower'][0] is not None and stock['lower'][1] is not None:
|
||||
# bb 하단에 부딪힘
|
||||
if stock['close'][-1] < stock['lower'][-1]:
|
||||
if stock['close'][0] < stock['lower'][0]:
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -662,3 +708,11 @@ class Common:
|
||||
return obv
|
||||
|
||||
return -1
|
||||
|
||||
def buy_stock_dail5_5_20(self, stock_daily):
|
||||
|
||||
if stock_daily['avg5'][1] < stock_daily['avg20'][1] and stock_daily['avg20'][0] < stock_daily['avg5'][1]:
|
||||
if stock_daily['avg20'][0] < stock_daily['avg5'][0] < stock_daily['avg40'][0]:
|
||||
return True
|
||||
|
||||
return False
|
||||
Reference in New Issue
Block a user