> ## 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.

# Momentum

> systematica.api.models.momentum

Momentum factors capture price trends across multiple time horizons, incorporating volatility adjustments and weighted scoring mechanisms to generate normalized signals between -1 and 1.

## Momentum Calculation Components

The momentum model computes scores based on the following key components:

| Component             | Description                | Function                          |
| --------------------- | -------------------------- | --------------------------------- |
| Short-term Momentum   | Recent price trends        | `get_momentum_components_nb()`    |
| Medium-term Momentum  | Intermediate price trends  | `get_momentum_components_nb()`    |
| Long-term Momentum    | Full dataset price trends  | `get_momentum_components_nb()`    |
| Volatility Adjustment | Risk normalization         | `get_volatility_adjustments_nb()` |
| Weighted Scoring      | Combined signal generation | `weighted_average_scores_nb()`    |

## API Classes for Momentum

The momentum API provides four main classes:

| Class                          | Purpose           | Core Function                   |
| ------------------------------ | ----------------- | ------------------------------- |
| `RollingMomentumFactor`        | Per-asset rolling | `rolling_momentum_nb()`         |
| `RollingAverageMomentumFactor` | Averaged rolling  | `rolling_momentum_average_nb()` |
| `MomentumFactorCV`             | Per-asset CV      | `momentum_cv(combined=False)`   |
| `AverageMomentumFactorCV`      | Averaged CV       | `momentum_cv(combined=True)`    |

## `RollingAverageMomentumFactor`

```python theme={null}
RollingAverageMomentumFactor(
    window: int = 365,
    minp: int = None,
    short_term_mom: int = 30,
    medium_term_mom: int = 50,
    short_term_vol: int = 30,
    short_term_weight: float = 0.5,
    medium_term_weight: float = 0.3,
    long_term_weight: float = 0.2,
    score_scale: float = 2.0,
)
```

Momentum variation factor for calculating and scoring momentum between two
symbols:

* **Multiple Periods**:
  The Momentum indicator is calculated through different time horizons,
  giving more weight to recent data for faster response.
* **Volatility Adjustments** : It incorporates both momentum and volatility
  adjustments to generate a normalized score.

**Workflow**:

1. **Trend Components Calculation**:
   For each symbol, calculate the short, medium and long-term momentum using
   the average price returns over specified periods.

2. **Volatility Adjustment**:
   Calculate the short-term and long-term volatility using the standard
   deviation of returns over the respective periods.

3. **Standardization**:
   Normalize the momentum components by dividing them by the corresponding
   volatility values to account for risk.

4. **Scoring Mechanism**:
   Combine the normalized scores from the short, medium and long-term periods,
   applying different weights to each based on their importance
   (e.g., more weight for short-term momentum).

5. **Signal Calculation**:
   Amplify the combined score by a scaling factor and clip the final signal to
   a range between -1 and 1 to represent the direction and strength of the
   momentum.

6. **Handling Multiple Symbols**:
   The process is repeated for each pair, with the final signal being the
   equal-weighted average, offering a broader market view.

Method generated by attrs for class RollingAverageMomentumFactor.

### Ancestors

* `systematica.models.base.BaseStatArb`
* `abc.ABC`

### Descendants

* `systematica.api.models.momentum.RollingMomentumFactor`

### Instance variables

* `long_term_weight: float`: Long term weight coefficient. Defaults to `0.2`.

* `medium_term_mom: int`: Medium term momentum window. Defaults to `50`.

* `medium_term_weight: float`: Medium term weight coefficient. Defaults to `0.3`.

* `minp: int`: Mininim period. Defaults to `None`, which means no minimum period is applied.

* `score_scale: float`: Scale final score. Defaults to `2.0`. This factor amplifies the final score, enhancing the signal strength.

* `short_term_mom: int`: Short term momentum window. Defaults to `30`.

* `short_term_vol: int`: Short term volatility window. Defaults to `30`.

* `short_term_weight: float`: Short term weight coeff. Defaults to `0.5`.

* `window: int`: The size of the rolling window. Defaults to `365`.

## `RollingMomentumFactor`

