stratstat 0.1.0__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stratstat-0.1.0/src/stratstat.egg-info → stratstat-0.2.0}/PKG-INFO +14 -13
- {stratstat-0.1.0 → stratstat-0.2.0}/README.md +13 -12
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/__init__.py +1 -1
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/benchmark.py +109 -18
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/compare.py +17 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/exposure.py +52 -6
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/returns/descriptive.py +447 -55
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/returns/inference.py +45 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/returns/risk.py +167 -17
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/returns/risk_adjusted.py +23 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/trades.py +179 -9
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/registry.py +54 -5
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/results.py +13 -1
- stratstat-0.2.0/src/stratstat/units.py +113 -0
- {stratstat-0.1.0 → stratstat-0.2.0/src/stratstat.egg-info}/PKG-INFO +14 -13
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat.egg-info/SOURCES.txt +2 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_results.py +66 -0
- stratstat-0.2.0/tests/test_units.py +327 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/LICENSE +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/pyproject.toml +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/setup.cfg +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/container.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/conventions.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/__init__.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/_utils.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/returns/__init__.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/core/returns/wrappers.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/exceptions.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/inputs.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/py.typed +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/report/__init__.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/report/_charts.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/report/_common.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/report/_dashboard.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/report/_export.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/report/_report.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/report/_tearsheet.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat/schema.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat.egg-info/dependency_links.txt +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat.egg-info/requires.txt +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/src/stratstat.egg-info/top_level.txt +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_api.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_boundaries.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_container.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_conventions.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_exceptions.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_input_routing.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_inputs.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_kwarg_validation.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_registry.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_rf_propagation.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_schema.py +0 -0
- {stratstat-0.1.0 → stratstat-0.2.0}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stratstat
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Quantitative strategy evaluation statistics — the modern successor to empyrical, pyfolio, and QuantStats.
|
|
5
5
|
Author: Syed Qaisar Jalil
|
|
6
6
|
License: MIT
|
|
@@ -62,12 +62,12 @@ Strategy evaluation statistics for Python. One library that replaces
|
|
|
62
62
|
`empyrical`, `pyfolio`, and `QuantStats` with more metrics, a cleaner API, and
|
|
63
63
|
faster computation.
|
|
64
64
|
|
|
65
|
-
StratStat computes
|
|
65
|
+
StratStat computes 182 statistics across five input tiers. Give it a return
|
|
66
66
|
series, a trade log, positions, a benchmark, or several strategies, and it
|
|
67
67
|
returns typed results with the formula and its citation attached to every
|
|
68
68
|
number.
|
|
69
69
|
|
|
70
|
-
> **Status:** early release, version 0.
|
|
70
|
+
> **Status:** early release, version 0.2.0. The metric and report APIs work
|
|
71
71
|
> today, but several planned features are not implemented yet, including batch
|
|
72
72
|
> strategy computation, resampling of irregular bars, and reconstruction of
|
|
73
73
|
> positions from a trade log. The public API may still change before 1.0.
|
|
@@ -94,11 +94,12 @@ Three libraries (`empyrical`, `pyfolio`, `QuantStats`) split strategy
|
|
|
94
94
|
evaluation across three incompatible APIs. StratStat is one library with more
|
|
95
95
|
metrics, one call shape, and the working shown on every number.
|
|
96
96
|
|
|
97
|
-
- **More coverage.**
|
|
97
|
+
- **More coverage.** 182 metrics across five input tiers (returns, benchmark,
|
|
98
98
|
exposure, trades, compare). QuantStats exposes roughly 75.
|
|
99
99
|
- **Provenance on every result.** Every `MetricResult` carries its name,
|
|
100
|
-
category, annualization factor,
|
|
101
|
-
|
|
100
|
+
category, annualization factor, machine readable units (a closed vocabulary,
|
|
101
|
+
with per output units when a result mixes scales), and the citation for its
|
|
102
|
+
formula, so you can reproduce a number and defend it.
|
|
102
103
|
- **No engine lock in.** Pass numpy arrays, pandas objects, polars objects, or
|
|
103
104
|
plain dicts. The core runs on numpy only, no scipy, so it works on a headless
|
|
104
105
|
server.
|
|
@@ -232,19 +233,19 @@ was skipped, excluded, and deduplicated, so nothing is dropped silently.
|
|
|
232
233
|
|
|
233
234
|
## Metrics
|
|
234
235
|
|
|
235
|
-
|
|
236
|
+
182 metrics across eight categories. Each returns a `MetricResult` with a
|
|
236
237
|
`meta["ref"]` citation. The full list with formulas is in the
|
|
237
238
|
[formula reference](docs/formula-reference.md).
|
|
238
239
|
|
|
239
240
|
| Category | Count | What it measures | Example metrics |
|
|
240
241
|
|---|---|---|---|
|
|
241
|
-
| Descriptive |
|
|
242
|
+
| Descriptive | 30 | Distribution and summary of returns | `cagr`, `annualized_volatility`, `rolling_summary` |
|
|
242
243
|
| Risk | 24 | Downside, tail, and drawdown risk | `max_drawdown`, `var`, `cvar` |
|
|
243
244
|
| Risk adjusted | 23 | Return per unit of risk | `sharpe_ratio`, `sortino_ratio`, `calmar_ratio` |
|
|
244
245
|
| Inference | 14 | Confidence and significance of performance | `psr`, `sharpe_ci_analytic`, `bias_ratio` |
|
|
245
|
-
| Benchmark |
|
|
246
|
+
| Benchmark | 22 | Performance relative to a benchmark | `alpha`, `beta`, `information_ratio` |
|
|
246
247
|
| Exposure | 24 | Position and book structure | `gross_exposure`, `net_exposure`, `turnover` |
|
|
247
|
-
| Trades |
|
|
248
|
+
| Trades | 38 | Round trip and trade log statistics | `win_rate`, `profit_factor`, `expectancy` |
|
|
248
249
|
| Compare | 7 | Several strategies side by side | `correlation_matrix`, `diversification_ratio`, `pbo` |
|
|
249
250
|
|
|
250
251
|
`rolling(metric_name, window)` slides any metric over time, and
|
|
@@ -397,14 +398,14 @@ src/stratstat/
|
|
|
397
398
|
core/ # pure computation, numpy only
|
|
398
399
|
_utils.py # shared helpers
|
|
399
400
|
returns/
|
|
400
|
-
descriptive.py #
|
|
401
|
+
descriptive.py # 30 metrics
|
|
401
402
|
risk.py # 24 metrics
|
|
402
403
|
risk_adjusted.py # 23 metrics
|
|
403
404
|
inference.py # 14 metrics
|
|
404
405
|
wrappers.py # rolling, by_regime
|
|
405
|
-
benchmark.py #
|
|
406
|
+
benchmark.py # 22 metrics
|
|
406
407
|
exposure.py # 24 metrics
|
|
407
|
-
trades.py #
|
|
408
|
+
trades.py # 38 metrics
|
|
408
409
|
compare.py # 7 metrics
|
|
409
410
|
report/ # plotly, optional extra
|
|
410
411
|
inputs.py # input containers
|
|
@@ -9,12 +9,12 @@ Strategy evaluation statistics for Python. One library that replaces
|
|
|
9
9
|
`empyrical`, `pyfolio`, and `QuantStats` with more metrics, a cleaner API, and
|
|
10
10
|
faster computation.
|
|
11
11
|
|
|
12
|
-
StratStat computes
|
|
12
|
+
StratStat computes 182 statistics across five input tiers. Give it a return
|
|
13
13
|
series, a trade log, positions, a benchmark, or several strategies, and it
|
|
14
14
|
returns typed results with the formula and its citation attached to every
|
|
15
15
|
number.
|
|
16
16
|
|
|
17
|
-
> **Status:** early release, version 0.
|
|
17
|
+
> **Status:** early release, version 0.2.0. The metric and report APIs work
|
|
18
18
|
> today, but several planned features are not implemented yet, including batch
|
|
19
19
|
> strategy computation, resampling of irregular bars, and reconstruction of
|
|
20
20
|
> positions from a trade log. The public API may still change before 1.0.
|
|
@@ -41,11 +41,12 @@ Three libraries (`empyrical`, `pyfolio`, `QuantStats`) split strategy
|
|
|
41
41
|
evaluation across three incompatible APIs. StratStat is one library with more
|
|
42
42
|
metrics, one call shape, and the working shown on every number.
|
|
43
43
|
|
|
44
|
-
- **More coverage.**
|
|
44
|
+
- **More coverage.** 182 metrics across five input tiers (returns, benchmark,
|
|
45
45
|
exposure, trades, compare). QuantStats exposes roughly 75.
|
|
46
46
|
- **Provenance on every result.** Every `MetricResult` carries its name,
|
|
47
|
-
category, annualization factor,
|
|
48
|
-
|
|
47
|
+
category, annualization factor, machine readable units (a closed vocabulary,
|
|
48
|
+
with per output units when a result mixes scales), and the citation for its
|
|
49
|
+
formula, so you can reproduce a number and defend it.
|
|
49
50
|
- **No engine lock in.** Pass numpy arrays, pandas objects, polars objects, or
|
|
50
51
|
plain dicts. The core runs on numpy only, no scipy, so it works on a headless
|
|
51
52
|
server.
|
|
@@ -179,19 +180,19 @@ was skipped, excluded, and deduplicated, so nothing is dropped silently.
|
|
|
179
180
|
|
|
180
181
|
## Metrics
|
|
181
182
|
|
|
182
|
-
|
|
183
|
+
182 metrics across eight categories. Each returns a `MetricResult` with a
|
|
183
184
|
`meta["ref"]` citation. The full list with formulas is in the
|
|
184
185
|
[formula reference](docs/formula-reference.md).
|
|
185
186
|
|
|
186
187
|
| Category | Count | What it measures | Example metrics |
|
|
187
188
|
|---|---|---|---|
|
|
188
|
-
| Descriptive |
|
|
189
|
+
| Descriptive | 30 | Distribution and summary of returns | `cagr`, `annualized_volatility`, `rolling_summary` |
|
|
189
190
|
| Risk | 24 | Downside, tail, and drawdown risk | `max_drawdown`, `var`, `cvar` |
|
|
190
191
|
| Risk adjusted | 23 | Return per unit of risk | `sharpe_ratio`, `sortino_ratio`, `calmar_ratio` |
|
|
191
192
|
| Inference | 14 | Confidence and significance of performance | `psr`, `sharpe_ci_analytic`, `bias_ratio` |
|
|
192
|
-
| Benchmark |
|
|
193
|
+
| Benchmark | 22 | Performance relative to a benchmark | `alpha`, `beta`, `information_ratio` |
|
|
193
194
|
| Exposure | 24 | Position and book structure | `gross_exposure`, `net_exposure`, `turnover` |
|
|
194
|
-
| Trades |
|
|
195
|
+
| Trades | 38 | Round trip and trade log statistics | `win_rate`, `profit_factor`, `expectancy` |
|
|
195
196
|
| Compare | 7 | Several strategies side by side | `correlation_matrix`, `diversification_ratio`, `pbo` |
|
|
196
197
|
|
|
197
198
|
`rolling(metric_name, window)` slides any metric over time, and
|
|
@@ -344,14 +345,14 @@ src/stratstat/
|
|
|
344
345
|
core/ # pure computation, numpy only
|
|
345
346
|
_utils.py # shared helpers
|
|
346
347
|
returns/
|
|
347
|
-
descriptive.py #
|
|
348
|
+
descriptive.py # 30 metrics
|
|
348
349
|
risk.py # 24 metrics
|
|
349
350
|
risk_adjusted.py # 23 metrics
|
|
350
351
|
inference.py # 14 metrics
|
|
351
352
|
wrappers.py # rolling, by_regime
|
|
352
|
-
benchmark.py #
|
|
353
|
+
benchmark.py # 22 metrics
|
|
353
354
|
exposure.py # 24 metrics
|
|
354
|
-
trades.py #
|
|
355
|
+
trades.py # 38 metrics
|
|
355
356
|
compare.py # 7 metrics
|
|
356
357
|
report/ # plotly, optional extra
|
|
357
358
|
inputs.py # input containers
|
|
@@ -93,6 +93,7 @@ def _active_return_series(
|
|
|
93
93
|
|
|
94
94
|
@register_metric(
|
|
95
95
|
name="alpha",
|
|
96
|
+
units="fraction",
|
|
96
97
|
requires="benchmark",
|
|
97
98
|
category=("benchmark",),
|
|
98
99
|
backend="vectorized",
|
|
@@ -158,6 +159,7 @@ def alpha(inp: BenchmarkInput) -> MetricResult:
|
|
|
158
159
|
|
|
159
160
|
@register_metric(
|
|
160
161
|
name="beta",
|
|
162
|
+
units="ratio",
|
|
161
163
|
requires="benchmark",
|
|
162
164
|
category=("benchmark", "risk"),
|
|
163
165
|
backend="vectorized",
|
|
@@ -190,6 +192,7 @@ def beta(inp: BenchmarkInput) -> MetricResult:
|
|
|
190
192
|
|
|
191
193
|
@register_metric(
|
|
192
194
|
name="r_squared",
|
|
195
|
+
units="fraction",
|
|
193
196
|
requires="benchmark",
|
|
194
197
|
category=("benchmark",),
|
|
195
198
|
backend="vectorized",
|
|
@@ -244,6 +247,7 @@ def r_squared(inp: BenchmarkInput) -> MetricResult:
|
|
|
244
247
|
|
|
245
248
|
@register_metric(
|
|
246
249
|
name="tracking_error",
|
|
250
|
+
units="fraction",
|
|
247
251
|
requires="benchmark",
|
|
248
252
|
category=("benchmark", "risk"),
|
|
249
253
|
backend="vectorized",
|
|
@@ -278,6 +282,7 @@ def tracking_error(inp: BenchmarkInput) -> MetricResult:
|
|
|
278
282
|
|
|
279
283
|
@register_metric(
|
|
280
284
|
name="information_ratio",
|
|
285
|
+
units="ratio",
|
|
281
286
|
requires="benchmark",
|
|
282
287
|
category=("benchmark",),
|
|
283
288
|
backend="vectorized",
|
|
@@ -319,6 +324,7 @@ def information_ratio(inp: BenchmarkInput) -> MetricResult:
|
|
|
319
324
|
|
|
320
325
|
@register_metric(
|
|
321
326
|
name="up_capture",
|
|
327
|
+
units="ratio",
|
|
322
328
|
requires="benchmark",
|
|
323
329
|
category=("benchmark", "capture"),
|
|
324
330
|
backend="vectorized",
|
|
@@ -358,6 +364,7 @@ def up_capture(inp: BenchmarkInput) -> MetricResult:
|
|
|
358
364
|
|
|
359
365
|
@register_metric(
|
|
360
366
|
name="down_capture",
|
|
367
|
+
units="ratio",
|
|
361
368
|
requires="benchmark",
|
|
362
369
|
category=("benchmark", "capture"),
|
|
363
370
|
backend="vectorized",
|
|
@@ -397,6 +404,7 @@ def down_capture(inp: BenchmarkInput) -> MetricResult:
|
|
|
397
404
|
|
|
398
405
|
@register_metric(
|
|
399
406
|
name="up_down_capture",
|
|
407
|
+
units="ratio",
|
|
400
408
|
requires="benchmark",
|
|
401
409
|
category=("benchmark", "capture"),
|
|
402
410
|
backend="vectorized",
|
|
@@ -436,6 +444,7 @@ def up_down_capture(inp: BenchmarkInput) -> MetricResult:
|
|
|
436
444
|
|
|
437
445
|
@register_metric(
|
|
438
446
|
name="correlation",
|
|
447
|
+
units="fraction",
|
|
439
448
|
requires="benchmark",
|
|
440
449
|
category=("benchmark",),
|
|
441
450
|
backend="vectorized",
|
|
@@ -472,6 +481,7 @@ def correlation(inp: BenchmarkInput) -> MetricResult:
|
|
|
472
481
|
|
|
473
482
|
@register_metric(
|
|
474
483
|
name="active_return",
|
|
484
|
+
units="fraction",
|
|
475
485
|
requires="benchmark",
|
|
476
486
|
category=("benchmark",),
|
|
477
487
|
backend="vectorized",
|
|
@@ -508,6 +518,7 @@ def active_return(inp: BenchmarkInput) -> MetricResult:
|
|
|
508
518
|
|
|
509
519
|
@register_metric(
|
|
510
520
|
name="batting_average",
|
|
521
|
+
units="fraction",
|
|
511
522
|
requires="benchmark",
|
|
512
523
|
category=("benchmark",),
|
|
513
524
|
backend="vectorized",
|
|
@@ -544,6 +555,7 @@ def batting_average(inp: BenchmarkInput) -> MetricResult:
|
|
|
544
555
|
|
|
545
556
|
@register_metric(
|
|
546
557
|
name="treynor_ratio",
|
|
558
|
+
units="ratio",
|
|
547
559
|
requires="benchmark",
|
|
548
560
|
category=("benchmark",),
|
|
549
561
|
backend="vectorized",
|
|
@@ -590,6 +602,7 @@ def treynor_ratio(inp: BenchmarkInput) -> MetricResult:
|
|
|
590
602
|
|
|
591
603
|
@register_metric(
|
|
592
604
|
name="outperformance",
|
|
605
|
+
units="fraction",
|
|
593
606
|
requires="benchmark",
|
|
594
607
|
category=("benchmark",),
|
|
595
608
|
backend="vectorized",
|
|
@@ -625,6 +638,7 @@ def outperformance(inp: BenchmarkInput) -> MetricResult:
|
|
|
625
638
|
|
|
626
639
|
@register_metric(
|
|
627
640
|
name="outperformance_ratio",
|
|
641
|
+
units="ratio",
|
|
628
642
|
requires="benchmark",
|
|
629
643
|
category=("benchmark",),
|
|
630
644
|
backend="vectorized",
|
|
@@ -655,44 +669,116 @@ def outperformance_ratio(inp: BenchmarkInput) -> MetricResult:
|
|
|
655
669
|
|
|
656
670
|
|
|
657
671
|
# ===================================================================
|
|
658
|
-
# §8.15
|
|
672
|
+
# §8.15 Performance Period Comparison
|
|
659
673
|
# ===================================================================
|
|
660
674
|
|
|
661
675
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
requires="benchmark",
|
|
665
|
-
category=("benchmark",),
|
|
666
|
-
backend="vectorized",
|
|
667
|
-
ref=_REF_BACON_95,
|
|
668
|
-
)
|
|
669
|
-
def underperforming_periods(inp: BenchmarkInput) -> MetricResult:
|
|
670
|
-
r"""Count and fraction of periods where strategy underperforms benchmark.
|
|
671
|
-
|
|
672
|
-
Returns ``[count, pct]``.
|
|
673
|
-
"""
|
|
674
|
-
_require_single_strategy(inp, "underperforming_periods")
|
|
676
|
+
def _period_comparison(inp: BenchmarkInput) -> tuple[int, int, int, int]:
|
|
677
|
+
"""Return outperforming, underperforming, tie counts, and valid periods."""
|
|
675
678
|
r = inp.returns[:, 0]
|
|
676
679
|
bench = inp.benchmark
|
|
677
680
|
valid = np.isfinite(r) & np.isfinite(bench)
|
|
678
681
|
n_valid = int(valid.sum())
|
|
679
682
|
if n_valid == 0:
|
|
680
|
-
|
|
683
|
+
return 0, 0, 0, 0
|
|
684
|
+
return (
|
|
685
|
+
int(np.sum((r > bench) & valid)),
|
|
686
|
+
int(np.sum((r < bench) & valid)),
|
|
687
|
+
int(np.sum((r == bench) & valid)),
|
|
688
|
+
n_valid,
|
|
689
|
+
)
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
def _period_result(
|
|
693
|
+
name: str,
|
|
694
|
+
count: int,
|
|
695
|
+
n_valid: int,
|
|
696
|
+
inp: BenchmarkInput,
|
|
697
|
+
) -> MetricResult:
|
|
698
|
+
"""Build the standard ``[count, pct]`` result for a comparison outcome."""
|
|
699
|
+
if n_valid == 0:
|
|
700
|
+
# A count of zero is a fact; a percentage of zero periods is undefined.
|
|
701
|
+
arr: NDArray[np.floating] = np.array([0.0, np.nan])
|
|
681
702
|
else:
|
|
682
|
-
|
|
683
|
-
arr = np.array([n_under, n_under / n_valid], dtype=np.float64)
|
|
703
|
+
arr = np.array([count, count / n_valid * 100.0], dtype=np.float64)
|
|
684
704
|
return MetricResult(
|
|
685
|
-
name=
|
|
705
|
+
name=name,
|
|
686
706
|
value=arr,
|
|
687
707
|
category=("benchmark",),
|
|
688
708
|
periods_per_year=inp.periods_per_year,
|
|
689
709
|
meta={
|
|
690
710
|
"ref": _REF_BACON_95,
|
|
691
711
|
"output_index": ["count", "pct"],
|
|
712
|
+
"comparison_periods": n_valid,
|
|
692
713
|
},
|
|
693
714
|
)
|
|
694
715
|
|
|
695
716
|
|
|
717
|
+
@register_metric(
|
|
718
|
+
name="underperforming_periods",
|
|
719
|
+
units={
|
|
720
|
+
"count": "count",
|
|
721
|
+
"pct": "percent",
|
|
722
|
+
},
|
|
723
|
+
requires="benchmark",
|
|
724
|
+
category=("benchmark",),
|
|
725
|
+
backend="vectorized",
|
|
726
|
+
ref=_REF_BACON_95,
|
|
727
|
+
)
|
|
728
|
+
def underperforming_periods(inp: BenchmarkInput) -> MetricResult:
|
|
729
|
+
r"""Count and percentage of periods where strategy underperforms benchmark.
|
|
730
|
+
|
|
731
|
+
Returns ``[count, pct]`` with ``pct`` in ``[0, 100]``. A tie is an exact
|
|
732
|
+
equality between the strategy and benchmark return.
|
|
733
|
+
"""
|
|
734
|
+
_require_single_strategy(inp, "underperforming_periods")
|
|
735
|
+
_, n_under, _, n_valid = _period_comparison(inp)
|
|
736
|
+
return _period_result("underperforming_periods", n_under, n_valid, inp)
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
@register_metric(
|
|
740
|
+
name="outperforming_periods",
|
|
741
|
+
units={
|
|
742
|
+
"count": "count",
|
|
743
|
+
"pct": "percent",
|
|
744
|
+
},
|
|
745
|
+
requires="benchmark",
|
|
746
|
+
category=("benchmark",),
|
|
747
|
+
backend="vectorized",
|
|
748
|
+
ref=_REF_BACON_95,
|
|
749
|
+
)
|
|
750
|
+
def outperforming_periods(inp: BenchmarkInput) -> MetricResult:
|
|
751
|
+
r"""Count and percentage of periods where strategy outperforms benchmark.
|
|
752
|
+
|
|
753
|
+
Returns ``[count, pct]`` with ``pct`` in ``[0, 100]``. A tie is an exact
|
|
754
|
+
equality between the strategy and benchmark return.
|
|
755
|
+
"""
|
|
756
|
+
_require_single_strategy(inp, "outperforming_periods")
|
|
757
|
+
n_out, _, _, n_valid = _period_comparison(inp)
|
|
758
|
+
return _period_result("outperforming_periods", n_out, n_valid, inp)
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
@register_metric(
|
|
762
|
+
name="tie_periods",
|
|
763
|
+
units={
|
|
764
|
+
"count": "count",
|
|
765
|
+
"pct": "percent",
|
|
766
|
+
},
|
|
767
|
+
requires="benchmark",
|
|
768
|
+
category=("benchmark",),
|
|
769
|
+
backend="vectorized",
|
|
770
|
+
ref=_REF_BACON_95,
|
|
771
|
+
)
|
|
772
|
+
def tie_periods(inp: BenchmarkInput) -> MetricResult:
|
|
773
|
+
r"""Count and percentage of periods where strategy equals benchmark exactly.
|
|
774
|
+
|
|
775
|
+
Returns ``[count, pct]`` with ``pct`` in ``[0, 100]``.
|
|
776
|
+
"""
|
|
777
|
+
_require_single_strategy(inp, "tie_periods")
|
|
778
|
+
_, _, n_tie, n_valid = _period_comparison(inp)
|
|
779
|
+
return _period_result("tie_periods", n_tie, n_valid, inp)
|
|
780
|
+
|
|
781
|
+
|
|
696
782
|
# ===================================================================
|
|
697
783
|
# §8.16 Max Outperformance
|
|
698
784
|
# ===================================================================
|
|
@@ -700,6 +786,7 @@ def underperforming_periods(inp: BenchmarkInput) -> MetricResult:
|
|
|
700
786
|
|
|
701
787
|
@register_metric(
|
|
702
788
|
name="max_outperformance",
|
|
789
|
+
units="fraction",
|
|
703
790
|
requires="benchmark",
|
|
704
791
|
category=("benchmark",),
|
|
705
792
|
backend="vectorized",
|
|
@@ -735,6 +822,7 @@ def max_outperformance(inp: BenchmarkInput) -> MetricResult:
|
|
|
735
822
|
|
|
736
823
|
@register_metric(
|
|
737
824
|
name="max_underperformance",
|
|
825
|
+
units="fraction",
|
|
738
826
|
requires="benchmark",
|
|
739
827
|
category=("benchmark",),
|
|
740
828
|
backend="vectorized",
|
|
@@ -773,6 +861,7 @@ def max_underperformance(inp: BenchmarkInput) -> MetricResult:
|
|
|
773
861
|
|
|
774
862
|
@register_metric(
|
|
775
863
|
name="benchmark_volatility",
|
|
864
|
+
units="fraction",
|
|
776
865
|
requires="benchmark",
|
|
777
866
|
category=("benchmark", "risk"),
|
|
778
867
|
backend="vectorized",
|
|
@@ -807,6 +896,7 @@ _REF_RANK_IC = "Spearman (1904); standard rank-based information coefficient."
|
|
|
807
896
|
|
|
808
897
|
@register_metric(
|
|
809
898
|
name="information_coefficient",
|
|
899
|
+
units="fraction",
|
|
810
900
|
requires="benchmark",
|
|
811
901
|
category=("benchmark",),
|
|
812
902
|
backend="vectorized",
|
|
@@ -888,6 +978,7 @@ _REF_DIR_CONSISTENCY = (
|
|
|
888
978
|
|
|
889
979
|
@register_metric(
|
|
890
980
|
name="directional_consistency",
|
|
981
|
+
units="fraction",
|
|
891
982
|
requires="benchmark",
|
|
892
983
|
category=("benchmark",),
|
|
893
984
|
backend="vectorized",
|
|
@@ -270,6 +270,7 @@ def _cov_matrix(
|
|
|
270
270
|
|
|
271
271
|
@register_metric(
|
|
272
272
|
name="correlation_matrix",
|
|
273
|
+
units="fraction",
|
|
273
274
|
requires="compare",
|
|
274
275
|
category=("relative", "compare"),
|
|
275
276
|
backend="vectorized",
|
|
@@ -319,6 +320,7 @@ def correlation_matrix(inp: CompareInput) -> MetricResult:
|
|
|
319
320
|
|
|
320
321
|
@register_metric(
|
|
321
322
|
name="diversification_ratio",
|
|
323
|
+
units="ratio",
|
|
322
324
|
requires="compare",
|
|
323
325
|
category=("relative", "compare"),
|
|
324
326
|
backend="vectorized",
|
|
@@ -400,6 +402,11 @@ def diversification_ratio(inp: CompareInput) -> MetricResult:
|
|
|
400
402
|
|
|
401
403
|
@register_metric(
|
|
402
404
|
name="sharpe_difference_test",
|
|
405
|
+
units={
|
|
406
|
+
"z": "statistic",
|
|
407
|
+
"p_value": "probability",
|
|
408
|
+
"sr_diff": "ratio",
|
|
409
|
+
},
|
|
403
410
|
requires="compare",
|
|
404
411
|
category=("relative", "compare"),
|
|
405
412
|
backend="vectorized",
|
|
@@ -568,6 +575,10 @@ def _stationary_bootstrap(
|
|
|
568
575
|
|
|
569
576
|
@register_metric(
|
|
570
577
|
name="whites_reality_check",
|
|
578
|
+
units={
|
|
579
|
+
"statistic": "statistic",
|
|
580
|
+
"p_value": "probability",
|
|
581
|
+
},
|
|
571
582
|
requires="compare",
|
|
572
583
|
category=("relative", "compare"),
|
|
573
584
|
backend="resampling",
|
|
@@ -736,6 +747,10 @@ def _pbo_overfit_fallback(
|
|
|
736
747
|
|
|
737
748
|
@register_metric(
|
|
738
749
|
name="pbo",
|
|
750
|
+
units={
|
|
751
|
+
"pbo": "fraction",
|
|
752
|
+
"n_splits": "count",
|
|
753
|
+
},
|
|
739
754
|
requires="compare",
|
|
740
755
|
category=("relative", "compare"),
|
|
741
756
|
backend="resampling",
|
|
@@ -838,6 +853,7 @@ def pbo(
|
|
|
838
853
|
|
|
839
854
|
@register_metric(
|
|
840
855
|
name="marginal_contribution_to_risk",
|
|
856
|
+
units="fraction",
|
|
841
857
|
requires="compare",
|
|
842
858
|
category=("relative", "compare"),
|
|
843
859
|
backend="vectorized",
|
|
@@ -952,6 +968,7 @@ def marginal_contribution_to_risk(inp: CompareInput) -> MetricResult:
|
|
|
952
968
|
|
|
953
969
|
@register_metric(
|
|
954
970
|
name="component_var",
|
|
971
|
+
units="fraction",
|
|
955
972
|
requires="compare",
|
|
956
973
|
category=("relative", "compare"),
|
|
957
974
|
backend="vectorized",
|