quantlab.factor.base#
Abstract factor layer: Factor, the backend-agnostic base class of every factor.
A factor turns market data into engineered features, for example a
20-day momentum or a moving-average deviation. It reads a panel of
a dataset (an xarray.Dataset indexed by timestamp and symbol)
and produces a panel of the same shape. A label is a factor wrapped in
quantlab.label.forward.Forward, which shifts it forward to make a
prediction target such as a forward return.
Factor is the backend-agnostic contract the model layer programs
against. Its two computation backends live in the factor layer:
quantlab.factor.kunquant.FactorKunQuant (a KunQuant operator graph, batch
and streaming) and quantlab.factor.polars.FactorPolars (a Polars
expression chain, batch only). Shipped factor sets live under
quantlab/factor/predefined and labels under quantlab/label.
Rolling operators need history before the first bar they report. That extra
history is the warm-up. compute(start, end) reads config.warmup_bars
bars before start, counted on the input dataset’s own calendar, and trims
them off again.
A factor’s output is not always on its dataset’s bars: a factor made with
Factor.resample is on the resampled bars. The factor calendar, the
bars of the output panel, is what calendar, bar_before and
bar_after answer on (ADR 0051); a consumer counting bars of a factor
(a model’s warm-up, a label’s lookahead) counts on them, never on
config.dataset, whose calendar only the factor’s own warm-up reads.
Classes
Backend-agnostic base class for factors and labels. |