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_beta applied to the simple returns derived from the X/B price curves (see module docstring) — no new kernel, the trailing OLS-slope logic is entirely reused from fynance.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 first w - 1 entries are np.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