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:
Your Name
2026-08-21 19:05:23 +09:00
parent 0ecac7cb95
commit 0780b2cdd0
76 changed files with 4648 additions and 516 deletions

View File

@@ -2745,6 +2745,10 @@
<label class="form-label param-row">trials</label>
<input type="number" class="form-control form-control-sm" id="usmom_opt_trials" value="100" min="1" max="2000" style="width:90px">
</div>
<div class="col-auto">
<label class="form-label param-row" title="이 study 완료 목표. 비우면 이번 trials">스터디 총 횟수</label>
<input type="number" class="form-control form-control-sm" id="usmom_opt_study_trials" min="0" max="5000" placeholder="비움" style="width:90px">
</div>
<div class="col-auto">
<button type="button" class="btn btn-sm btn-primary" id="usmom_opt_btn_start" onclick="usmomStockOptunaStart()">이 종목 Optuna</button>
<button type="button" class="btn btn-sm btn-outline-danger" id="usmom_opt_btn_stop" onclick="usmomStockOptunaStop()" disabled>중지</button>
@@ -2765,7 +2769,7 @@
<div class="col-12 mt-2" id="usmom_opt_results_box" style="display:none">
<div class="row g-2">
<div class="col-md-6">
<h6 class="mb-1" style="font-size:12px">학습 Top5 <small class="text-muted">results (진행바 best=1위)</small></h6>
<h6 class="mb-1" style="font-size:12px">학습 Top10 <small class="text-muted">results (진행바 best=1위)</small></h6>
<div class="table-responsive">
<table class="table table-sm table-hover mb-0" style="font-size:11px">
<thead>
@@ -2781,7 +2785,7 @@
</div>
</div>
<div class="col-md-6">
<h6 class="mb-1" style="font-size:12px">사후합격 Top5 <small class="text-muted">results_gated</small></h6>
<h6 class="mb-1" style="font-size:12px">사후합격 Top10 <small class="text-muted">results_gated</small></h6>
<div class="table-responsive">
<table class="table table-sm table-hover mb-0" style="font-size:11px">
<thead>
@@ -3777,6 +3781,10 @@
<label class="form-label param-row">trials</label>
<input type="number" id="opt_trials" class="form-control form-control-sm" style="width:90px" value="200" min="1" max="2000">
</div>
<div class="col-auto">
<label class="form-label param-row" title="이 study 완료 목표. 비우면 이번 trials 와 같음. 미달이면 후처리 안 함">스터디 총 횟수</label>
<input type="number" id="opt_study_trials" class="form-control form-control-sm" style="width:90px" min="0" max="5000" placeholder="비움=이번">
</div>
<div class="col-auto">
<label class="form-label param-row">mode</label>
<input type="text" id="opt_mode" class="form-control form-control-sm" style="width:80px" value="tpe" readonly>
@@ -3834,7 +3842,9 @@
<div id="opt_st_post" class="small text-muted mb-2">후처리 — trial 끝난 뒤 시작</div>
<div class="row g-2" style="font-size:13px">
<div class="col-md-6">
<div><span class="text-muted">상태</span> <b id="opt_st_status"></b></div>
<div><span class="text-muted">상태</span> <b id="opt_st_status" style="cursor:pointer" title="클릭하면 다른 PC 실행 명령"></b>
<button type="button" class="btn btn-sm btn-outline-secondary py-0 ms-1" onclick="optunaOpenJoinCmd()">명령</button>
</div>
<div><span class="text-muted"></span> <code id="opt_st_job"></code></div>
<div><span class="text-muted">study</span> <code id="opt_st_study" style="font-size:11px"></code></div>
<div><span class="text-muted">trial</span> <span id="opt_st_trials"></span></div>
@@ -3913,7 +3923,7 @@
</div>
<div class="card p-3 mb-3">
<h6>학습 Top5 <small class="text-muted">results · Optuna 목적함수 1위 풀 · 진행바 best=여기 1위</small></h6>
<h6>학습 Top10 <small class="text-muted">results · Optuna 목적함수 1위 풀 · 진행바 best=여기 1위 · OPTUNA_POST_TOP_N</small></h6>
<div class="table-responsive">
<table class="table table-sm table-hover mb-0" style="font-size:12px">
<thead>
@@ -3934,7 +3944,7 @@
</div>
<div class="card p-3 mb-3">
<h6>사후합격 Top5 <small class="text-muted">results_gated · 「상세」=아래 후처리 표(8방 호가)</small></h6>
<h6>사후합격 Top10 <small class="text-muted">results_gated · 「상세」=아래 후처리 표(8방 호가)</small></h6>
<div class="table-responsive">
<table class="table table-sm table-hover mb-0" style="font-size:12px">
<thead>
@@ -3955,7 +3965,12 @@
</div>
<div class="card p-3 mb-3">
<h6>안정 Top5 <small class="text-muted">results_stable · 「상세」=아래 후처리 표(8방 호가) · 손실일/최악일 게이트</small></h6>
<h6>mode_combo <small class="text-muted">축별 최빈 조립 · trial 번호 없음 · 탐색(WR/PF=0) TopN 합의 1회 실측</small></h6>
<div id="opt_mode_combo_body" class="small">완료 후 표시</div>
</div>
<div class="card p-3 mb-3">
<h6>안정 Top10 <small class="text-muted">results_stable · gated/플러스와 독립 · 게이트0이면 안정점수순 폴백</small></h6>
<div id="opt_stable_gates" class="small text-muted mb-1"></div>
<div class="table-responsive">
<table class="table table-sm table-hover mb-0" style="font-size:12px">
@@ -3976,16 +3991,16 @@
</div>
<div id="opt_postprocess_rec" class="mt-3 p-2 small" style="background:rgba(63,185,80,0.06);border:1px solid var(--border);border-radius:6px">
<div class="text-muted mb-1">후처리 비교표
<span class="text-muted">(사후합격·안정 Top5 「상세」 · 열까지 적용=뒤쪽 축은 OFF · live 참고만)</span>
<span class="text-muted">(사후합격「상세」· gated 없으면 학습Top learn# 폴백 · mode/live)</span>
</div>
<div class="mb-2">
<button class="btn btn-sm btn-outline-secondary py-0" id="opt_btn_pp_rerun" onclick="optunaRerunPostprocess()">이 잡 후처리 재실행</button>
<button class="btn btn-sm btn-warning py-0" id="opt_btn_pp_rerun" onclick="optunaRerunPostprocess()">이 잡 후처리 재실행</button>
<button class="btn btn-sm btn-outline-secondary py-0 ms-1" id="opt_btn_mode_detail" onclick="optunaSelectPostprocess('mode',1)">mode 상세</button>
<span id="opt_pp_rerun_status" class="text-muted ms-1">후처리 바가 100%·「상세 가능」이 뜬 뒤에 「상세」를 누르세요. 진짜 구 JSON만 재실행.</span>
<span id="opt_pp_rerun_status" class="text-muted ms-1">끝난 잡은 이 버튼이 켜집니다. 8방이 비면 누르세요(호가스냅 부족이면 재실행해도 동일).</span>
</div>
<div id="opt_postprocess_consensus" class="mb-1">합의: 완료 후 표시</div>
<div id="opt_postprocess_cards">
<div class="text-muted">사후합격 또는 안정 Top5에서 「상세」를 누르면 이 표가 바뀝니다.</div>
<div id="opt_postprocess_cards" style="max-height:min(72vh,680px);overflow:auto;padding-right:4px">
<div class="text-muted">사후합격 또는 안정 Top에서 「상세」를 누르면 이 표가 바뀝니다.</div>
</div>
</div>
</div>
@@ -4027,6 +4042,34 @@
</div><!-- container end -->
<script src="{{ url_for('static', filename='js/backtest.js') }}"></script>
<div id="opt_join_overlay" class="opt-join-overlay" onclick="if(event.target===this)optunaCloseJoinCmd()">
<div class="opt-join-panel" role="dialog" aria-labelledby="opt_join_title">
<div class="d-flex justify-content-between align-items-center gap-2 mb-2">
<h6 class="mb-0" id="opt_join_title">다른 PC에서 같은 study 붙이기</h6>
<button type="button" class="btn btn-sm btn-outline-secondary py-0" onclick="optunaCloseJoinCmd()">닫기</button>
</div>
<p id="opt_join_hint" class="small text-muted mb-2" style="white-space:pre-wrap"></p>
<div class="small text-muted">지금 study</div>
<code id="opt_join_study" style="font-size:11px"></code>
<div class="d-flex justify-content-between align-items-center mt-2 mb-1">
<span class="small text-muted">Linux / VM (bash)</span>
<button type="button" class="btn btn-sm btn-outline-secondary py-0" onclick="optunaCopyJoin('join')">복사</button>
</div>
<pre id="opt_join_cmd" class="opt-join-pre mb-2"></pre>
<div class="d-flex justify-content-between align-items-center mb-1">
<span class="small text-muted">Windows PowerShell (이걸 복사)</span>
<button type="button" class="btn btn-sm btn-primary py-0" onclick="optunaCopyJoin('ps')">복사</button>
</div>
<pre id="opt_join_cmd_ps" class="opt-join-pre mb-2"></pre>
<div class="d-flex justify-content-between align-items-center mb-1">
<span class="small text-muted">웹이 실행한 명령 (순차=bash · 그대로 돌리면 새 study)</span>
<button type="button" class="btn btn-sm btn-outline-secondary py-0" onclick="optunaCopyJoin('web')">복사</button>
</div>
<pre id="opt_web_cmd" class="opt-join-pre mb-2"></pre>
<div id="opt_join_all" class="small"></div>
</div>
</div>
<script src="{{ url_for('static', filename='js/backtest.js') }}?v=20260821stableMode"></script>
</body>
</html>