roll_beta_benchmark¶
Defined in fynance.metrics
- roll_beta_benchmark(X, B, w=252)[source]
Trailing rolling beta of the strategy against the benchmark.
Thin wrapper around
fynance.features.roll_functions.roll_betaapplied to the simple returns derived from theX/Bprice curves (see module docstring) — no new kernel, the trailing OLS-slope logic is entirely reused fromfynance.features.roll_functions.- Parameters:
- Xnp.ndarray[float64, ndim=1]
Strategy price/level curve.
- Bnp.ndarray[float64, ndim=1]
Benchmark price/level curve, same length as
X.- wint, optional
Size of the trailing window, must be an integer >= 2. Default 252.
- Returns:
- np.ndarray[float64, ndim=1]
Trailing rolling beta, same length as
X/B. The firstw - 1entries arenp.nan(insufficient history).
See also
beta,fynance.features.roll_functions.roll_beta
Examples
>>> import numpy as np >>> rng = np.random.default_rng(1) >>> b_ret = rng.normal(0., 0.01, 300) >>> B = np.concatenate([[100.], 100. * np.cumprod(1. + b_ret)]) >>> X = np.concatenate([[100.], 100. * np.cumprod(1. + 0.5 * b_ret)]) >>> rb = roll_beta_benchmark(X, B, w=63) >>> bool(np.isnan(rb[:62]).all()) True >>> round(float(np.nanmean(rb[62:])), 1) 0.5