fix: B组trades补profit_pct+hold_days字段,兼容portfolio_sim温区预计算(否则KeyError被吞)

This commit is contained in:
xxm
2026-08-16 18:40:51 +08:00
parent 5daca7fa6b
commit ad859d3297
+6 -1
View File
@@ -112,17 +112,22 @@ def _simulate_verify(market, regime, panel, cond, tp=20, sl=10, maxh=40):
if ep <= 0:
continue
res = None
for _, fb in fut.iterrows():
hold_days = maxh
for j, (_, fb) in enumerate(fut.iterrows()):
if fb["close"] <= ep * (1 - sl / 100):
res = -sl
hold_days = j + 1
break
if fb["close"] >= ep * (1 + tp / 100):
res = tp
hold_days = j + 1
break
if res is None:
res = (fut.iloc[-1]["close"] / ep - 1) * 100
hold_days = len(fut)
trades.append(res)
trade_details.append({"entry_date": str(g.loc[i, "date"]), "pnl_pct": round(res, 2),
"profit_pct": round(res, 2), "hold_days": hold_days,
"code": str(code)})
if not trades:
return None