init
This commit is contained in:
@@ -170,12 +170,23 @@ def check_buy_point(data, simulation=None):
|
|||||||
if data['buy_point'].iloc[-1] != 1:
|
if data['buy_point'].iloc[-1] != 1:
|
||||||
# 코드 계속
|
# 코드 계속
|
||||||
for i in range(1, len(data)):
|
for i in range(1, len(data)):
|
||||||
|
# 이동평균선 기반 매수 조건
|
||||||
if all(data[f'MA{n}'].iloc[i] < data['MA720'].iloc[i] for n in [5, 20, 40, 120, 200, 240]) and \
|
if all(data[f'MA{n}'].iloc[i] < data['MA720'].iloc[i] for n in [5, 20, 40, 120, 200, 240]) and \
|
||||||
all(data[f'MA{n}'].iloc[i] > data[f'MA{n}'].iloc[i - 1] for n in [5, 20, 40, 120, 200, 240]) and \
|
all(data[f'MA{n}'].iloc[i] > data[f'MA{n}'].iloc[i - 1] for n in [5, 20, 40, 120, 200, 240]) and \
|
||||||
data['MA720'].iloc[i] < data['MA1440'].iloc[i]:
|
data['MA720'].iloc[i] < data['MA1440'].iloc[i]:
|
||||||
data.at[data.index[i], 'buy_signal'] = 'moving average'
|
data.at[data.index[i], 'buy_signal'] = 'moving average'
|
||||||
data.at[data.index[i], 'buy_point'] = 1
|
data.at[data.index[i], 'buy_point'] = 1
|
||||||
|
|
||||||
|
# Deviation40(이격도 40) 기반 매수 조건: 90 이하에서 상승 전환
|
||||||
|
if data['Deviation40'].iloc[i - 1] < data['Deviation40'].iloc[i] and data['Deviation40'].iloc[i - 1] <= 90:
|
||||||
|
data.at[data.index[i], 'buy_signal'] = 'deviation40'
|
||||||
|
data.at[data.index[i], 'buy_point'] = 1
|
||||||
|
|
||||||
|
# Deviation240(이격도 240) 기반 매수 조건: 90 이하에서 상승 전환
|
||||||
|
if data['Deviation240'].iloc[i - 1] < data['Deviation240'].iloc[i] and data['Deviation240'].iloc[i - 1] <= 90:
|
||||||
|
data.at[data.index[i], 'buy_signal'] = 'deviation240'
|
||||||
|
data.at[data.index[i], 'buy_point'] = 1
|
||||||
|
|
||||||
if not simulation:
|
if not simulation:
|
||||||
if data['buy_point'][-10:-1].sum() > 0:
|
if data['buy_point'][-10:-1].sum() > 0:
|
||||||
data.at[data.index[-1], 'buy_point'] = 1
|
data.at[data.index[-1], 'buy_point'] = 1
|
||||||
|
|||||||
@@ -234,23 +234,66 @@ def run_simulation(symbol: str, interval_minutes: int, days: int = 30):
|
|||||||
# 매수 포인트 탐지 및 표시
|
# 매수 포인트 탐지 및 표시
|
||||||
# 'buy_point' 열 추가
|
# 'buy_point' 열 추가
|
||||||
data['buy_point'] = 0
|
data['buy_point'] = 0
|
||||||
|
data['buy_signal'] = ''
|
||||||
for i in range(1, len(data)):
|
for i in range(1, len(data)):
|
||||||
|
# 이동평균선 기반 매수 조건
|
||||||
if all(data[f'MA{n}'].iloc[i] < data['MA720'].iloc[i] for n in [5, 20, 40, 120, 200, 240]) and \
|
if all(data[f'MA{n}'].iloc[i] < data['MA720'].iloc[i] for n in [5, 20, 40, 120, 200, 240]) and \
|
||||||
all(data[f'MA{n}'].iloc[i] > data[f'MA{n}'].iloc[i-1] for n in [5, 20, 40, 120, 200, 240]) and \
|
all(data[f'MA{n}'].iloc[i] > data[f'MA{n}'].iloc[i-1] for n in [5, 20, 40, 120, 200, 240]) and \
|
||||||
data['MA720'].iloc[i] < data['MA1440'].iloc[i]:
|
data['MA720'].iloc[i] < data['MA1440'].iloc[i]:
|
||||||
|
data.at[data.index[i], 'buy_signal'] = 'moving average'
|
||||||
data.at[data.index[i], 'buy_point'] = 1
|
data.at[data.index[i], 'buy_point'] = 1
|
||||||
|
|
||||||
# 매수 포인트를 빨간 동그라미로 표시
|
# Deviation40(이격도 40) 기반 매수 조건: 90 이하에서 상승 전환
|
||||||
buy_points = data[data['buy_point'] == 1]
|
if data['Deviation40'].iloc[i - 1] < data['Deviation40'].iloc[i] and data['Deviation40'].iloc[i - 1] <= 90:
|
||||||
scatter_buy_points = ax1.scatter(buy_points.index, buy_points['Close'], color='red', s=100, zorder=5, label='매수 포인트')
|
data.at[data.index[i], 'buy_signal'] = 'deviation40'
|
||||||
|
data.at[data.index[i], 'buy_point'] = 1
|
||||||
|
|
||||||
# 마우스 오버 기능 추가
|
# Deviation240(이격도 240) 기반 매수 조건: 90 이하에서 상승 전환
|
||||||
cursor = mplcursors.cursor(scatter_buy_points, hover=True)
|
if data['Deviation240'].iloc[i - 1] < data['Deviation240'].iloc[i] and data['Deviation240'].iloc[i - 1] <= 90:
|
||||||
|
data.at[data.index[i], 'buy_signal'] = 'deviation240'
|
||||||
|
data.at[data.index[i], 'buy_point'] = 1
|
||||||
|
|
||||||
|
# 매수 포인트를 신호 유형별로 다르게 표시
|
||||||
|
# 이동평균선 기반 매수 포인트 (빨간 동그라미)
|
||||||
|
ma_buy_points = data[(data['buy_point'] == 1) & (data['buy_signal'] == 'moving average')]
|
||||||
|
scatter_ma_buy_points = ax1.scatter(ma_buy_points.index, ma_buy_points['Close'], color='red', s=100, zorder=5, label='MA 매수 포인트')
|
||||||
|
|
||||||
|
# Deviation40 기반 매수 포인트 (속이 빈 빨간 점선 원)
|
||||||
|
dev40_buy_points = data[(data['buy_point'] == 1) & (data['buy_signal'] == 'deviation40')]
|
||||||
|
scatter_dev40_buy_points = ax1.scatter(dev40_buy_points.index, dev40_buy_points['Close'],
|
||||||
|
facecolors='none', edgecolors='red', linestyle='--',
|
||||||
|
linewidth=1, s=150, zorder=5, label='Dev40 매수 포인트')
|
||||||
|
|
||||||
|
# Deviation240 기반 매수 포인트 (속이 빈 파란 점선 원)
|
||||||
|
dev240_buy_points = data[(data['buy_point'] == 1) & (data['buy_signal'] == 'deviation240')]
|
||||||
|
scatter_dev240_buy_points = ax1.scatter(dev240_buy_points.index, dev240_buy_points['Close'],
|
||||||
|
facecolors='none', edgecolors='blue', linestyle='--',
|
||||||
|
linewidth=1, s=150, zorder=5, label='Dev240 매수 포인트')
|
||||||
|
|
||||||
|
# 마우스 오버 기능 추가 (이동평균선 매수 포인트)
|
||||||
|
if len(ma_buy_points) > 0:
|
||||||
|
cursor = mplcursors.cursor(scatter_ma_buy_points, hover=True)
|
||||||
cursor.connect("add", lambda sel: sel.annotation.set_text(
|
cursor.connect("add", lambda sel: sel.annotation.set_text(
|
||||||
f'날짜: {matplotlib.dates.num2date(sel.target[0]).replace(tzinfo=None).strftime("%Y-%m-%d %H:%M")}'
|
f'MA 매수신호\n날짜: {matplotlib.dates.num2date(sel.target[0]).replace(tzinfo=None).strftime("%Y-%m-%d %H:%M")}\n가격: {sel.target[1]:.2f}'
|
||||||
))
|
))
|
||||||
cursor.connect("remove", lambda sel: sel.annotation.set_visible(False))
|
cursor.connect("remove", lambda sel: sel.annotation.set_visible(False))
|
||||||
|
|
||||||
|
# 마우스 오버 기능 추가 (Deviation40 매수 포인트)
|
||||||
|
if len(dev40_buy_points) > 0:
|
||||||
|
cursor_dev40 = mplcursors.cursor(scatter_dev40_buy_points, hover=True)
|
||||||
|
cursor_dev40.connect("add", lambda sel: sel.annotation.set_text(
|
||||||
|
f'Dev40 매수신호\n날짜: {matplotlib.dates.num2date(sel.target[0]).replace(tzinfo=None).strftime("%Y-%m-%d %H:%M")}\n가격: {sel.target[1]:.2f}'
|
||||||
|
))
|
||||||
|
cursor_dev40.connect("remove", lambda sel: sel.annotation.set_visible(False))
|
||||||
|
|
||||||
|
# 마우스 오버 기능 추가 (Deviation240 매수 포인트)
|
||||||
|
if len(dev240_buy_points) > 0:
|
||||||
|
cursor_dev240 = mplcursors.cursor(scatter_dev240_buy_points, hover=True)
|
||||||
|
cursor_dev240.connect("add", lambda sel: sel.annotation.set_text(
|
||||||
|
f'Dev240 매수신호\n날짜: {matplotlib.dates.num2date(sel.target[0]).replace(tzinfo=None).strftime("%Y-%m-%d %H:%M")}\n가격: {sel.target[1]:.2f}'
|
||||||
|
))
|
||||||
|
cursor_dev240.connect("remove", lambda sel: sel.annotation.set_visible(False))
|
||||||
|
|
||||||
# 매수 신호에도 마우스 오버 기능 추가
|
# 매수 신호에도 마우스 오버 기능 추가
|
||||||
if scatter_buy is not None:
|
if scatter_buy is not None:
|
||||||
cursor2 = mplcursors.cursor(scatter_buy, hover=True)
|
cursor2 = mplcursors.cursor(scatter_buy, hover=True)
|
||||||
@@ -284,7 +327,7 @@ def run_simulation(symbol: str, interval_minutes: int, days: int = 30):
|
|||||||
legend_handles = legend.get_lines()
|
legend_handles = legend.get_lines()
|
||||||
plot_lines = [line_close, line_ma5, line_ma20, line_ma40, line_ma120,
|
plot_lines = [line_close, line_ma5, line_ma20, line_ma40, line_ma120,
|
||||||
line_ma200, line_ma240, line_ma720, line_ma1440,
|
line_ma200, line_ma240, line_ma720, line_ma1440,
|
||||||
line_upper, line_lower, scatter_buy_points]
|
line_upper, line_lower, scatter_ma_buy_points, scatter_dev40_buy_points, scatter_dev240_buy_points]
|
||||||
# 매수신호 scatter가 있으면 포함
|
# 매수신호 scatter가 있으면 포함
|
||||||
if scatter_buy is not None:
|
if scatter_buy is not None:
|
||||||
plot_lines.append(scatter_buy)
|
plot_lines.append(scatter_buy)
|
||||||
@@ -398,8 +441,8 @@ def run_simulation(symbol: str, interval_minutes: int, days: int = 30):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
interval = 60
|
interval = 60
|
||||||
days = 90 # 분석 기간을 90일로 늘림 (6월~8월 데이터 포함)
|
days = 90 # 분석 기간을 90일로 늘림 (6월~8월 데이터 포함)
|
||||||
#target_coins = ['ADA','APE','ARB','BONK','HBAR','LINK','ONDO','PEPE','SEI','SHIB','STORJ','SUI','TON','TRX','WLD','XLM','XRP']
|
target_coins = ['ADA','APE','ARB','BONK','HBAR','LINK','ONDO','PEPE','SEI','SHIB','STORJ','SUI','TON','TRX','WLD','XLM','XRP']
|
||||||
target_coins = ['APE']
|
#target_coins = ['APE']
|
||||||
|
|
||||||
for symbol in target_coins:
|
for symbol in target_coins:
|
||||||
print(f"\n=== {symbol} 저점 기간 분석 시작 ===")
|
print(f"\n=== {symbol} 저점 기간 분석 시작 ===")
|
||||||
|
|||||||
Reference in New Issue
Block a user