init
This commit is contained in:
@@ -12,8 +12,8 @@ def inserData(symbol, interval, data):
|
|||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
# 테이블/키 생성
|
# 테이블/키 생성
|
||||||
cursor.execute("CREATE TABLE IF NOT EXISTS " + symbol + " (period text, CODE text, NAME text, ymdhms datetime, ymd text, hms text, close REAL, open REAL, high REAL, low REAL, volume REAL)")
|
cursor.execute("CREATE TABLE IF NOT EXISTS " + symbol + " (interval text, CODE text, NAME text, ymdhms datetime, ymd text, hms text, close REAL, open REAL, high REAL, low REAL, volume REAL)")
|
||||||
cursor.execute("CREATE INDEX IF NOT EXISTS " + symbol + "_idx on " + symbol + "(CODE, ymdhms)")
|
cursor.execute("CREATE INDEX IF NOT EXISTS " + symbol + "_idx on " + symbol + "(interval, CODE, ymdhms)")
|
||||||
|
|
||||||
for i in range(len(data)):
|
for i in range(len(data)):
|
||||||
ymd = data.index[i].strftime('%Y%m%d')
|
ymd = data.index[i].strftime('%Y%m%d')
|
||||||
@@ -28,9 +28,9 @@ def inserData(symbol, interval, data):
|
|||||||
cursor.execute("SELECT * from " + symbol + " where CODE = ? and ymdhms = ? and interval = ?", (symbol, ymdhms, interval))
|
cursor.execute("SELECT * from " + symbol + " where CODE = ? and ymdhms = ? and interval = ?", (symbol, ymdhms, interval))
|
||||||
arr = cursor.fetchone()
|
arr = cursor.fetchone()
|
||||||
if arr:
|
if arr:
|
||||||
cursor.execute("UPDATE " + symbol + " SET close=?, open=?, high=?, low=?, volume=? where CODE=? and ymdhms=? and period=?", (close, open, high, low, volume, symbol, ymdhms, interval))
|
cursor.execute("UPDATE " + symbol + " SET close=?, open=?, high=?, low=?, volume=? where CODE=? and ymdhms=? and interval=?", (close, open, high, low, volume, symbol, ymdhms, interval))
|
||||||
else:
|
else:
|
||||||
cursor.execute("INSERT INTO " + symbol + " (period, CODE, NAME, ymdhms, ymd, hms, close, open, high, low, volume) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (interval, symbol, KR_COINS[symbol], ymdhms, ymd, hms, close, open, high, low, volume))
|
cursor.execute("INSERT INTO " + symbol + " (interval, CODE, NAME, ymdhms, ymd, hms, close, open, high, low, volume) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (interval, symbol, KR_COINS[symbol], ymdhms, ymd, hms, close, open, high, low, volume))
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
@@ -39,6 +39,7 @@ def inserData(symbol, interval, data):
|
|||||||
|
|
||||||
def download():
|
def download():
|
||||||
for symbol in KR_COINS:
|
for symbol in KR_COINS:
|
||||||
|
print(symbol)
|
||||||
|
|
||||||
# 1시간
|
# 1시간
|
||||||
interval = 60
|
interval = 60
|
||||||
|
|||||||
@@ -111,8 +111,14 @@ def calculate_technical_indicators(data):
|
|||||||
data['MA1440'] = data['Close'].rolling(window=1440).mean()
|
data['MA1440'] = data['Close'].rolling(window=1440).mean()
|
||||||
|
|
||||||
# --- 이격도(Deviation) 계산 ---
|
# --- 이격도(Deviation) 계산 ---
|
||||||
|
data['Deviation5'] = (data['Close'] / data['MA5']) * 100
|
||||||
data['Deviation20'] = (data['Close'] / data['MA20']) * 100
|
data['Deviation20'] = (data['Close'] / data['MA20']) * 100
|
||||||
data['Deviation40'] = (data['Close'] / data['MA40']) * 100
|
data['Deviation40'] = (data['Close'] / data['MA40']) * 100
|
||||||
|
data['Deviation120'] = (data['Close'] / data['MA120']) * 100
|
||||||
|
data['Deviation200'] = (data['Close'] / data['MA200']) * 100
|
||||||
|
data['Deviation240'] = (data['Close'] / data['MA240']) * 100
|
||||||
|
data['Deviation720'] = (data['Close'] / data['MA720']) * 100
|
||||||
|
data['Deviation1440'] = (data['Close'] / data['MA1440']) * 100
|
||||||
|
|
||||||
# 매수 타이밍을 이동평균선으로 결정
|
# 매수 타이밍을 이동평균선으로 결정
|
||||||
# 골든크로스: 단기 이동평균선이 장기 이동평균선을 상향 돌파할 때 매수
|
# 골든크로스: 단기 이동평균선이 장기 이동평균선을 상향 돌파할 때 매수
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ def run_simulation(symbol: str, interval_minutes: int, days: int = 30):
|
|||||||
line_ma40 = ax1.plot(data.index, data["MA40"], label="MA40", color="green", linewidth=1)[0]
|
line_ma40 = ax1.plot(data.index, data["MA40"], label="MA40", color="green", linewidth=1)[0]
|
||||||
line_ma120 = ax1.plot(data.index, data["MA120"], label="MA120", color="purple", linewidth=1)[0]
|
line_ma120 = ax1.plot(data.index, data["MA120"], label="MA120", color="purple", linewidth=1)[0]
|
||||||
line_ma200 = ax1.plot(data.index, data["MA200"], label="MA200", color="brown", linewidth=1)[0]
|
line_ma200 = ax1.plot(data.index, data["MA200"], label="MA200", color="brown", linewidth=1)[0]
|
||||||
line_ma240 = ax1.plot(data.index, data["MA240"], label="MA240", color="black", linewidth=1)[0]
|
line_ma240 = ax1.plot(data.index, data["MA240"], label="MA240", color="darkred", linewidth=1)[0]
|
||||||
line_ma720 = ax1.plot(data.index, data["MA720"], label="MA720", color="cyan", linewidth=1)[0]
|
line_ma720 = ax1.plot(data.index, data["MA720"], label="MA720", color="cyan", linewidth=1)[0]
|
||||||
line_ma1440 = ax1.plot(data.index, data["MA1440"], label="MA1440", color="magenta", linewidth=1)[0]
|
line_ma1440 = ax1.plot(data.index, data["MA1440"], label="MA1440", color="magenta", linewidth=1)[0]
|
||||||
|
|
||||||
@@ -308,14 +308,21 @@ def run_simulation(symbol: str, interval_minutes: int, days: int = 30):
|
|||||||
fig.canvas.mpl_connect('pick_event', on_pick)
|
fig.canvas.mpl_connect('pick_event', on_pick)
|
||||||
|
|
||||||
# Deviation subplot
|
# Deviation subplot
|
||||||
line_dev20 = ax2.plot(data.index, data['Deviation20'], color='orange', label='Dev20(C/MA20×100)')[0]
|
line_dev5 = ax2.plot(data.index, data['Deviation5'], color='red', label='Dev5')[0]
|
||||||
line_dev40 = ax2.plot(data.index, data['Deviation40'], color='blue', label='Dev40(C/MA40×100)')[0]
|
line_dev20 = ax2.plot(data.index, data['Deviation20'], color='blue', label='Dev20')[0]
|
||||||
cursor_dev = mplcursors.cursor([line_dev20, line_dev40], hover=True)
|
line_dev40 = ax2.plot(data.index, data['Deviation40'], color='green', label='Dev40')[0]
|
||||||
|
line_dev120 = ax2.plot(data.index, data['Deviation120'], color='purple', label='Dev120')[0]
|
||||||
|
line_dev200 = ax2.plot(data.index, data['Deviation200'], color='brown', label='Dev200')[0]
|
||||||
|
line_dev240 = ax2.plot(data.index, data['Deviation240'], color='darkred', label='Dev240')[0]
|
||||||
|
line_dev720 = ax2.plot(data.index, data['Deviation720'], color='cyan', label='Dev720')[0]
|
||||||
|
line_dev1440 = ax2.plot(data.index, data['Deviation1440'], color='magenta', label='Dev1440')[0]
|
||||||
|
|
||||||
|
cursor_dev = mplcursors.cursor([line_dev5, line_dev20, line_dev40, line_dev120, line_dev200, line_dev240, line_dev720, line_dev1440], hover=True)
|
||||||
cursor_dev.connect("add", lambda sel: sel.annotation.set_text(
|
cursor_dev.connect("add", lambda sel: sel.annotation.set_text(
|
||||||
f"{sel.artist.get_label()}\n날짜: {matplotlib.dates.num2date(sel.target[0]).replace(tzinfo=None).strftime('%Y-%m-%d %H:%M')}\n값: {sel.target[1]:.2f}"
|
f"{sel.artist.get_label()}\n날짜: {matplotlib.dates.num2date(sel.target[0]).replace(tzinfo=None).strftime('%Y-%m-%d %H:%M')}\n값: {sel.target[1]:.2f}"
|
||||||
))
|
))
|
||||||
line_h98 = ax2.axhline(90, color='red', linestyle='--', linewidth=1, label='90')
|
line_h90 = ax2.axhline(90, color='red', linestyle='--', linewidth=1, label='90')
|
||||||
line_h97 = ax2.axhline(95, color='green', linestyle='--', linewidth=1, label='93')
|
line_h95 = ax2.axhline(95, color='green', linestyle='--', linewidth=1, label='93')
|
||||||
ax2.set_ylabel('Deviation %')
|
ax2.set_ylabel('Deviation %')
|
||||||
legend2 = ax2.legend(loc='upper left', fontsize=9)
|
legend2 = ax2.legend(loc='upper left', fontsize=9)
|
||||||
|
|
||||||
@@ -327,7 +334,7 @@ def run_simulation(symbol: str, interval_minutes: int, days: int = 30):
|
|||||||
legend2_handles = legend2.legendHandles
|
legend2_handles = legend2.legendHandles
|
||||||
else:
|
else:
|
||||||
legend2_handles = legend2.get_lines()
|
legend2_handles = legend2.get_lines()
|
||||||
plot_lines2 = [line_dev20, line_dev40, line_h98, line_h97]
|
plot_lines2 = [line_dev5, line_dev20, line_dev40, line_dev120, line_dev200, line_dev240, line_dev720, line_dev1440, line_h90, line_h95]
|
||||||
# 레이블 기준으로 안정적 매핑
|
# 레이블 기준으로 안정적 매핑
|
||||||
for leg_handle in legend2_handles:
|
for leg_handle in legend2_handles:
|
||||||
label = leg_handle.get_label()
|
label = leg_handle.get_label()
|
||||||
|
|||||||
Reference in New Issue
Block a user