quantlab.factor.predefined.residual_momentum.ResidualMomentumFF3#

class quantlab.factor.predefined.residual_momentum.ResidualMomentumFF3(config)[source]#

Bases: FactorKunQuant

Residual momentum estimated from a Fama-French three-factor regression.

Formula settings, the Fama-French CSV and optional column renames live in config.kwargs (see ResidualMomentumParameters). The usual setup on a CRSP daily panel names the CSV in fama_french_csv and reads only the panel’s ret; the four factor series are then compounded onto the panel’s bars by compound_onto_bars() and broadcast across symbols before they reach KunQuant. Without a CSV the panel must already carry all five inputs, broadcast across symbols.

With the defaults on daily bars, the signal at bar d fits the regression on bars d-755 to d and sums residuals over bars d-251 to d-21. It uses data up to bar d only, so it can be traded from bar d+1. config.warmup_bars is the warm-up in bars that compute reads before start, like every factor: 756 covers the regression window.

Outputs are resmom_raw (the score) and resmom_rank (its cross-sectional rank in [0, 1] per bar), plus the diagnostics listed in _DIAGNOSTIC_FACTOR_NAMES when emit_diagnostics is on. Stream mode needs the five inputs on the panel and refuses a CSV.

Parameters:
factor_configFactorConfig

The KunQuant factor config. data_columns must name exactly ResidualMomentumParameters.panel_columns, and factor_names may pick any subset of the outputs.

Raises:
ValueError

If data_columns does not match the panel columns, if factor_names names an unknown output, or if kwargs holds an unknown or invalid parameter.

Examples

dataset is a CrspStockDataset over a daily market store and ff3_daily.csv the file scripts/fama_french.py writes.

>>> config = FactorConfig(
...     warmup_bars=756,
...     dataset=dataset,
...     mode="batch",
...     data_columns=("ret",),
...     factor_names=("resmom_raw", "resmom_rank"),
...     file_path="resmom.zarr",
...     kwargs={"fama_french_csv": "downloads/fama_french/ff3_daily.csv"},
... )
>>> factor = ResidualMomentumFF3(config)
>>> factor.get_factor_names()
('resmom_raw', 'resmom_rank')
cal_stream(data, timestamp, symbols)[source]#

Advance the streaming graph by one bar; refused with fama_french_csv.

A stream pushes config.data_columns bar by bar, so the five inputs must all be panel variables.

Raises:
ValueError

If fama_french_csv is set.