quantlab.factor.predefined.momentum.Momentum#
- class quantlab.factor.predefined.momentum.Momentum(factor_config)[source]#
Bases:
FactorPolarsN-bar per-symbol price momentum,
Close_t / Close_{t-n} - 1.Momentum is the return a symbol earned over the last
nbars; it is the classic “recent winners keep winning” signal. The class overrides only_get_factor_lazyframe, which returns a lazy frame with justtimestamp,symboland the factor column, and lets the inheritedcompute()collect it into anxarray.Dataset. The horizonnis read fromconfig.kwargs["n"](default 20) and the output column is namedmomentum_{n}, so different config files give different signals from one class.The expression reads the store’s
Closecolumn, 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