quantlab.factor.predefined.momentum.Momentum#

class quantlab.factor.predefined.momentum.Momentum(factor_config)[source]#

Bases: FactorPolars

N-bar per-symbol price momentum, Close_t / Close_{t-n} - 1.

Momentum is the return a symbol earned over the last n bars; it is the classic “recent winners keep winning” signal. The class overrides only _get_factor_lazyframe, which returns a lazy frame with just timestamp, symbol and the factor column, and lets the inherited compute() collect it into an xarray.Dataset. The horizon n is read from config.kwargs["n"] (default 20) and the output column is named momentum_{n}, so different config files give different signals from one class.

The expression reads the store’s Close column, spelled as the crypto spot kline store spells it. get_lazyframe() does not rename columns, so a store that names its close price differently needs its own subclass.

Parameters:
factor_configPolarsFactorConfig

The Polars factor config. kwargs["n"] sets the horizon in bars.

Examples

>>> factor = Momentum(PolarsFactorConfig(
...     warmup_bars=20, dataset=dataset, kwargs={"n": 20},
...     file_path="momentum.zarr",
... ))
>>> factor.get_factor_names()
('momentum_20',)
>>> panel = factor.compute("2024-01-01", "2024-06-30")
property horizon#

Momentum horizon in bars, from config.kwargs["n"] (default 20).

Examples

>>> factor.horizon
20