init
This commit is contained in:
@@ -10,7 +10,7 @@ class BuySellChecker():
|
||||
PATTERNS = None
|
||||
RESOURCE_PATH = None
|
||||
|
||||
def __init__(self, RESOURCE_PATH):
|
||||
def __init__(self, RESOURCE_PATH, s):
|
||||
self.RESOURCE_PATH = RESOURCE_PATH
|
||||
return
|
||||
|
||||
@@ -91,6 +91,28 @@ class BuySellChecker():
|
||||
macd_dup = list(set(macd_limit))
|
||||
return macd_dup
|
||||
|
||||
|
||||
def is_Support(self, df, i, observation_time=300):
|
||||
# c1 = df.Low[i] < df.Low[i - 1] < df.Low[i - 2] < df.Low[i - 3]
|
||||
# c2 = df.Low[i] < df.Low[i + 1] < df.Low[i + 2] < df.Low[i + 3]
|
||||
# return c1 & c2
|
||||
|
||||
#if df['low'][i] == np.min(df['low'][i - self.observation_time:i + self.observation_time + 1]):
|
||||
if df['low'][i] == np.min(df['low'][i - observation_time:i+1]):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def is_Resistance(self, df, i, observation_time = 300):
|
||||
# c1 = df.High[i] > df.High[i - 1] > df.High[i - 2] > df.High[i - 3]
|
||||
# c2 = df.High[i] > df.High[i + 1] > df.High[i + 2] > df.High[i + 3]
|
||||
# return c1 & c2
|
||||
#if df['high'][i] == np.max(df['high'][i - self.observation_time:i + self.observation_time + 1]):
|
||||
if df['high'][i] == np.max(df['high'][i - observation_time:i+1]):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def getBuyPriceAndWeight1(self, ticker, MAX_BUY_PRICE, i, data, data_signal, BUY_LIST, isRealTime=True):
|
||||
buy_ymd, buy_price, buy_count, buy_cut, buy_type = None, -1, -1, -1, ''
|
||||
|
||||
@@ -98,120 +120,107 @@ class BuySellChecker():
|
||||
df_signal = data_signal.loc[df_tmp]
|
||||
si = len(df_signal) - 1
|
||||
|
||||
duration = 3
|
||||
if sum(data['trend_avg'][i - duration:i]) / duration < data['trend_avg'][i]:
|
||||
# 상승 트렌드
|
||||
if data_signal['avg20'][si] < data_signal['avg5'][si]:
|
||||
"""
|
||||
# 방법 1:
|
||||
if max(data['volume_up'][i-180:i]) < data['volume_up'][i]:
|
||||
if data_signal['slow_k'][si] < 70:
|
||||
if BUY_LIST is not None and 0 < len(BUY_LIST['buy_list']) and BUY_LIST['buy_list'][-1]['buy_price'] < data['close'][i]):
|
||||
buy_price = data['close'][i]
|
||||
buy_type = 'volume_up'
|
||||
buy_ymd = data['ymd'][i]
|
||||
if data['slow_k'][si] < 30:
|
||||
buy_count = MAX_BUY_PRICE / (1 * data['close'][i])
|
||||
elif data['slow_k'][si] < 50:
|
||||
buy_count = MAX_BUY_PRICE / (1.5 * data['close'][i])
|
||||
else:
|
||||
buy_count = MAX_BUY_PRICE / (2 * data['close'][i])
|
||||
return buy_ymd, buy_price, buy_count, buy_cut, buy_type
|
||||
|
||||
if BUY_LIST is None:
|
||||
buy_price = data['close'][i]
|
||||
buy_type = 'golden'
|
||||
buy_ymd = data['ymd'][i]
|
||||
if data['slow_k'][si] < 30:
|
||||
buy_count = MAX_BUY_PRICE / (1 * data['close'][i])
|
||||
elif data['slow_k'][si] < 50:
|
||||
buy_count = MAX_BUY_PRICE / (1.5 * data['close'][i])
|
||||
else:
|
||||
buy_count = MAX_BUY_PRICE / (2 * data['close'][i])
|
||||
return buy_ymd, buy_price, buy_count, buy_cut, buy_type
|
||||
"""
|
||||
"""
|
||||
duration = 5
|
||||
if duration < i:
|
||||
if sum(data['avg20'][i - duration:i])/len(data['avg20'][i - duration:i]) < data['avg20'][i]:
|
||||
min_value1 = min(data['close'][i - 1], data['close'][i - 1])
|
||||
min_value2 = min(data['close'][i - 2], data['close'][i - 2])
|
||||
min_value3 = min(data['close'][i - 3], data['close'][i - 3])
|
||||
min_sum = min_value1 + min_value2 + min_value3
|
||||
if min_sum / 3 < data['close'][i] and data['close'][i] == data['high'][i]:
|
||||
if data['avg60'][i] < data['avg20'][i] and data['avg5'][i-1] < data['avg5'][i]:
|
||||
if data['middle'][i-1] < data['middle'][i]:
|
||||
if 0 < len(BUY_LIST['buy_list']):
|
||||
if BUY_LIST['buy_list'][-1]['buy_price'] < data['close'][i]:
|
||||
buy_price = data['close'][i]
|
||||
buy_type = 'avg20_close_up'
|
||||
buy_ymd = data['ymd'][i]
|
||||
buy_cut = -1
|
||||
if data['slow_k'][si] < 30:
|
||||
buy_count = MAX_BUY_PRICE / (1 * data['close'][i])
|
||||
elif data['slow_k'][si] < 50:
|
||||
buy_count = MAX_BUY_PRICE / (1.5 * data['close'][i])
|
||||
else:
|
||||
buy_count = MAX_BUY_PRICE / (2 * data['close'][i])
|
||||
|
||||
# 방법 2:
|
||||
if data['avg480'][i] < data['avg120'][i] < data['avg60'][i] < data['avg20'][i] < data['avg5'][i] < data['close'][i]:
|
||||
if data['avg240'][i] < min(data['avg5'][i], data['avg20'][i], data['avg60'][i], data['avg120'][i]):
|
||||
if BUY_LIST is not None and 0 < len(BUY_LIST['buy_list']) and data['ymd'][i] < BUY_LIST['buy_list'][-1]['buy_ymd'] + timedelta(minutes=10):
|
||||
if BUY_LIST['buy_list'][-1]['buy_price'] < data['close'][i]:
|
||||
return buy_ymd, buy_price, buy_count, buy_cut, buy_type
|
||||
else:
|
||||
buy_price = data['close'][i]
|
||||
buy_type = 'golden'
|
||||
buy_type = 'avg20_close_up'
|
||||
buy_ymd = data['ymd'][i]
|
||||
buy_cut = -1
|
||||
if data['slow_k'][si] < 30:
|
||||
buy_count = MAX_BUY_PRICE / (1 * data['close'][i])
|
||||
elif data['slow_k'][si] < 50:
|
||||
buy_count = MAX_BUY_PRICE / (1.5 * data['close'][i])
|
||||
else:
|
||||
buy_count = MAX_BUY_PRICE / (2 * data['close'][i])
|
||||
return buy_ymd, buy_price, buy_count, buy_cut, buy_type
|
||||
|
||||
if BUY_LIST is None:
|
||||
return buy_ymd, buy_price, buy_count, buy_cut, buy_type
|
||||
"""
|
||||
|
||||
duration = 5
|
||||
if duration < i:
|
||||
if np.average(data['trend_avg'][i - duration:i]) < data['trend_avg'][i]:
|
||||
if self.is_Support(data, i-10, observation_time = 300):
|
||||
if data['open'][i] < data['close'][i]:
|
||||
if np.max(data['high'][i-2:i]) < data['close'][i]:
|
||||
|
||||
buy_price = data['close'][i]
|
||||
buy_type = 'golden'
|
||||
buy_type = 'support_300'
|
||||
buy_ymd = data['ymd'][i]
|
||||
buy_cut = data['close'][i] * 0.995
|
||||
BUY_LIST['buy_limit'] = 0
|
||||
if data['slow_k'][si] < 30:
|
||||
buy_count = MAX_BUY_PRICE / (1 * data['close'][i])
|
||||
buy_count = MAX_BUY_PRICE*5 / (data['close'][i])
|
||||
elif data['slow_k'][si] < 50:
|
||||
buy_count = MAX_BUY_PRICE / (1.5 * data['close'][i])
|
||||
buy_count = MAX_BUY_PRICE*4 / (data['close'][i])
|
||||
else:
|
||||
buy_count = MAX_BUY_PRICE / (2 * data['close'][i])
|
||||
buy_count = MAX_BUY_PRICE*3 / (data['close'][i])
|
||||
|
||||
return buy_ymd, buy_price, buy_count, buy_cut, buy_type
|
||||
|
||||
|
||||
# 방법 3:
|
||||
#if sum(data['avg480'][i - 5:i]) < data['avg480'][i] and sum(data['avg60'][i - 5:i]) < data['avg60'][i] and sum(data['avg20'][i - 5:i]) < data['avg20'][i] and sum(data['avg5'][i - 5:i]) < data['avg5'][i]:
|
||||
if data['avg480'][i] < data['avg20'][i] < data['avg5'][i] and data['avg60'][i] < data['avg20'][i] < data['avg5'][i]:
|
||||
if BUY_LIST is not None and 0 < len(BUY_LIST['buy_list']) and BUY_LIST['buy_list'][-1]['buy_price'] < data['close'][i]:
|
||||
|
||||
buy_price = data['close'][i]
|
||||
buy_type = 'trend_up'
|
||||
buy_ymd = data['ymd'][i]
|
||||
if data['slow_k'][si] < 30:
|
||||
buy_count = MAX_BUY_PRICE / (1 * data['close'][i])
|
||||
elif data['slow_k'][si] < 50:
|
||||
buy_count = MAX_BUY_PRICE / (1.5 * data['close'][i])
|
||||
else:
|
||||
buy_count = MAX_BUY_PRICE / (2 * data['close'][i])
|
||||
|
||||
return buy_ymd, buy_price, buy_count, buy_cut, buy_type
|
||||
|
||||
if BUY_LIST is None:
|
||||
buy_price = data['close'][i]
|
||||
buy_type = 'golden'
|
||||
buy_ymd = data['ymd'][i]
|
||||
if data['slow_k'][si] < 30:
|
||||
buy_count = MAX_BUY_PRICE / (1 * data['close'][i])
|
||||
elif data['slow_k'][si] < 50:
|
||||
buy_count = MAX_BUY_PRICE / (1.5 * data['close'][i])
|
||||
else:
|
||||
buy_count = MAX_BUY_PRICE / (2 * data['close'][i])
|
||||
return buy_ymd, buy_price, buy_count, buy_cut, buy_type
|
||||
if data['slow_k'][i] < 15:
|
||||
if data['slow_k'][i-1] < data['slow_d'][i-1] and data['slow_d'][i] < data['slow_k'][i]:
|
||||
buy_price = data['close'][i]
|
||||
buy_type = 'slow_k'
|
||||
buy_ymd = data['ymd'][i]
|
||||
buy_cut = data['close'][i] * 0.995
|
||||
BUY_LIST['buy_limit'] = 0
|
||||
buy_count = MAX_BUY_PRICE * 2 / (data['close'][i])
|
||||
return buy_ymd, buy_price, buy_count, buy_cut, buy_type
|
||||
|
||||
return buy_ymd, buy_price, buy_count, buy_cut, buy_type
|
||||
|
||||
def getSellPriceAndWeight1(self, ticker, i, data, data_signal, BUY_LIST=None):
|
||||
sell_price, sell_count = -1, -1
|
||||
sell_price, sell_count, sell_type = -1, -1, ''
|
||||
|
||||
if BUY_LIST is not None and 0 < len(BUY_LIST['buy_list']):
|
||||
# 방법1에 대해서는 1% 이익시 매도 한다. (Upbit.py 파일에서)
|
||||
df_tmp = data_signal['ymd'] <= data['ymd'][i]
|
||||
df_signal = data_signal.loc[df_tmp]
|
||||
si = len(df_signal) - 1
|
||||
|
||||
# 방법2에 대한 매도
|
||||
if data['close'][i-1] < data['open'][i-1] and data['close'][i] < data['open'][i]:
|
||||
count = sum([price['buy_count'] for price in BUY_LIST['buy_list'] if price['buy_type'] == 'golden'])
|
||||
if 0 < count:
|
||||
if 0 < len(BUY_LIST['buy_list']):
|
||||
duration = 5
|
||||
if duration < i:
|
||||
if data['trend_avg'][i] < np.average(data['trend_avg'][i - duration:i]):
|
||||
if self.is_Resistance(data, i - 10, observation_time=300):
|
||||
sell_price = data['close'][i]
|
||||
sell_count = sum([price['buy_count'] for price in BUY_LIST['buy_list']])
|
||||
|
||||
if 75 < np.max(data_signal['rsi'][si-5:si]):
|
||||
if self.is_Resistance(data, i - 10, observation_time=300):
|
||||
sell_price = data['close'][i]
|
||||
sell_count = sum([price['buy_count'] for price in BUY_LIST['buy_list']])
|
||||
|
||||
down_count = [1 for c in range(i - 3, i + 1) if data['close'][c - 1] < data['open'][c]]
|
||||
if 3 <= sum(down_count):
|
||||
count = sum([price['buy_count'] for price in BUY_LIST['buy_list']])
|
||||
if 0 < count:
|
||||
sell_price = data['close'][i]
|
||||
sell_count = sum([price['buy_count'] for price in BUY_LIST['buy_list']])
|
||||
|
||||
return sell_price, sell_count
|
||||
if 70 < data['slow_k'][i]:
|
||||
if data['slow_d'][i-1] < data['slow_k'][i-1] and data['slow_k'][i] <= data['slow_d'][i]:
|
||||
sell_price = data['close'][i]
|
||||
sell_count = sum([price['buy_count'] for price in BUY_LIST['buy_list'] if price['buy_type'] == 'slow_k'])
|
||||
sell_type = 'slow_k'
|
||||
|
||||
return sell_price, sell_count, sell_type
|
||||
|
||||
def checkTransaction1(self, ticker, MAX_BUY_PRICE, data, data_signal, BUY_LIST=None, isRealTime=True):
|
||||
|
||||
@@ -225,19 +234,24 @@ class BuySellChecker():
|
||||
# isRealTime=True, 실시간 적용
|
||||
last_index = size - 1
|
||||
|
||||
sell_price, sell_weight = self.getSellPriceAndWeight1(ticker, last_index, data, data_signal, BUY_LIST)
|
||||
sell_price, sell_count, sell_type = self.getSellPriceAndWeight1(ticker, last_index, data, data_signal, BUY_LIST)
|
||||
bsLine['sell_price'] = [sell_price]
|
||||
bsLine['sell_weight'] = [sell_weight]
|
||||
bsLine['sell_count'] = [sell_count]
|
||||
bsLine['sell_type'] = [sell_type]
|
||||
|
||||
buy_ymd, buy_price, buy_count, buy_cut, buy_type = self.getBuyPriceAndWeight1(ticker, MAX_BUY_PRICE, last_index, data, data_signal, BUY_LIST, isRealTime)
|
||||
bsLine['buy_ymd'] = [buy_ymd]
|
||||
bsLine['buy_price'] = [buy_price]
|
||||
bsLine['buy_count'] = [buy_count]
|
||||
bsLine['buy_cut'] = [buy_cut]
|
||||
bsLine['buy_type'] = [buy_type]
|
||||
if 0 < sell_price:
|
||||
BUY_LIST['buy_limit'] = 0
|
||||
BUY_LIST['buy_list'].clear()
|
||||
else:
|
||||
buy_ymd, buy_price, buy_count, buy_cut, buy_type = self.getBuyPriceAndWeight1(ticker, MAX_BUY_PRICE, last_index, data, data_signal, BUY_LIST, isRealTime)
|
||||
bsLine['buy_ymd'] = [buy_ymd]
|
||||
bsLine['buy_price'] = [buy_price]
|
||||
bsLine['buy_count'] = [buy_count]
|
||||
bsLine['buy_cut'] = [buy_cut]
|
||||
bsLine['buy_type'] = [buy_type]
|
||||
|
||||
if BUY_LIST is not None and 0 < buy_price:
|
||||
BUY_LIST['buy_list'].append({'buy_ymd': buy_ymd, 'buy_price': buy_price, 'buy_count': buy_count, 'buy_cut': buy_cut, 'buy_type': buy_type})
|
||||
if 0 < buy_price:
|
||||
BUY_LIST['buy_list'].append({'buy_ymd': buy_ymd, 'buy_price': buy_price, 'buy_count': buy_count, 'buy_cut': buy_cut, 'buy_type': buy_type})
|
||||
else:
|
||||
# Type=False, 시뮬레이션 적용
|
||||
bsLine['buy_ymd'] = [-1 for i in range(size)]
|
||||
@@ -246,22 +260,27 @@ class BuySellChecker():
|
||||
bsLine['buy_cut'] = [-1 for i in range(size)]
|
||||
bsLine['buy_type'] = ['' for i in range(size)]
|
||||
bsLine['sell_price'] = [-1 for i in range(size)]
|
||||
bsLine['sell_weight'] = [-1 for i in range(size)]
|
||||
bsLine['sell_count'] = [-1 for i in range(size)]
|
||||
bsLine['sell_type'] = ['' for i in range(size)]
|
||||
|
||||
for last_index in range(size):
|
||||
|
||||
sell_price, sell_weight = self.getSellPriceAndWeight1(ticker, last_index, data, data_signal, BUY_LIST)
|
||||
sell_price, sell_count, sell_type = self.getSellPriceAndWeight1(ticker, last_index, data, data_signal, BUY_LIST)
|
||||
bsLine['sell_price'][last_index] = sell_price
|
||||
bsLine['sell_weight'][last_index] = sell_weight
|
||||
bsLine['sell_count'][last_index] = sell_count
|
||||
bsLine['sell_type'] = [sell_type]
|
||||
|
||||
if sell_price < 0:
|
||||
if 0 < sell_price:
|
||||
BUY_LIST['buy_limit'] = 0
|
||||
BUY_LIST['buy_list'].clear()
|
||||
else:
|
||||
buy_ymd, buy_price, buy_count, buy_cut, buy_type = self.getBuyPriceAndWeight1(ticker, MAX_BUY_PRICE, last_index, data, data_signal, BUY_LIST, isRealTime)
|
||||
bsLine['buy_price'][last_index] = buy_price
|
||||
bsLine['buy_count'][last_index] = buy_count
|
||||
bsLine['buy_cut'][last_index] = buy_cut
|
||||
bsLine['buy_type'][last_index] = buy_type
|
||||
|
||||
if BUY_LIST is not None and 0 < buy_price:
|
||||
if 0 < buy_price:
|
||||
BUY_LIST['buy_list'].append({'buy_ymd': buy_ymd, 'buy_price': buy_price, 'buy_count': buy_count, 'buy_cut': buy_cut, 'buy_type': buy_type})
|
||||
|
||||
else:
|
||||
@@ -270,7 +289,6 @@ class BuySellChecker():
|
||||
bsLine['buy_cut'] = [-1]
|
||||
bsLine['buy_type'] = ['']
|
||||
bsLine['sell_price'] = [-1]
|
||||
bsLine['sell_weight'] = [-1]
|
||||
|
||||
return bsLine
|
||||
bsLine['sell_count'] = [-1]
|
||||
|
||||
return bsLine
|
||||
Reference in New Issue
Block a user