rebalance_turnover_cap¶
Defined in fynance.portfolio.rebalance
- rebalance_turnover_cap(W, X, budget=0.10)[source]
Move toward the target each bar under a per-bar turnover budget.
Each bar the held book is drifted with asset returns, then traded toward the current target
W[t]— but the trade \(\Delta w = E_t - w^{\text{drift}}_t\) is capped so its one-way turnover \(\sum_i |\Delta w_i|\) never exceeds budget. When the desired move is larger than the budget the whole trade vector is scaled down bybudget / desired(its direction preserved, only its size shrunk), so the book eases toward a persistent target over several bars instead of snapping in one. The book starts flat, so the initial entry is throttled by the same budget.- Parameters:
- Warray_like
Target weights, shape
(T, N)(1-D promoted to(T, 1), output squeezed back). Long-short books are supported.- Xarray_like
Price/level panel aligned with W, same shape.
- budgetfloat, optional
Maximum one-way turnover
sum_i |dw_i|allowed per bar; must be>= 0. Default 0.10.
- Returns:
- np.ndarray
Effective weights actually held, same shape as W.
- Raises:
- ValueError
If W and X do not share the same shape, contain non-finite values, or
budget < 0.
See also
rebalance_calendarrebalance_band
Examples
A 50% budget lets an all-in-asset-0 to all-in-asset-1 target ease over several bars; the first bar can move at most 0.5 of turnover from flat:
>>> import numpy as np >>> W = np.array([[1.0, 0.0], [0.0, 1.0]]) >>> X = np.array([[100.0, 100.0], [100.0, 100.0]]) >>> E = rebalance_turnover_cap(W, X, budget=0.5) >>> np.round(E[0], 3) array([0.5, 0. ])