mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-27 15:37:44 +00:00
fix: filter NaN in max(), remove redundant ternary, handle non-finite vbt results
This commit is contained in:
@@ -576,9 +576,11 @@ def top(
|
||||
|
||||
console.print(table)
|
||||
|
||||
# Summary
|
||||
valid_ic = [r.get("ic") for r in results if r.get("ic") is not None]
|
||||
valid_sharpe = [r.get("sharpe") for r in results if r.get("sharpe") is not None]
|
||||
# Summary — filter None, NaN, and non-numeric values
|
||||
valid_ic = [v for v in (r.get("ic") for r in results)
|
||||
if isinstance(v, (int, float)) and v is not None and not np.isnan(v)]
|
||||
valid_sharpe = [v for v in (r.get("sharpe") for r in results)
|
||||
if isinstance(v, (int, float)) and v is not None and not np.isnan(v)]
|
||||
# Filter extreme outliers for average
|
||||
valid_sharpe_filtered = [s for s in valid_sharpe if abs(s or 0) < 1e6]
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user