fix: parse backtest end date from period string with trailing paren

Period format is "H4 (2024.12.25 - 2026.06.22)" — use regex to extract
the date before the closing paren instead of split+strip which fails on
the trailing ")".
This commit is contained in:
ZhijuCen
2026-06-25 03:12:48 +08:00
parent e0d7c3ca54
commit 99fa0477ab
+5 -4
View File
@@ -569,13 +569,14 @@ def analyze_report(report: Report) -> dict:
if not trades:
return {"error": "No trades found", "trades": []}
# Parse backtest end date from period string (e.g. "2024.01.01 - 2025.06.22")
# Parse backtest end date from period string (e.g. "H4 (2024.01.01 - 2025.06.22)")
bt_end = None
period = report.settings.period
if " - " in period:
m = re.search(r"(\d{4}\.\d{2}\.\d{2})\s*\)\s*$", period)
if m:
try:
bt_end = datetime.strptime(period.split(" - ")[1].strip(), "%Y.%m.%d")
except (ValueError, IndexError):
bt_end = datetime.strptime(m.group(1), "%Y.%m.%d")
except ValueError:
pass
# Per-trade risk check