This commit is contained in:
dsyoon
2024-03-20 11:46:53 +09:00
parent 716285fed8
commit b24705e211
7 changed files with 1793 additions and 816 deletions

178
hts/BuySell_Daily.py Normal file
View File

@@ -0,0 +1,178 @@
import numpy as np
from datetime import datetime
class BuySell_Daily:
def countYangBong(self, data, i):
count = 0
for c in range(5):
if data['open'][i-c] < data['close'][i-c]:
count += 1
return count
def getBuyPrice(self, data, i, BS=None):
buy_ymd, buy_price, buy_count, buy_weight, buy_type, buy_cut = None, 0, 0, 1, '', None
tmp_buy_ymd, tmp_buy_price, tmp_buy_count, tmp_buy_type, tmp_buy_cut = self.getBuyPrice_ichimok_changeLine(data, i, BS)
if 0 < tmp_buy_count:
buy_ymd = tmp_buy_ymd; buy_price = tmp_buy_price; buy_count = tmp_buy_count; buy_type = tmp_buy_type; buy_cut = tmp_buy_cut
tmp_buy_ymd, tmp_buy_price, tmp_buy_count, tmp_buy_type, tmp_buy_cut = self.getBuyPrice_ichimok_baseLine(data, i, BS)
if 0 < tmp_buy_count:
buy_ymd = tmp_buy_ymd; buy_price = tmp_buy_price; buy_count = tmp_buy_count; buy_type = tmp_buy_type; buy_cut = tmp_buy_cut
tmp_buy_ymd, tmp_buy_price, tmp_buy_count, tmp_buy_type, tmp_buy_cut = self.getBuyPrice_ichimok_laggingSpan(data, i, BS)
if 0 < tmp_buy_count:
buy_ymd = tmp_buy_ymd; buy_price = tmp_buy_price; buy_count = tmp_buy_count; buy_type = tmp_buy_type; buy_cut = tmp_buy_cut
return buy_ymd, buy_price, buy_count, buy_type, buy_cut
def getSellPrice(self, data, i, BS=None):
sell_price, sell_count, sell_type = 0, 1, ''
sell_type_list = []
tmp_sell_price, tmp_sell_type_list = self.getSellPrice_ichimok_baseLine(data, i, BS)
sell_type_list += tmp_sell_type_list
sell_price = tmp_sell_price
if 0 < len(sell_type_list) or 0 < sell_price:
sell_type = ','.join(list(set(sell_type_list)))
return sell_price, sell_count, sell_type
def getBuyPrice_ichimok_changeLine(self, data, i, BS=None):
buy_ymd, buy_price, buy_count, buy_weight, buy_type, buy_cut = None, 0, 0, 1, '', None
check = False
id9, id26, id33, id52 = 8, 25, 32, 51
if 5 < i:
# 신저가를 갱신하지 않으면서 전환선이 떨어질 때 주가는 올라감 (기준선은 횡보, 현재 봉이 신저가가 이닐 때)
# --> 기준선이 계속 횡보하거나 떨어지면 상승하지는 않는다.
# https://www.youtube.com/watch?v=KZMP0Ssv8WI&t=432s (8:45)
if data['new_low_9'][i] == 0:
if data['changeLine'][i] < data['baseLine'][i]:
if data['changeLine'][i] < data['changeLine'][i-1] and np.min(data['close'][i-8:i]) < data['close'][i]:
if data['baseLine'][i-1] == data['baseLine'][i] < data['baseLine'][i-2]:
if 3 < self.countYangBong(data, i):
check = True
buy_type = "ichimok_changeLine_1"
buy_weight = 5
buy_cut = min(np.min(data['open'][i - 60:i]), np.min(data['close'][i - 60:i]))
if data['new_high_9'][i] == 1:
if data['changeLine'][i-1] < data['changeLine'][i] and data['baseLine'][i-1] < data['baseLine'][i]:
if data['baseLine'][i - 1] != data['baseLine'][i]:
if 0.2 < data['leadingSpan1_leadingSpan2_diff_rate'][i+id52]:
check = True
buy_type = "ichimok_changeLine_2"
buy_weight = 10
buy_cut = min(np.min(data['open'][i - 60:i]), np.min(data['close'][i - 60:i]))
if data['new_high_26'][i] == 1:
for c in range(i-15, i):
if data['changeLine'][c-1] < data['baseLine'][c] and data['baseLine'][i-1] < data['changeLine'][i]:
if 0.2 < data['leadingSpan1_leadingSpan2_diff_rate'][i + id52]:
check = True
buy_type = "ichimok_changeLine_3"
buy_weight = 10
buy_cut = min(np.min(data['open'][i - 60:i]), np.min(data['close'][i - 60:i]))
break
if check:
buy_ymd = data['ymd'][i]
buy_price = data['close'][i]
buy_count = buy_weight
return buy_ymd, buy_price, buy_count, buy_type, buy_cut
""""""""""""""""""
""""""""""""""""""
def getBuyPrice_ichimok_baseLine(self, data, i, BS=None):
buy_ymd, buy_price, buy_count, buy_weight, buy_type, buy_cut = None, 0, 0, 1, '', None
check = False
id9, id26, id33, id52 = 9, 26, 33, 52
if 5 < i:
# 기준선이 하락할 때, 전환선이 상승하는 경우를 중기 추세의 변곡이라 한다
if data['changeLine'][i-1] < data['changeLine'][i] and data['baseLine'][i] < data['baseLine'][i-1]:
if data['changeLine'][i - 1] < data['baseLine'][i-1] and data['baseLine'][i] < data['changeLine'][i]:
if data['open'][i] < data['close'][i]:
if 3 < self.countYangBong(data, i):
check = True
buy_type = "ichimok_baseLine_1"
buy_weight = 5
buy_cut = min(np.min(data['open'][i - 60:i]), np.min(data['close'][i - 60:i]))
# 기준선이 평행 때, 전환선이 상승하는 경우를 중기 추세의 변곡이라 한다
if data['changeLine'][i-1] < data['changeLine'][i] and data['baseLine'][i-3] == data['baseLine'][i-2] == data['baseLine'][i-1] == data['baseLine'][i]:
if data['changeLine'][i - 1] < data['baseLine'][i-1] and data['baseLine'][i] < data['changeLine'][i]:
if data['open'][i] < data['close'][i]:
if 3 < self.countYangBong(data, i):
check = True
buy_type = "ichimok_baseLine_1"
buy_weight = 5
buy_cut = min(np.min(data['open'][i - 60:i]), np.min(data['close'][i - 60:i]))
if check:
buy_ymd = data['ymd'][i]
buy_price = data['close'][i]
buy_count = buy_weight
return buy_ymd, buy_price, buy_count, buy_type, buy_cut
""""""""""""""""""
""""""""""""""""""
def getBuyPrice_ichimok_laggingSpan(self, data, i, BS):
buy_ymd, buy_price, buy_count, buy_weight, buy_type, buy_cut = None, 0, 0, 1, '', None
check = False
if 5 < i:
if data['laggingSpan_close_diff_rate'][i-1] <= 0 and 0 < data['laggingSpan_close_diff_rate'][i]:
check = True
buy_price = data['close'][i]
buy_count = buy_weight
buy_weight = 2
buy_type = 'laggingSpan1'
if 0 <= data['laggingSpan_avg60_diff_rate'][i-1] and data['laggingSpan_avg60_diff_rate'][i] < 0:
check = True
buy_price = data['close'][i]
buy_count = buy_weight
buy_weight = 2
buy_type = 'laggingSpan2'
if check:
buy_price = data['close'][i]
buy_count = buy_weight
return buy_ymd, buy_price, buy_count, buy_type, buy_cut
""""""""""""""""""
""""""""""""""""""
def getSellPrice_ichimok_baseLine(self, data, i, BS=None):
sell_price = 0
sell_type_list = []
check = False
id26, id52 = 26, 52
if data['new_high_9'][i] == 0:
if data['baseLine'][i-1] < data['baseLine'][i] and data['changeLine'][i] < data['changeLine'][i-1]:
check = True
sell_type_list.append('ichimok_baseLine')
if check:
sell_price = data['close'][i]
return sell_price, sell_type_list