quantlab.factor.predefined.benchmark_beta.BenchmarkBeta#
- class quantlab.factor.predefined.benchmark_beta.BenchmarkBeta(config)[source]#
Bases:
FactorEach symbol’s rolling OLS beta of one-bar returns on
config.benchmark.A one-bar return is
price[t] / price[t - 1] - 1onprice_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 thelookback_barsreturns ending at t where both are present, and is NaN when fewer thanmin_barsare. It reads nothing after t. The panel is float64, one variable,beta.- Parameters:
- configBenchmarkBetaConfig
The factor config: the symbols’
dataset, thebenchmarkand the window.
- Raises:
- ValueError
At construction, if
min_barsis below 2 or abovelookback_bars, orwarmup_barsis belowlookback_bars; oncompute, if the benchmark panel does not hold exactly one symbol.
Examples
With
stocksa price dataset andvtthe 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_configrebuilds this factor with.alias of
BenchmarkBetaConfig