#### Previous topic

fynance.algorithms.allocation.MVP_uc

#### Next topic

BackTest (fynance.backtest)

# 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 (as np.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 and s=63. ret : bool, optional If True (default) pass to f the returns of X. Otherwise pass X to f. 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. 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 to t and are applied to backtest on data from t to t + s.

$\forall t \in [n, T], w_{t:t+s} = f(X_{t-n:t})$