优化前改动

This commit is contained in:
ddrwode
2026-02-06 14:09:38 +08:00
parent 649858761e
commit e22048fe0d

View File

@@ -142,6 +142,9 @@ class BitmartFuturesTransactionConservative:
self.auto_optimize_stability_weight = float(os.getenv("BITMART_AUTO_OPT_STABILITY_WEIGHT", "0.6"))
self.auto_optimize_stress_slippage = os.getenv("BITMART_AUTO_OPT_STRESS_SLIPPAGE", "0.8,1.0,1.2,1.4")
self.auto_optimize_stress_fee = os.getenv("BITMART_AUTO_OPT_STRESS_FEE", "1.0,1.15,1.3")
self.auto_optimize_allow_method_fallback = os.getenv(
"BITMART_AUTO_OPT_ALLOW_METHOD_FALLBACK", "1"
).strip().lower() not in {"0", "false", "off", "no"}
self.auto_optimize_data_file = os.getenv("BITMART_AUTO_OPT_DATA_FILE", "").strip()
self.auto_optimize_script_path = Path(__file__).with_name("optimize_params.py")
self.auto_optimized_this_run = False
@@ -256,6 +259,20 @@ class BitmartFuturesTransactionConservative:
output_path = self.get_runtime_params_path()
output_path.parent.mkdir(parents=True, exist_ok=True)
method = str(self.auto_optimize_method).strip().lower() or "auto"
if method not in {"auto", "optuna", "random"}:
logger.warning(f"未知优化方法 {method},自动改为 auto")
method = "auto"
if method == "optuna" and self.auto_optimize_allow_method_fallback:
try:
import optuna # noqa: F401
except Exception:
logger.warning(
"当前环境未安装 optuna启动前优化自动降级为 random。"
"如需 optuna请执行: pip install optuna"
)
method = "random"
cmd = [
sys.executable,
str(script_path),
@@ -272,7 +289,7 @@ class BitmartFuturesTransactionConservative:
"--window-step-days",
str(self.auto_optimize_window_step_days),
"--method",
str(self.auto_optimize_method),
method,
"--n-trials",
str(self.auto_optimize_n_trials),
"--valid-score-weight",