This commit is contained in:
dsyoon
2023-11-05 20:26:04 +09:00
parent e832b629e1
commit 9dbb0c4247
4 changed files with 51 additions and 56 deletions

View File

@@ -52,26 +52,12 @@ class Simulation (HTS):
sell_line = bsLine['sell'][len(bsLine['buy'])-len(data):]
# 그래프 설정을 위한 변수를 생성한다.
data = data.astype({'open': 'int',
'high': 'int',
'low': 'int',
'close': 'int',
'volume': 'int',
'avg5': 'float',
'avg20': 'float',
'avg60': 'float',
'avg120': 'float',
'avg200': 'float',
'disparity_avg5': 'float',
'disparity_avg20': 'float',
'disparity_avg60': 'float',
'disparity_avg120': 'float',
'disparity_avg200': 'float',
'fast_k': 'float',
'slow_k': 'float',
'slow_d': 'float',
'rsi': 'float',
'rsis': 'float'
data = data.astype({'open': 'int', 'high': 'int', 'low': 'int', 'close': 'int', 'volume': 'int',
'avg5': 'float', 'avg20': 'float', 'avg60': 'float', 'avg120': 'float', 'avg200': 'float',
'disparity_avg5': 'float', 'disparity_avg20': 'float', 'disparity_avg60': 'float', 'disparity_avg120': 'float', 'disparity_avg200': 'float',
'fast_k': 'float', 'slow_k': 'float', 'slow_d': 'float',
'macd': 'float', 'macds': 'float', 'macdo': 'float',
'rsi': 'float', 'rsis': 'float'
})
buy_size = []
@@ -145,13 +131,14 @@ class Simulation (HTS):
text_list = []
for i in range(len(data['macd'])):
text = "{}<br><br>open: {}<br>close: {}<br>high: {}<br>low: {}<br>volume: {}<br><br>avg5: {:.2f}<br>avg20: {:.2f}<br>avg60: {:.2f}<br>avg200: {:.2f}<br><br>d_avg5: {:.6f}<br>d_avg20: {:.6f}<br>d_avg60: {:.6f}<br>d_avg200: {:.6f}<br>d_avg5_60: {:.6f}<br>d_avg5_200: {:.6f}<br><br>macd: {:.2f}<br>slow_k: {:.2f}<br>rsi: {:.2f}".format(
text = "{}<br><br>open: {}<br>close: {}<br>high: {}<br>low: {}<br>volume: {}<br><br>avg5: {:.2f}<br>avg20: {:.2f}<br>avg60: {:.2f}<br>avg200: {:.2f}<br><br>d_avg5: {:.6f}<br>d_avg20: {:.6f}<br>d_avg60: {:.6f}<br>d_avg200: {:.6f}<br>d_avg5_60: {:.6f}<br>d_avg5_200: {:.6f}<br>d_avg200-5: {:.6f}<br><br>macd: {:.2f}<br>slow_k: {:.2f}<br>rsi: {:.2f}".format(
data['date'][i],
data['open'][i],data['close'][i],data['high'][i],data['low'][i],data['volume'][i],
data['avg5'][i],data['avg20'][i],data['avg60'][i],data['avg200'][i],
data['disparity_avg5'][i], data['disparity_avg20'][i], data['disparity_avg60'][i], data['disparity_avg200'][i],
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]),
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]),
abs(data['disparity_avg200'][i] - data['disparity_avg5'][i]),
data['macd'][i],data['slow_k'][i],data['rsi'][i]
)
text_list.append(text)
@@ -170,8 +157,9 @@ class Simulation (HTS):
# candle_data = [avg5, avg20, avg30, avg60, avg120, avg200, buy_check, sell_check, laggingSpan, changeLine, baseLine, upper, lower, candle_stick]
# candle_data = [avg5, avg20, avg30, avg60, avg200, buy_check, sell_check, upper, lower, candle_stick]
# candle_data = [avg5, avg200, buy_check, sell_check, candle_stick]
candle_data = [buy_check, sell_check, changeLine, baseLine, changeLine, laggingSpan, candle_stick]
# candle_data = [buy_check, sell_check, changeLine, baseLine, changeLine, laggingSpan, candle_stick]
candle_data = [avg5, avg200, buy_check, sell_check, candle_stick]
volume_data = [volume_line]
disparity_data = [disparity_avg5, disparity_avg20, disparity_avg30, disparity_avg60, disparity_avg120, disparity_avg200]
macd_data = [macd_line, macd_s_line, macd_o_line]
@@ -254,7 +242,7 @@ class Simulation (HTS):
match = False
LIMIT_PRICE = []
for i, rows in enumerate(db_result):
if rows[0].replace('.', '') == ymd:
if rows[0].replace('.', '') <= ymd:
match = True
if match:
LIMIT_PRICE.append(rows[2])
@@ -302,22 +290,24 @@ if __name__ == "__main__":
PROJECT_HOME = os.getcwd()
RESOURCE_PATH = os.path.join(PROJECT_HOME, "resources")
day_list = ['20231101']
day_list = ['20231016', '20231017', '20231018', '20231019', '20231020',
'20231023', '20231024', '20231025', '20231026', '20231027',
'20231030', '20231031', '20231101', '20231102']
# to check bying
stock = {'code': '233740', 'name': 'KODEX 200선물인버스2X', 'ymd': day_list}
stock = {'code': '252670', 'name': 'KODEX 200선물인버스2X', 'ymd': day_list}
simulation = Simulation(RESOURCE_PATH, stock['code'])
simulation.simulate(stock)
#stock = {'code': '233740', 'name': 'KODEX 200선물인버스2X', 'ymd': day_list}
#stock = {'code': '122630', 'name': 'KODEX 레버리지', 'ymd': day_list}
#simulation = Simulation(RESOURCE_PATH, stock['code'])
#simulation.simulate(stock)
#stock = {'code': '233740', 'name': 'KODEX 200선물인버스2X', 'ymd': day_list}
#stock = {'code': '233740', 'name': 'KODEX 코스닥150레버리지', 'ymd': day_list}
#simulation = Simulation(RESOURCE_PATH, stock['code'])
#simulation.simulate(stock)
#stock = {'code': '233740', 'name': 'KODEX 200선물인버스2X', 'ymd': day_list}
#stock = {'code': '251340', 'name': 'KODEX 코스닥150선물인버스', 'ymd': day_list}
#simulation = Simulation(RESOURCE_PATH, stock['code'])
#simulation.simulate(stock)

