> ## Documentation Index
> Fetch the complete documentation index at: https://systematica.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Rolling

> systematica.walk_forward.rolling

## `RollingWalkForward`

```python theme={null}
RollingWalkForward(
    id: str = None,
    loader_or_data: Callable = <function load_clean_data>,
    timeframe: str = '1d',
    start: str = None,
    end: str = None,
    s1: str = 'BTCUSDT',
    s2: str = 'ETHUSDT',
    suffix: str = 'h5',
    use_close: bool = True,
    freq: str = None,
    signal_model: str = None,
    long_entries: float = nan,
    long_exits: float = nan,
    short_entries: float = nan,
    short_exits: float = nan,
    clean: bool = True,
    select_symbols: str | int | List[str | int] = None,
    portfolio_config: Dict[str, Any] = _Nothing.NOTHING,
    model_params: Dict[str, Any] = _Nothing.NOTHING,
    metrics: str | List[str] = None,
    metrics_kwargs: Dict[str, Any] = _Nothing.NOTHING,
    use_rolling: bool = False,
    storage: str | optuna.storages._base.BaseStorage = None,
    pruner: optuna.pruners._base.BasePruner = <optuna.pruners._successive_halving.SuccessiveHalvingPruner object>,
    sampler: optuna.samplers._base.BaseSampler = <optuna.samplers._tpe.sampler.TPESampler object>,
    study_name: str = None,
    direction: str | List[str] = 'maximize',
    load_if_exists: bool = False,
    n_trials: int = 100,
    n_completed_trials: int = None,
    timeout: float = None,
    n_jobs: int = 1,
    catch: Iterable[Type[Exception]] | Type[Exception] = _Nothing.NOTHING,
    callbacks: Iterable[Callable[[optuna.study.study.Study, optuna.trial._frozen.FrozenTrial], None]] | None = None,
    gc_after_trial: bool = False,
    show_progress_bar: bool = False,
    verbose: bool = True,
    tracker: Type = None,
    model: Any = None,
    preprocess_func: Callable = None,
)
```

Analyzes a statistical arbitrage model using **rolling metrics**.

Method generated by attrs for class RollingWalkForward.

### Ancestors

* `systematica.walk_forward.base.BaseWalkForward`
* `abc.ABC`
* `systematica.generic.base.Model`
* `systematica.generic.base.Feature`

### Descendants

* `systematica.api.analytics.arbitrage_index.ArbitrageIndexRolling`
* `systematica.api.analytics.meta_model.MetaModelRolling`
* `systematica.api.analytics.momentum.AverageMomentumFactorRolling`
* `systematica.api.analytics.momentum.MomentumFactorRolling`
* `systematica.api.analytics.ou_process.OUProcessRolling`
* `systematica.api.analytics.volatility.VolatilityFactorRolling`
* `systematica.api.analytics.volume_profile.VolumeProfileFactorRolling`

### Static methods

#### `check_is_valid`

```python theme={null}
check_is_valid(
    model: Any,
)
```

Validates that the model has the necessary parameters for the strategy.

Specifically, the model must have either:

* Both `window` and `minp` attributes, or
* Both `train_window` and `splitter` (set to `*_rolling`).

**Raises**:

| Type         | Description                                                                                           |
| ------------ | ----------------------------------------------------------------------------------------------------- |
| `ValueError` | If the model does not have either `window` and `minp` or `train_window` and `splitter=="*_rolling"`). |

### Instance variables

* `window: int`: Window size.

* `minp: int | None`: Minimum number of observations required.

* `all_portfolio_metrics: List[str]`: Get available rolling metrics.

### Methods

#### `get_portfolio_metrics`

```python theme={null}
get_portfolio_metrics(
    self,
    metrics: str | List[str] = None,
    metrics_kwargs: Dict[str, Any] = None,
    to_numpy: bool = False,
    validate_model: bool = True,
    portfolio_config: Dict[str, Any] = None,
) ‑> pandas.core.frame.DataFrame | numpy.ndarray
```

Computes portfolio performance metrics on a rolling basis.

**Parameters**:

| Name               | Type        | Default | Description                                                                                                   |
| ------------------ | ----------- | ------- | ------------------------------------------------------------------------------------------------------------- |
| `metrics`          | `str`       | `--`    | \| tp.List\[str], default None Portfolio performance metrics to compute. If `None`, uses the default metrics. |
| `metrics_kwargs`   | `tp.Kwargs` | `None`  | Additional keyword arguments for the metrics. Defaults to `None`.                                             |
| `to_numpy`         | `bool`      | `False` | If `True`, returns a `np.ndarray`. Default is `False`, returning a `pd.DataFrame`.                            |
| `validate_model`   | `bool`      | `True`  | Check if model parameters are valid. Defaults to `True`.                                                      |
| `portfolio_config` | `tp.Kwargs` | `None`  | Additional configuration for the portfolio simulation. Defaults to `None`.                                    |

**Returns**:

| Type                       | Description                                                  |
| -------------------------- | ------------------------------------------------------------ |
| `pd.DataFrame \| tp.Array` | DataFrame or array containing portfolio performance metrics. |
