전 봉 BB·일목 조합 분석 및 simulation 단일 실행으로 통합

9개 간격(1~1440분) BB·일목 위치 특징을 3분 타임라인에 맞춰 분석하고,
discover로 매수·매도 규칙을 찾은 뒤 HTML 차트에 해당 체결만 표시한다.
simulation_1h.py를 simulation.py로 변경했으며, 파라미터 없이 실행하면
analyze→discover→차트가 한 번에 수행된다.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dsyoon
2026-05-29 01:20:36 +09:00
parent 7d53090034
commit e218a8ea32
15 changed files with 1510 additions and 803 deletions

View File

@@ -92,7 +92,7 @@ class StrategyConfig:
use_discovered_rules: bool = False
# HTML 시뮬: discovered_rules.json (python simulation_1h.py discover)
# HTML 시뮬: discovered_rules.json (python simulation.py discover)
ACTIVE_CONFIG = StrategyConfig(
name="discovered_best",
use_discovered_rules=True,
@@ -478,6 +478,44 @@ def annotate_mtf_signals(
return df
def evaluate_discovered_live(
symbol: str,
frames: dict[int, pd.DataFrame],
df_1d: pd.DataFrame,
df_1h: pd.DataFrame,
balances: dict,
) -> TradeSignal | None:
"""
최신 3분 봉 시점에서 discovered_rules + 전 봉 BB·일목 조합으로 신호 1건.
"""
from candle_features import build_master_feature_matrix
from rule_discovery import buy_mask, load_rules, rules_have_buy, sell_mask
rules = load_rules()
if rules is None or not rules_have_buy(rules):
return None
matrix = build_master_feature_matrix(frames)
if len(matrix) < 22:
return None
last = matrix.iloc[[-1]]
ts = last.index[-1]
close = float(last["Close"].iloc[-1])
trend = get_trend_at(df_1d, df_1h, ts)
position = float(balances.get(symbol, {}).get("balance", 0) or 0)
if position >= 1.0:
if rules.sell_stop and sell_mask(last, rules, stop=True)[0]:
return TradeSignal("sell", SIGNAL_SELL_STOP, close, trend)
if sell_mask(last, rules, stop=False)[0]:
return TradeSignal("sell", SIGNAL_SELL_UPPER, close, trend)
return None
if buy_mask(last, rules)[0]:
return TradeSignal("buy", SIGNAL_BUY_LOWER, close, trend)
return None
def annotate_discovered_signals(
symbol: str,
frames: dict[int, pd.DataFrame],
@@ -494,7 +532,7 @@ def annotate_discovered_signals(
if rule_set is None or not rules_have_buy(rule_set):
raise FileNotFoundError(
"discovered_rules.json 없거나 매수 규칙이 비어 있습니다. "
"python simulation_1h.py discover 실행"
"python simulation.py 실행"
)
entry = frames.get(ENTRY_INTERVAL)