<a id="skfolio-descriptor-ewmomentum"></a>

# skfolio.descriptor.EWMomentum

<a id="skfolio.descriptor.EWMomentum"></a>

### *class* skfolio.descriptor.EWMomentum(half_life=87.0, skip=21, min_periods=None, exponentiate=False)

Exponentially weighted momentum descriptor.

Computes an EWMA of log returns with an optional skip period to exclude the most
recent observations:

The skip period separates medium-term momentum from short-term reversal. The classic
“12-1” momentum signal uses a skip of approximately one month [[1]](#r9ed0ebc21f02-1).

$$
\[
\begin{aligned}
x(t)
    &= \log(1 + r(t)) \\[0.75em]
S(t)
    &= \lambda \cdot S(t-1)
       + (1 - \lambda) \cdot x(t - \text{skip}) \\[0.75em]
\text{momentum}(t)
    &=
    \begin{cases}
    \exp(S(t)) - 1 & \text{if } \texttt{exponentiate=True} \\
    S(t) & \text{otherwise}
    \end{cases}
\end{aligned}
\]
$$

where $\lambda = \exp(-\ln(2) / \text{half\_life})$ is the EWMA decay factor.
At observation $t$, the EWMA input is the log return from $t - \text{skip}$.
Therefore, $\text{half\_life}$ is measured on the delayed input series. An
EWMA with this half-life is comparable to a fixed window of about
$2 \cdot \text{half\_life} / \ln 2$ delayed observations, with the most recent
$\text{skip}$ observations excluded.

* **Parameters:**
  **half_life** *float, default=87.0*
  : Controls how fast old returns decay in the EWMA of
    $\log(1 + r(t - \text{skip}))$. The default of 87 approximately matches a
    [`RollingMomentum`](https://skfolio.org/generated/skfolio.descriptor.RollingMomentum.html.md#skfolio.descriptor.RollingMomentum) window of 252 observations (~1 year of daily data). To
    match a different window $W$, use
    $\text{half\_life} \approx W \cdot \ln(2) / 2 \approx 0.35 \, W$. Adjust
    for other frequencies (e.g., `half_life=6` for monthly data).

  **skip** *int, default=21*
  : Number of most recent observations to exclude before the EWMA window starts.
    Used to separate medium-term momentum from short-term reversal. The default
    assumes daily data and skips approximately one month. Set to `0` for short-term
    momentum.

  **min_periods** *int, optional*
  : Minimum number of valid delayed returns required for each asset. Until an asset
    reaches this count, its output is NaN. This warm-up period avoids exposing early
    EWMA values before the estimate has sufficiently converged from its zero
    initialization. If `None`, defaults to $\lceil\text{half\_life}\rceil$,
    with a minimum of 1.

  **exponentiate** *bool, default=False*
  : If True, output is $\exp(S(t)) - 1$ (return units). If False, output is
    $S(t)$ (EWMA of log returns; log space). Cross-sectional ranking is
    unchanged.
* **Attributes:**
  **n_assets_** *int*
  : Number of assets seen during fitting.

  **asset_names_** *ndarray of shape (n_assets,)*
  : Asset names seen during fitting.

  **momentum_** *ndarray of shape (n_assets,)*
  : Last exponentially weighted momentum value for each asset.

### Methods

| [`fit_transform`](#skfolio.descriptor.EWMomentum.fit_transform)(X[, y])         | Compute exponentially weighted momentum from returns.   |
|--------------------------------------------------------------------------------|---------------------------------------------------------|
| [`get_metadata_routing`](#skfolio.descriptor.EWMomentum.get_metadata_routing)()        | Get metadata routing of this object.                    |
| [`get_params`](#skfolio.descriptor.EWMomentum.get_params)([deep])            | Get parameters for this estimator.                      |
| [`partial_fit_transform`](#skfolio.descriptor.EWMomentum.partial_fit_transform)(X[, y]) | Compute exponentially weighted momentum from returns.   |
| [`set_params`](#skfolio.descriptor.EWMomentum.set_params)(\*\*params)        | Set the parameters of this estimator.                   |

#### SEE ALSO
[`RollingMomentum`](https://skfolio.org/generated/skfolio.descriptor.RollingMomentum.html.md#skfolio.descriptor.RollingMomentum)
: Fixed-window (equal-weighted) momentum.

### Notes

The EWMA is initialized to zero (no bias correction).

NaNs are allowed as missing observations. Non-missing `returns` values must be
finite and greater than `-1`, so $\log(1 + r)$ is finite. The EWMA state is
updated only for finite delayed log returns, and each asset’s valid-observation
count controls when its output starts. The `active_mask` property of the input
[`AssetPanel`](https://skfolio.org/generated/skfolio.containers.AssetPanel.html.md#skfolio.containers.AssetPanel) distinguishes holidays from delistings.

### References

* <a id='r9ed0ebc21f02-1'>**[1]**</a> “Returns to buying winners and selling losers: Implications for stock market efficiency” The Journal of Finance. Jegadeesh, N., & Titman, S. (1993).

### Examples

```pycon
>>> from skfolio.datasets import make_synthetic_characteristics
>>> from skfolio.descriptor import EWMomentum
>>>
>>> X = make_synthetic_characteristics()
>>>
>>> # 12-1 momentum with daily data (default)
>>> descriptor = EWMomentum()
>>> momentum = descriptor.fit_transform(X)
>>>
>>> # Short-term momentum (no skip)
>>> descriptor = EWMomentum(half_life=10, skip=0)
>>> short_term_momentum = descriptor.fit_transform(X)
>>>
>>> # Log-space output
>>> descriptor = EWMomentum(exponentiate=False)
>>> momentum_log = descriptor.fit_transform(X)
```

<a id="skfolio.descriptor.EWMomentum.fit_transform"></a>

#### fit_transform(X, y=None, \*\*fit_params)

Compute exponentially weighted momentum from returns.

* **Parameters:**
  **X** *AssetPanel*
  : Input panel containing `returns`.

  **y** *None*
  : Ignored. Present for compatibility with scikit-learn’s API.

  **\*\*fit_params** *dict*
  : Additional fit parameters. Ignored.
* **Returns:**
  **momentum** *ndarray of shape (n_observations, n_assets)*
  : EWMA momentum signal for each observation and asset.

<a id="skfolio.descriptor.EWMomentum.get_metadata_routing"></a>

#### get_metadata_routing()

Get metadata routing of this object.

Please check [User Guide](https://skfolio.org/user_guide/metadata_routing.html.md#metadata-routing) on how the routing
mechanism works.

* **Returns:**
  **routing** *MetadataRequest*
  : A `MetadataRequest` encapsulating
    routing information.

<a id="skfolio.descriptor.EWMomentum.get_params"></a>

#### get_params(deep=True)

Get parameters for this estimator.

* **Parameters:**
  **deep** *bool, default=True*
  : If True, will return the parameters for this estimator and
    contained subobjects that are estimators.
* **Returns:**
  **params** *dict*
  : Parameter names mapped to their values.

<a id="skfolio.descriptor.EWMomentum.partial_fit_transform"></a>

#### partial_fit_transform(X, y=None, \*\*fit_params)

Compute exponentially weighted momentum from returns.

This method supports online updates by continuing from the current fitted state.
Use `fit_transform` to start from a clean state.

* **Parameters:**
  **X** *AssetPanel*
  : Input panel containing `returns`.

  **y** *None*
  : Ignored. Present for compatibility with scikit-learn’s API.

  **\*\*fit_params** *dict*
  : Additional fit parameters. Ignored.
* **Returns:**
  **momentum** *ndarray of shape (n_observations, n_assets)*
  : EWMA momentum signal for each observation and asset.

<a id="skfolio.descriptor.EWMomentum.set_params"></a>

#### set_params(\*\*params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects
(such as `Pipeline`). The latter have
parameters of the form `<component>__<parameter>` so that it’s
possible to update each component of a nested object.

* **Parameters:**
  **\*\*params** *dict*
  : Estimator parameters.
* **Returns:**
  **self** *estimator instance*
  : Estimator instance.

