skfolio.descriptor.EWMomentum#
- class skfolio.descriptor.EWMomentum(half_life=87.0, skip=21, min_periods=None, exponentiate=False)[source]#
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].
\[ \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_lifefloat, 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
RollingMomentumwindow 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=6for monthly data).- skipint, 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
0for short-term momentum.- min_periodsint, 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.- exponentiatebool, 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(X[, y])Compute exponentially weighted momentum from returns.
Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
partial_fit_transform(X[, y])Compute exponentially weighted momentum from returns.
set_params(**params)Set the parameters of this estimator.
See also
RollingMomentumFixed-window (equal-weighted) momentum.
Notes
The EWMA is initialized to zero (no bias correction).
NaNs are allowed as missing observations. Non-missing
returnsvalues 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. Theactive_maskproperty of the inputAssetPaneldistinguishes holidays from delistings.References
[1]“Returns to buying winners and selling losers: Implications for stock market efficiency” The Journal of Finance. Jegadeesh, N., & Titman, S. (1993).
Examples
>>> 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)
- fit_transform(X, y=None, **fit_params)[source]#
Compute exponentially weighted momentum from returns.
- Parameters:
- XAssetPanel
Input panel containing
returns.- yNone
Ignored. Present for compatibility with scikit-learn’s API.
- **fit_paramsdict
Additional fit parameters. Ignored.
- Returns:
- momentumndarray of shape (n_observations, n_assets)
EWMA momentum signal for each observation and asset.
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating routing information.
- get_params(deep=True)#
Get parameters for this estimator.
- Parameters:
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
- Returns:
- paramsdict
Parameter names mapped to their values.
- partial_fit_transform(X, y=None, **fit_params)[source]#
Compute exponentially weighted momentum from returns.
This method supports online updates by continuing from the current fitted state. Use
fit_transformto start from a clean state.- Parameters:
- XAssetPanel
Input panel containing
returns.- yNone
Ignored. Present for compatibility with scikit-learn’s API.
- **fit_paramsdict
Additional fit parameters. Ignored.
- Returns:
- momentumndarray of shape (n_observations, n_assets)
EWMA momentum signal for each observation and asset.
- 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:
- **paramsdict
Estimator parameters.
- Returns:
- selfestimator instance
Estimator instance.