Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(quantlib): use absolute sum for unmatched_weight in factor risk decomposition

santhreal5be9aa40aa71
diff --git a/agent/src/quantlib/factormodel.py b/agent/src/quantlib/factormodel.py
index 4ad3702dc..a347d62b4 100644
--- a/agent/src/quantlib/factormodel.py
+++ b/agent/src/quantlib/factormodel.py
@@ -620,7 +620,7 @@ def factor_risk_decomposition(
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").sum())
+ unmatched_weight = float(w_series.drop(index=assets, errors="ignore").abs().sum())
w = w_series.loc[assets]
X = exposures.loc[assets]