Add Direction label and PM probe diagnostics

This commit is contained in:
Codex
2026-06-28 09:00:15 +08:00
parent 5ad77ffe90
commit e8420f76fe
8 changed files with 634 additions and 16 deletions
+5 -4
View File
@@ -165,7 +165,8 @@ def integrated_backtest(args: Any) -> None:
price_plan,
)
stress_trades["eval_split"] = LATEST_STRESS_SPLIT
trades = pd.concat([tune_trades, validation_locked_trades, stress_trades], ignore_index=True)
trade_parts = [part for part in (tune_trades, validation_locked_trades, stress_trades) if not part.empty]
trades = pd.concat(trade_parts, ignore_index=True) if trade_parts else _empty_trade_frame()
metrics = {
TUNE_SPLIT: _trade_metrics(tune_trades),
VALIDATION_LOCKED_SPLIT: _trade_metrics(validation_locked_trades),
@@ -281,7 +282,7 @@ def _probability_implied_edge(entry_prob: pd.Series, price_plan: dict[str, Any])
price_plan.get("costBps", DEFAULT_BACKTEST_PRICE_PLAN["costBps"])
)
probability = pd.to_numeric(entry_prob, errors="coerce").fillna(0.0).clip(lower=0.0, upper=1.0)
# Entry 的概率头比收益回归头稳定。这里用固定止盈止损的盈亏比把概率换成期望收益,
# Entry 的概率头比收益回归头稳定。这里用当前价格计划的盈亏比把概率换成期望收益,
# 让低命中、高赔率计划也能被 PM 正常搜索;真实结果仍由标签里的实际路径收益评估。
return probability * target_net_bps + (1.0 - probability) * stop_net_bps
@@ -690,7 +691,7 @@ def _write_pm_report(path, candidates: pd.DataFrame, best_thresholds: dict[str,
lines = [
"# PM Threshold Report",
"",
"本次不是固定写死阈值,而是在调参集上试一组可复现的阈值。PM 回测使用固定止盈止损后的真实净收益,并且开仓后按持仓结束时间加冷却时间阻止重叠开仓。",
"本次不是固定写死阈值,而是在调参集上试一组可复现的阈值。PM 回测使用当前价格计划的真实净收益,并且开仓后按持仓结束时间加冷却时间阻止重叠开仓。",
"",
"## Best Thresholds",
"",
@@ -716,7 +717,7 @@ def _write_backtest_report(path, result: dict[str, Any]) -> None:
lines = [
"# Integrated Backtest Report",
"",
"这里用验证集模型输出和 PM 阈值生成交易明细,统计净收益、胜率、回撤和分段表现。收益按固定止盈止损计划的真实净收益计算,不使用窗口内最大可拿收益。",
"这里用验证集模型输出和 PM 阈值生成交易明细,统计净收益、胜率、回撤和分段表现。收益按当前价格计划的真实净收益计算,不使用窗口内最大可拿收益。",
"",
"```json",
str(result).replace("'", '"'),