fix: filter NaN in max(), remove redundant ternary, handle non-finite vbt results

This commit is contained in:
TPTBusiness
2026-05-03 00:25:58 +02:00
parent bc15434e02
commit dcd4697b75
3 changed files with 8 additions and 5 deletions
@@ -222,7 +222,7 @@ class FactorBacktester:
# Calculate return for this step
if step > 0:
prev_price = float(price_values[step - 1]) if step > 0 else current_price
prev_price = float(price_values[step - 1])
if prev_price > 0:
step_return = (current_price - prev_price) / prev_price * position
returns_history.append(step_return)
@@ -83,7 +83,8 @@ def _cross_check_with_vbt(
init_cash=10_000.0,
freq=freq,
)
return float(pf.total_return())
tr = float(pf.total_return())
return tr if np.isfinite(tr) else None
except Exception:
return None