View File

@@ -42,7 +42,7 @@ class BuySellChecker_122630 (BuySellChecker):
def checkTransaction(self, stock_code, data, INFO, isRealTime=True):
sell, weight = -1, -1
if data['close'][i] < INFO['LOW_PRICE'] < data['close'][i-1]:
if data['close'][i] < INFO['LIMIT_PRICE'] < data['close'][i-1]:
sell = data['close'][i]
weight = 1

View File

@@ -42,7 +42,7 @@ class BuySellChecker_251340 (BuySellChecker):
def getSellPriceAndWeight(self, stock_code, i, data, INFO):
sell, weight = -1, -1
if data['close'][i] < INFO['LOW_PRICE'] < data['close'][i-1]:
if data['close'][i] < INFO['LIMIT_PRICE'] < data['close'][i-1]:
sell = data['close'][i]
weight = 1

View File

@@ -11,42 +11,47 @@ class BuySellChecker_252670 (BuySellChecker):
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])
C_DIFF_AVG_200_5 = abs(data['disparity_avg200'][i] - data['disparity_avg5'][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]:
if 0.004 < C_MIN_AVG_5_60 < 0.005 and 0.007 < C_MIN_AVG_5_200 < 0.008 and 0.007 < C_DIFF_AVG_200_5 < 0.008:
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]:
if 0.023 < C_MIN_AVG_5_60 < 0.024 and 0.026 < C_MIN_AVG_5_200 < 0.027 and 0.026 < C_DIFF_AVG_200_5 < 0.027:
buy = data['close'][i]
weight = 1
if 0.013 < C_MIN_AVG_5_60 < 0.014 and 0.013 < C_MIN_AVG_5_200 < 0.014 and 0.013 < C_DIFF_AVG_200_5 < 0.014:
buy = data['close'][i]
weight = 1
if 0.004 < C_MIN_AVG_5_60 < 0.005 and 0.005 < C_MIN_AVG_5_200 < 0.006 and 0.0008 < C_DIFF_AVG_200_5 < 0.001:
buy = data['close'][i]
weight = 1
if 0.001 < C_MIN_AVG_5_60 < 0.0015 and 0.0055 < C_MIN_AVG_5_200 < 0.006 and 0.0055 < C_DIFF_AVG_200_5 < 0.006:
buy = data['close'][i]
weight = 1
if 0.001 < C_MIN_AVG_5_60 < 0.0015 and 0.0015 < C_MIN_AVG_5_200 < 0.002 and 0.0015 < C_DIFF_AVG_200_5 < 0.002:
buy = data['close'][i]
weight = 1
if 0.009 < C_MIN_AVG_5_60 < 0.0095 and 0.01 < C_MIN_AVG_5_200 < 0.012 and 0.01 < C_DIFF_AVG_200_5 < 0.012:
buy = data['close'][i]
weight = 1
if 0.002 < C_MIN_AVG_5_60 < 0.0023 and 0.0062 < C_MIN_AVG_5_200 < 0.0068 and 0.0062 < C_DIFF_AVG_200_5 < 0.0068:
buy = data['close'][i]
weight = 1
if 0.008 < C_MIN_AVG_5_60 < 0.0085 and 0.008 < C_MIN_AVG_5_200 < 0.0085 and 0.0075 < C_DIFF_AVG_200_5 < 0.008:
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]:
if data['close'][i] < INFO['LIMIT_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 (5 < 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]