```python theme={null}
RollingMomentumFactor(
    window: int = 365,
    minp: int = None,
    short_term_mom: int = 30,
    medium_term_mom: int = 50,
    short_term_vol: int = 30,
    short_term_weight: float = 0.5,
    medium_term_weight: float = 0.3,
    long_term_weight: float = 0.2,
    score_scale: float = 2.0,
)
```

Rolling momentum variation factor for calculating and scoring momentum on
mulitple symbols. See `RollingAverageMomentumFactor`.

Method generated by attrs for class RollingMomentumFactor.

### Ancestors

* `systematica.api.models.momentum.RollingAverageMomentumFactor`
* `systematica.models.base.BaseStatArb`
* `abc.ABC`

## `MomentumFactorCV`

```python theme={null}
MomentumFactorCV(
    training_window: int = 365,
    testing_window: int = 60,
    splitter: str = 'from_custom_rolling',
    custom_splitter: str | None = None,
    custom_splitter_kwargs: dict | None = None,
    short_term_mom: int = 30,
    medium_term_mom: int = 50,
    short_term_vol: int = 30,
    short_term_weight: float = 0.5,
    medium_term_weight: float = 0.3,
    long_term_weight: float = 0.2,
    score_scale: float = 2.0,
)
```

Momentum cross-validation variation factor for calculating and scoring
momentum between two symbols.
More information, see `RollingMomentumAverageFactor`.

Method generated by attrs for class MomentumFactorCV.

### Ancestors

* `systematica.api.models.momentum.AverageMomentumFactorCV`
* `systematica.models.base.BaseStatArb`
* `abc.ABC`

## `AverageMomentumFactorCV`

```python theme={null}
AverageMomentumFactorCV(
    training_window: int = 365,
    testing_window: int = 60,
    splitter: str = 'from_custom_rolling',
    custom_splitter: str | None = None,
    custom_splitter_kwargs: dict | None = None,
    short_term_mom: int = 30,
    medium_term_mom: int = 50,
    short_term_vol: int = 30,
    short_term_weight: float = 0.5,
    medium_term_weight: float = 0.3,
    long_term_weight: float = 0.2,
    score_scale: float = 2.0,
)
```

Momentum cross-validation variation factor for calculating and scoring
momentum between two symbols.
More information, see `RollingMomentumAverageFactor`.

Method generated by attrs for class AverageMomentumFactorCV.

### Ancestors

* `systematica.models.base.BaseStatArb`
* `abc.ABC`

### Descendants

* `systematica.api.models.momentum.MomentumFactorCV`

### Instance variables

* `custom_splitter: str | None`: Custom splitter to use for data partitioning. Defaults to `None`. If set, it should be a string that matches a custom splitter function.

* `custom_splitter_kwargs: dict | None`: Additional keyword arguments for the custom splitter. Defaults to `None`. If `custom_splitter` is set, this should contain any necessary parameters for the custom splitter function.

* `long_term_weight: float`: Long term weight coeff. Defaults to `0.2`. This is the weight applied to the long-term momentum in the final score calculation.

* `medium_term_mom: int`: Medium term momentum window. Defaults to `50`. This is the window size used for medium-term momentum calculations.

* `medium_term_weight: float`: Medium term weight coeff. Defaults to `0.3`. This is the weight applied to the medium-term momentum in the final score calculation.

* `score_scale: float`: Scale final score. Defaults to `2.0`. This factor amplifies the final score, enhancing the signal strength.

* `short_term_mom: int`: Short term momentum window. Defaults to `30`. This is the window size used for short-term momentum calculations.

* `short_term_vol: int`: Short term volatility window. Defaults to `30`. This is the window size used for short-term volatility calculations.

* `short_term_weight: float`: Short term weight coeff. Defaults to `0.5`. This is the weight applied to the short-term momentum in the final score calculation.

* `splitter: str`: Default splitter to be used if custom\_splitter is not passed.  Choices are `from_rolling`, `from_custom_rolling`, `from_expanding`,  `from_custom_expanding`. Defaults to `from_custom_rolling`.

* `testing_window: int`: The size of the testing window. Defaults to `60`. This is the period used for testing the model after training on the training window.

* `training_window: int`: The size of the training window. Defaults to `365`.
