alpha

Defined in fynance.metrics

alpha(X, B, period=252, rf=0.0)[source]

Annualized Jensen’s alpha of the strategy against the benchmark.

Parameters:
Xnp.ndarray[float64, ndim=1]

Strategy price/level curve.

Bnp.ndarray[float64, ndim=1]

Benchmark price/level curve, same length as X.

periodint, optional

Number of periods per year, default is 252 (trading days).

rffloat, optional

Annualized risk-free rate, default is 0.

Returns:
float

Annualized Jensen’s alpha.

See also

beta, information_ratio

Notes

With \(x\)/\(b\) the strategy’s/benchmark’s simple returns, and \(\beta\) the OLS beta (beta):

\[\alpha = period \times E\left[ \left(x - \frac{rf}{period}\right) - \beta \left(b - \frac{rf}{period}\right) \right]\]

i.e. the mean per-bar residual of the strategy’s excess return once its benchmark-driven component (\(\beta \times\) the benchmark’s excess return) is removed, annualized by period.

Examples

A strategy that mirrors the benchmark one-for-one plus a constant bar return c has alpha close to c * period and beta close to 1:

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> b_ret = rng.normal(0., 0.01, 999)
>>> B = np.concatenate([[100.], 100. * np.cumprod(1. + b_ret)])
>>> c = 0.0005
>>> x_ret = b_ret + c
>>> X = np.concatenate([[100.], 100. * np.cumprod(1. + x_ret)])
>>> round(beta(X, B), 2)
1.0
>>> round(alpha(X, B, period=252) / (c * 252), 2)
1.0