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 and \(S(0) = 0\). At observation \(t\), the EWMA adds the log return from \(t - \text{skip}\). Only non-missing returns count toward the half-life. An EWMA with this half-life is comparable to a fixed window of about \(2 \cdot \text{half\_life} / \ln 2\) observations, excluding the most recent \(\text{skip}\) observations.
- 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 excluded from the EWMA, including those with missing returns. The default assumes daily data and skips about one month to separate medium-term momentum from short-term reversal. Set to
0to include the current return.- min_periodsint, optional
Minimum number of non-missing returns included in the EWMA for each asset, after excluding the most recent
skipobservations. Until an asset reaches this count, its output is NaN. The count restarts when the asset becomes active again. IfNone, 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). 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.
- decay_float
Exponential decay factor computed from
half_life.- min_periods_int
Minimum number of non-missing returns required per asset, resolved from
min_periodsandhalf_lifeduring fitting.
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 starts at zero and is not bias-corrected. After \(n\) returns have contributed, \(S(t)\) equals their normalized exponentially weighted average multiplied by \(1 - \lambda^n\). This factor is 50% after one half-life and 75% after two.
This scaling provides useful shrinkage toward zero for momentum signals based on short, potentially noisy return histories. It applies at the start of fitting, for late listings and after an asset becomes active again. In risk factor models, it can improve risk forecasts by reducing the influence of estimation noise. Bias correction would remove this shrinkage.
NaNs are allowed as missing observations. Non-missing
returnsvalues must be finite and greater than-1, so \(\log(1 + r)\) is finite. If the return at \(t - \text{skip}\) is missing, the EWMA and observation count remain unchanged, without decay. Whenskip > 0, a missing current return does not prevent an update using the earlier return.Setting
X.active_mask=Falseclears the asset’s history and sets its output to NaN. After the asset becomes active again, only returns from that point onward are used. The most recentskipobservations remain excluded.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) >>> >>> # Output in return units >>> descriptor = EWMomentum(exponentiate=True) >>> momentum_returns = 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.