quantlab.factor.predefined.benchmark_beta.BenchmarkBeta#

class quantlab.factor.predefined.benchmark_beta.BenchmarkBeta(config)[source]#

Bases: Factor

Each symbol’s rolling OLS beta of one-bar returns on config.benchmark.

A one-bar return is price[t] / price[t - 1] - 1 on price_column, NaN when either price is missing, for the symbols and the benchmark alike; the benchmark is read over the same bars and placed on the symbols’ timestamps. The beta at t uses the lookback_bars returns ending at t where both are present, and is NaN when fewer than min_bars are. It reads nothing after t. The panel is float64, one variable, beta.

Parameters:
configBenchmarkBetaConfig

The factor config: the symbols’ dataset, the benchmark and the window.

Raises:
ValueError

At construction, if min_bars is below 2 or above lookback_bars, or warmup_bars is below lookback_bars; on compute, if the benchmark panel does not hold exactly one symbol.

Examples

With stocks a price dataset and vt the single-symbol VT store:

>>> beta = BenchmarkBeta(BenchmarkBetaConfig(
...     dataset=stocks, benchmark=vt, file_path="factor/beta_vt.zarr",
... ))
>>> beta.get_factor_names(), beta.warmup_bars
(('beta',), 252)
>>> list(beta.compute("2024-01-02", "2024-12-31").data_vars)
['beta']
config_cls#

The config class from_config rebuilds this factor with.

alias of BenchmarkBetaConfig