capture_ratio¶
Defined in fynance.metrics
- capture_ratio(X, B, side='up', period=252)[source]
Up- or down-market capture ratio of the strategy against the benchmark.
Restricts to the bars where the benchmark moved in the direction given by
side('up': \(b_t > 0\);'down': \(b_t < 0\)), annualizes the strategy’s and the benchmark’s compounded return over that same subset of bars, and returns their ratio.- Parameters:
- Xnp.ndarray[float64, ndim=1]
Strategy price/level curve.
- Bnp.ndarray[float64, ndim=1]
Benchmark price/level curve, same length as
X.- side{‘up’, ‘down’}, optional
Which benchmark bars to condition on. Default is
'up'.- periodint, optional
Number of periods per year, default is 252 (trading days).
- Returns:
- float
The capture ratio,
1.0when the strategy replicates the benchmark on the selected bars,nanif the benchmark never moves in the requested direction (empty subset).
See also
benchmark_summary,beta
Notes
Let \(\mathcal{T}\) the set of bars with \(b_t > 0\) (
'up') or \(b_t < 0\) ('down'), and \(n = |\mathcal{T}|\):\[ \begin{align}\begin{aligned}annGeo(r, \mathcal{T}) = \left(\prod_{t \in \mathcal{T}} (1 + r_t)\right)^{period / n} - 1\\captureRatio = \frac{annGeo(x, \mathcal{T})}{annGeo(b, \mathcal{T})}\end{aligned}\end{align} \]A value above 1 (
'up') means the strategy out-gained the benchmark on the benchmark’s up bars; a value below 1 ('down') means the strategy lost less than the benchmark on its down bars — both read as “better” for the strategy.Examples
A strategy identical to its benchmark has both capture ratios equal to 1:
>>> import numpy as np >>> X = np.array([100., 102., 101., 105., 103., 108.]) >>> round(capture_ratio(X, X, side='up'), 6) 1.0 >>> round(capture_ratio(X, X, side='down'), 6) 1.0