fynance.algorithms.allocation.rolling_allocation¶
-
fynance.algorithms.allocation.
rolling_allocation
(f, X, n=252, s=63, ret=True, drift=True, **kwargs)¶ Roll an algorithm of portfolio allocation.
Parameters: - f : callable
Allocation algorithm that take as parameters a subarray of
X
and**kwargs
, and return a vector (asnp.ndarray
) of weights.- X : array_like
Data matrix, each columns is a series of prices, indexes or performances, each row is a observation at time
t
.- n, s : int
Respectively the number of observations to compute weights and the number of observations to roll. Default is
n=252
ands=63
.- ret : bool, optional
If True (default) pass to
f
the returns ofX
. Otherwise passX
tof
.- drift : bool, optional
If False performance of the portfolio is computed as if we rebalance the weights of asset at each timeframe. Otherwise we let to drift the weights. Default is True.
- **kwargs
Any keyword arguments to pass to
f
.
Returns: - pd.Series
Performance of the portfolio allocated following
f
algorithm.- pd.DataFrame
Weights of the portfolio allocated following
f
algorithm.
Notes
Weights are computed on the past data from
t - n
tot
and are applied to backtest on data fromt
tot + s
.\[\forall t \in [n, T], w_{t:t+s} = f(X_{t-n:t})\]