- Added MLFilter class to load and evaluate LightGBM model for trading signals. - Introduced retraining mechanism to update the model daily based on new data. - Created feature engineering and label building utilities for model training. - Updated bot logic to incorporate ML filter for signal validation. - Added scripts for data fetching and model training. Made-with: Cursor
30 lines
842 B
Python
30 lines
842 B
Python
from typing import Optional
|
|
|
|
|
|
def build_labels(
|
|
future_closes: list[float],
|
|
future_highs: list[float],
|
|
future_lows: list[float],
|
|
take_profit: float,
|
|
stop_loss: float,
|
|
side: str,
|
|
) -> Optional[int]:
|
|
"""
|
|
진입 이후 미래 캔들을 순서대로 확인해 TP/SL 도달 여부를 판단한다.
|
|
LONG: high >= TP → 1, low <= SL → 0
|
|
SHORT: low <= TP → 1, high >= SL → 0
|
|
둘 다 미도달 → None (학습 데이터에서 제외)
|
|
"""
|
|
for high, low in zip(future_highs, future_lows):
|
|
if side == "LONG":
|
|
if high >= take_profit:
|
|
return 1
|
|
if low <= stop_loss:
|
|
return 0
|
|
else: # SHORT
|
|
if low <= take_profit:
|
|
return 1
|
|
if high >= stop_loss:
|
|
return 0
|
|
return None
|