최초 프로젝트 업로드 (Script Auto Commit)
This commit is contained in:
59
test_compare_signals.py
Normal file
59
test_compare_signals.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import data_manager
|
||||
import strategy
|
||||
import pandas as pd
|
||||
|
||||
# 선택할 티커 (data_cache에 있어야 함)
|
||||
TICKER = '000660.KS' # 예: SK하이닉스
|
||||
START = '2022-01-01'
|
||||
END = '2023-12-31'
|
||||
|
||||
print('Loading', TICKER)
|
||||
df = data_manager.get_stock_data(TICKER, START, END)
|
||||
print('raw rows:', len(df))
|
||||
|
||||
df = df.dropna()
|
||||
print('clean rows:', len(df))
|
||||
|
||||
# Precompute LAST_PEAK if not present
|
||||
if 'LAST_PEAK' not in df.columns:
|
||||
df['LAST_PEAK'] = strategy.compute_last_peak_series(df)
|
||||
|
||||
# Vectorized signals
|
||||
vec = strategy.compute_buy_signals_vectorized(df)
|
||||
vec_buy_dates = vec[vec['BUY_SIGNAL'] == True].index.tolist()
|
||||
print('Vectorized buy count:', len(vec_buy_dates))
|
||||
|
||||
# Iterative check_buy_signal
|
||||
iter_buys = []
|
||||
for i in range(1, len(df)):
|
||||
today = df.iloc[i]
|
||||
yesterday = df.iloc[i-1]
|
||||
history = df.iloc[:i+1]
|
||||
ok, sl, stype = strategy.check_buy_signal(today, yesterday, history)
|
||||
if ok:
|
||||
iter_buys.append((history.index[i], sl, stype))
|
||||
|
||||
print('Iterative buy count:', len(iter_buys))
|
||||
|
||||
# Compare dates
|
||||
iter_dates = [d[0] for d in iter_buys]
|
||||
only_iter = sorted(set(iter_dates) - set(vec_buy_dates))
|
||||
only_vec = sorted(set(vec_buy_dates) - set(iter_dates))
|
||||
|
||||
print('Only iterative but not vectorized:', len(only_iter))
|
||||
for d in only_iter[:10]:
|
||||
print(' -', d)
|
||||
|
||||
print('Only vectorized but not iterative:', len(only_vec))
|
||||
for d in only_vec[:10]:
|
||||
print(' -', d)
|
||||
|
||||
# Compare stop loss differences for common dates
|
||||
common = sorted(set(iter_dates).intersection(set(vec_buy_dates)))
|
||||
print('Common buy dates:', len(common))
|
||||
for d in common[:10]:
|
||||
iter_sl = next(sl for (dt, sl, st) in iter_buys if dt == d)
|
||||
vec_sl = vec.loc[d, 'STOP_LOSS_PRICE']
|
||||
print(d, 'iter_sl=', iter_sl, 'vec_sl=', vec_sl)
|
||||
|
||||
print('\nDone')
|
||||
Reference in New Issue
Block a user