HKUDS/Vibe-Trading · error · ValueError
style drift needs at least 2 dates, got {exposure_history.sh
Error message
style drift needs at least 2 dates, got {exposure_history.shape[0]} What it means
style_drift measures change in exposures over time and needs a time series; with fewer than 2 rows in exposure_history there is no possible delta, so it raises.
Source
Thrown at agent/src/quantlib/factormodel.py:542
def style_drift(exposure_history: pd.DataFrame) -> StyleDrift:
"""Summarise how a portfolio's exposures moved over time.
Args:
exposure_history: Rows indexed by date in chronological order, one
column per factor, each cell a portfolio-level exposure from
:func:`portfolio_style_exposure`.
Returns:
A :class:`StyleDrift`.
Raises:
ValueError: If fewer than two dates are supplied -- drift is a change,
and one observation cannot express one.
"""
if exposure_history.shape[0] < 2:
raise ValueError(
f"style drift needs at least 2 dates, got {exposure_history.shape[0]}"
)
frame = exposure_history.drop(columns=["unmatched_weight"], errors="ignore")
return StyleDrift(
mean_exposure=frame.mean(),
std_exposure=frame.std(ddof=1),
first_exposure=frame.iloc[0],
last_exposure=frame.iloc[-1],
total_change=frame.iloc[-1] - frame.iloc[0],
max_abs_change=frame.diff().abs().max(),
)
def factor_return_attribution(
portfolio_exposures: pd.Series,
factor_returns: pd.Series,
portfolio_return: float,View on GitHub (pinned to 80ffdda44c)
Solutions
- Check exposure_history.shape[0] >= 2 before calling
- Widen the date window used to build the history
- If only one date exists, report zero drift instead of calling the API
Example fix
// before drift = style_drift(hist) // after drift = style_drift(hist) if len(hist) >= 2 else None
Defensive patterns
Strategy: validation
Validate before calling
assert exposure_history.shape[0] >= 2, 'need >= 2 dates for drift'
Prevention
- Check history length after any date slicing
- Report zero drift explicitly when only one rebalance exists
When it happens
Trigger: Calling style_drift with a one-row (or zero-row) history DataFrame, e.g. style_drift(exposure_history.iloc[[-1]]).
Common situations: Backfill produced only one rebalance date; date filtering (.loc[date:]) sliced history to a single point; new portfolio with one day of history.
Related errors
- holdings is empty
- exposures has no factor columns
- portfolio_weights cannot be empty
- portfolio_weights contains non-finite values
- exposures contains non-finite values
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/5c597c2343876644.
Report an issue: GitHub.