feat: Enhance trading system with new e_min_chg_pct parameter and related logic
Changes: - Introduced the `e_min_chg_pct` parameter to define the minimum price change percentage compared to the previous day's close, enhancing the momentum trading strategy. - Updated various functions and classes to incorporate this new parameter, ensuring it is utilized in both backtesting and live trading scenarios. - Improved documentation and comments to clarify the purpose and usage of the new parameter across the codebase. Impact: - This addition allows for more precise control over trading conditions, potentially increasing the effectiveness of the momentum strategy while maintaining system integrity and performance.
This commit is contained in:
@@ -939,12 +939,14 @@ def start_optuna_job(
|
||||
trials: int = 200,
|
||||
mode: str = "tpe",
|
||||
symbol: Optional[str] = None,
|
||||
universe_history_source: Optional[str] = None,
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
subprocess 로 Optuna 시작. apply-best 없음.
|
||||
전략 2개 이상 → scripts/run_optuna_4strat_tpe_seq.sh + STRATEGIES=
|
||||
(레거시 strategy='all' → 국내 4순차, 해외 미포함)
|
||||
symbol: us_momentum 종목 cfg Optuna (1종목 유니버스). 순차잡과 병행 불가.
|
||||
universe_history_source: kiwoom|ls (저장 후보 이력 테이블).
|
||||
"""
|
||||
_ensure_dirs()
|
||||
running = find_running_jobs()
|
||||
@@ -972,8 +974,12 @@ def start_optuna_job(
|
||||
if len(picked) != 1 or picked[0] != "us_momentum":
|
||||
raise ValueError("종목 Optuna(--symbol)는 us_momentum 단독만 가능")
|
||||
|
||||
from kis_trader.backtest.universe_history_source import (
|
||||
resolve_backtest_universe_history_source,
|
||||
)
|
||||
from kis_trader.utils.kr_trading_day import clamp_to_prev_kr_trading_day
|
||||
|
||||
hist_src = resolve_backtest_universe_history_source(universe_history_source)
|
||||
start = clamp_to_prev_kr_trading_day(start)
|
||||
end = clamp_to_prev_kr_trading_day(end)
|
||||
if start > end:
|
||||
@@ -984,6 +990,7 @@ def start_optuna_job(
|
||||
|
||||
env = os.environ.copy()
|
||||
env["PYTHONUNBUFFERED"] = "1"
|
||||
env["BACKTEST_UNIVERSE_HISTORY_SOURCE"] = hist_src
|
||||
|
||||
_labels = {
|
||||
"momentum": "모멘텀",
|
||||
@@ -1009,6 +1016,7 @@ def start_optuna_job(
|
||||
env["MIN_PF"] = "0"
|
||||
env["MIN_TRADES"] = "1"
|
||||
env["STRATEGIES"] = " ".join(picked)
|
||||
env["UNIVERSE_HISTORY_SOURCE"] = hist_src
|
||||
kind = "seq"
|
||||
label = "순차(" + "+".join(_labels.get(s, s) for s in picked) + ")"
|
||||
strat_field = ",".join(picked)
|
||||
@@ -1042,6 +1050,7 @@ def start_optuna_job(
|
||||
"--no-progress",
|
||||
"--study-name", study_name,
|
||||
"--sort-by", sort_by,
|
||||
"--universe-history-source", hist_src,
|
||||
]
|
||||
if sym and strat == "us_momentum":
|
||||
cmd.extend(["--symbol", sym])
|
||||
@@ -1070,6 +1079,7 @@ def start_optuna_job(
|
||||
"trials": trials,
|
||||
"study_name": study_name,
|
||||
"symbol": sym or None,
|
||||
"universe_history_source": hist_src,
|
||||
"log_path": str(log_path),
|
||||
"pid": int(proc.pid),
|
||||
"status": "running",
|
||||
|
||||
Reference in New Issue
Block a user