quantlab.factor.predefined.residual_momentum.ResidualMomentumParameters#

class quantlab.factor.predefined.residual_momentum.ResidualMomentumParameters(regression_window=756, formation_lookback=252, skip_recent=21, ridge=1e-08, determinant_floor=1e-18, variance_floor=1e-12, emit_diagnostics=True, fama_french_csv=None, return_column='ret', risk_free_column='risk_free', market_column='mkt_rf', smb_column='smb', hml_column='hml')[source]#

Bases: object

Formula parameters for ResidualMomentumFF3, read from config.kwargs.

Every field can be set through FactorConfig.kwargs; unknown keys are refused by from_config. Windows are counted in bars of the panel the factor runs on.

Parameters:
regression_windowint, default 756

Bars in the rolling factor regression (three years of daily bars).

formation_lookbackint, default 252

Bars back from the signal bar where the formation period starts (one year of daily bars).

skip_recentint, default 21

Most recent bars left out of the formation period (one month of daily bars). Skipping the last month avoids the short-term reversal effect.

ridgefloat, default 1e-8

Small value added to each factor variance to keep the regression solvable when factors are nearly collinear.

determinant_floorfloat, default 1e-18

Smallest absolute value the factor covariance determinant may take before it is replaced, to avoid dividing by zero.

variance_floorfloat, default 1e-12

Smallest residual variance used when computing volatility.

emit_diagnosticsbool, default True

Whether the factor also exposes the regression intermediates (alpha, betas, residual sum and volatility, determinant).

fama_french_csvstr or None, default None

Path of a CSV with a date column and the four FAMA_FRENCH_COLUMNS as decimal daily returns. When set, the panel supplies only the stock return and the four series are compounded onto its bars; when None, the panel must carry all five input variables.

return_columnstr, default “ret”

Panel variable holding each stock’s return per bar (ret on a CRSP panel).

risk_free_columnstr, default “risk_free”

Name of the risk-free rate input: a panel variable, or the name the CSV’s risk_free column takes inside the graph.

market_columnstr, default “mkt_rf”

Name of the market excess return input, as above.

smb_columnstr, default “smb”

Name of the size factor input, as above.

hml_columnstr, default “hml”

Name of the value factor input, as above.

Examples

>>> params = ResidualMomentumParameters(regression_window=36,
...                                     formation_lookback=12, skip_recent=1)
>>> params.regression_window, params.formation_window
(36, 11)
property formation_window#

Bars in the formation period, formation_lookback - skip_recent.

Examples

>>> ResidualMomentumParameters().formation_window
231
classmethod from_config(config)[source]#

Build and validate parameters from config.kwargs.

Parameters:
configFactorConfig

The factor config whose kwargs holds the overrides.

Returns:
ResidualMomentumParameters

The validated parameters.

Raises:
ValueError

If config.kwargs holds an unknown key or a value that fails validate().

Examples

>>> from dataclasses import replace
>>> config = replace(config, kwargs={"regression_window": 504})
>>> ResidualMomentumParameters.from_config(config).regression_window
504
property input_columns#

Names of the five graph inputs, in the order KunQuant receives them.

Examples

>>> ResidualMomentumParameters().input_columns
('ret', 'risk_free', 'mkt_rf', 'smb', 'hml')
property panel_columns#

Panel variables the factor reads, what config.data_columns must name.

With fama_french_csv set this is the return column alone; the other four inputs come from the CSV. Without it, all five inputs are panel variables.

Examples

>>> ResidualMomentumParameters(fama_french_csv="ff3.csv").panel_columns
('ret',)
>>> ResidualMomentumParameters().panel_columns
('ret', 'risk_free', 'mkt_rf', 'smb', 'hml')
validate()[source]#

Raise if a window, a numerical floor or a column name cannot work.

Raises:
ValueError

If a window is too short, a floor is not positive, or the input column names are empty or repeated.

Examples

>>> ResidualMomentumParameters(regression_window=3).validate()
Traceback (most recent call last):
    ...
ValueError: regression_window must be at least 4 for FF3 + intercept