HKUDS/Vibe-Trading · error · ValueError
exposures contains non-finite values
Error message
exposures contains non-finite values
What it means
The exposures matrix must contain only finite numbers; a NaN/inf entry would propagate into x_p = Xᵀw and corrupt every risk number, so the function validates up front.
Source
Thrown at agent/src/quantlib/factormodel.py:641
Returns:
:class:`FactorRiskDecomposition` containing total/factor/specific
variances, volatilities, marginal contributions to risk (MCR), and
percentage contributions to risk (PCR) per factor and per asset.
Raises:
ValueError: If weights or matrices are empty, contain non-finite values,
or share no common assets or factors.
"""
w_series = pd.Series(portfolio_weights, dtype=float)
if w_series.empty:
raise ValueError("portfolio_weights cannot be empty")
if not np.isfinite(w_series.values).all():
raise ValueError("portfolio_weights contains non-finite values")
if not isinstance(exposures, pd.DataFrame) or exposures.empty:
raise ValueError("exposures must be a non-empty DataFrame")
if not np.isfinite(exposures.values).all():
raise ValueError("exposures contains non-finite values")
if not isinstance(factor_cov, pd.DataFrame) or factor_cov.empty:
raise ValueError("factor_cov must be a non-empty DataFrame")
if not np.isfinite(factor_cov.values).all():
raise ValueError("factor_cov contains non-finite values")
# Align assets
assets = w_series.index.intersection(exposures.index)
if assets.empty:
raise ValueError(
f"No matching assets between weights ({sorted(w_series.index)}) and exposures ({sorted(exposures.index)})"
)
unmatched_weight = float(w_series.drop(index=assets, errors="ignore").abs().sum())
w = w_series.loc[assets]
X = exposures.loc[assets]
# Align factorsView on GitHub (pinned to 80ffdda44c)
Solutions
- Locate bad cells: exposures[~np.isfinite(exposures.values)] / exposures.mask(~np.isfinite(exposures))
- Fill NaNs with 0 exposure or drop the affected assets/factors
- Fix the standardizer to guard zero std before dividing
Example fix
# before risk = factor_risk_decomposition(w, X, F) # after X = X.fillna(0.0).replace([np.inf, -np.inf], 0.0) risk = factor_risk_decomposition(w, X, F)
Defensive patterns
Strategy: validation
Validate before calling
assert np.isfinite(exposures.values).all()
Prevention
- Fill/validate NaNs at ingest (X.fillna(0))
- Guard zero-std in standardizers before dividing
When it happens
Trigger: A NaN in the asset-factor matrix from a partial data join, or inf from a bad z-score division by zero std.
Common situations: Cross-sectional standardization with zero-variance factors; sparse vendor data with missing cells not filled.
Related errors
- portfolio_weights contains non-finite values
- factor_cov contains non-finite values
- specific_variances contains non-finite values
- holdings is empty
- exposures has no factor columns
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/2413733be011aa6b.
Report an issue: GitHub.