feat: Enhance Optuna integration and logging for backtesting framework
Changes: - Added new API endpoints for continuing and confirming Optuna jobs, allowing for better management of ongoing studies. - Introduced detailed logging for tick feed tracking and order book processing, improving traceability of vendor performance during backtests. - Updated database schema to include new fields for managing Optuna study results, enhancing the ability to track study progress and outcomes. - Refactored existing functions to utilize the new logging and tracking features, ensuring consistency across the backtesting framework. Impact: - These enhancements improve the robustness and transparency of the Optuna backtesting process, facilitating better analysis and optimization of trading strategies.
This commit is contained in:
@@ -169,6 +169,12 @@ def prepare_breakout_search_context(
|
||||
_hs = resolve_backtest_universe_history_source(history_source)
|
||||
base_fixed["_universe_history_source"] = _hs
|
||||
|
||||
try:
|
||||
from kis_trader.backtest.optuna_feed_trace import log_bt_feed_chain_banner
|
||||
|
||||
log_bt_feed_chain_banner(context="Optuna-BREAKOUT")
|
||||
except Exception:
|
||||
pass
|
||||
codes_candles = _load_candles_for_search(
|
||||
start, end, base_fixed.get("lookback_min", 1), base_fixed,
|
||||
history_source=_hs,
|
||||
@@ -348,6 +354,8 @@ def run_breakout_optuna(
|
||||
direction="maximize",
|
||||
sampler=_make_sampler(sampler_name, seed),
|
||||
)
|
||||
from kis_trader.backtest.optuna_study_store import bind_study_trials, finalize_optuna_export
|
||||
bind_study_trials(study, n_trials=n_trials, log=logger)
|
||||
|
||||
def objective(trial: optuna.Trial) -> float:
|
||||
if ctx.mode == "tpe":
|
||||
@@ -491,17 +499,28 @@ def run_breakout_optuna(
|
||||
out_path, strategy="breakout", mode=ctx.mode, note="mode_combo params 저장(실측 전)", log=logger,
|
||||
)
|
||||
|
||||
enrich_out_data_with_mode_combo(
|
||||
out_data,
|
||||
evaluate_fn=_eval_mode,
|
||||
grid_keys=ctx.grid_keys,
|
||||
def _enrich() -> None:
|
||||
enrich_out_data_with_mode_combo(
|
||||
out_data,
|
||||
evaluate_fn=_eval_mode,
|
||||
grid_keys=ctx.grid_keys,
|
||||
log=logger,
|
||||
on_partial_save=_save_partial,
|
||||
)
|
||||
with open(out_path, "w", encoding="utf-8") as f:
|
||||
json.dump(out_data, f, indent=2, ensure_ascii=False)
|
||||
announce_optuna_json_path(
|
||||
out_path, strategy="breakout", mode=ctx.mode, note="최종 JSON", log=logger,
|
||||
)
|
||||
|
||||
finalize_optuna_export(
|
||||
study,
|
||||
out_data=out_data,
|
||||
out_path=out_path,
|
||||
strategy="breakout",
|
||||
mode=ctx.mode,
|
||||
enrich_fn=_enrich,
|
||||
log=logger,
|
||||
on_partial_save=_save_partial,
|
||||
)
|
||||
with open(out_path, "w", encoding="utf-8") as f:
|
||||
json.dump(out_data, f, indent=2, ensure_ascii=False)
|
||||
announce_optuna_json_path(
|
||||
out_path, strategy="breakout", mode=ctx.mode, note="최종 JSON", log=logger,
|
||||
)
|
||||
study._kis_export_path = out_path # type: ignore[attr-defined]
|
||||
return study
|
||||
|
||||
Reference in New Issue
Block a user