rebalance_calendarΒΆ

Defined in fynance.portfolio.rebalance

rebalance_calendar(W, X, every=21)[source]

Rebalance to target weights on a fixed calendar, drift between.

The effective book is reset to the target W[t] at every bar t with t % every == 0 (bar 0 is always a rebalance bar) and left to drift with asset returns on all other bars. every = 1 reproduces the raw target series (rebalance every bar); larger periods trade less and let the book wander further from target between trades.

Parameters:
Warray_like

Target weights, shape (T, N) (a 1-D input is promoted to (T, 1) and the output squeezed back to (T,)). Long-short books are supported.

Xarray_like

Price/level panel aligned with W, same shape. Used only to drift held weights between rebalances (see _drift_step).

everyint, optional

Rebalancing period in bars; must be >= 1. Default 21.

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 every < 1.

See also

rebalance_band
rebalance_turnover_cap

Examples

>>> import numpy as np
>>> W = np.array([[0.5, 0.5], [0.5, 0.5], [0.5, 0.5]])
>>> X = np.array([[100.0, 100.0], [110.0, 90.0], [121.0, 81.0]])
>>> np.round(rebalance_calendar(W, X, every=2), 3)
array([[0.5 , 0.5 ],
       [0.55, 0.45],
       [0.5 , 0.5 ]])