Repository navigation
feat(backtest): expand benchmark analytics with M^2, Dual-Beta, and Batting Average - #307
Merged
brokermr810 merged 1 commit intoOct 24, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Expands the benchmark-relative performance analytics in$M^2$ ), Dual-Beta ($\beta^+$ and $\beta^-$ ), and Batting Average metrics:
app/services/backtest/metrics.pyand Strategy API V2 with Modigliani–Modigliani ($$M^2 = R_f + \text{Sharpe}p \times \sigma{b,\text{ann}} = R_f + \left(\frac{R_{p,\text{ann}} - R_f}{\sigma_{p,\text{ann}}}\right) \sigma_{b,\text{ann}}$$
zero_portfolio_variance) and flat benchmark variance (zero_benchmark_variance).betaSpread = \beta^+ - \beta^-. A positive spread represents a convex payoff structure with high upside participation and defensive downside insulation.battingAverage: Percentage of aligned observation periods where portfolio return strictly outperformed benchmark return:outperformancePayoffRatio: Ratio of average active return during winning periods to average active loss during losing periods.outperformancePeriodsandunderperformancePeriods.calculate_benchmark_relative_metrics, populatingmSquaredStatus,dualBetaStatus,battingStatus, and associated fields inresult["benchmarkRelativeMetrics"].__all__:calculate_m_squared,calculate_dual_beta, andcalculate_batting_average.docs/product/BACKTEST_CENTER.mdanddocs/product/BACKTEST_CENTER_CN.mdwith mathematical formulas and explanations.Related issue
Changes
backend_api_python/app/services/backtest/metrics.py:_calculate_m_squared_metrics,_calculate_dual_beta_metrics, and_calculate_batting_metrics.calculate_m_squared,calculate_dual_beta, andcalculate_batting_average.calculate_benchmark_relative_metrics.__all__.backend_api_python/tests/test_backtest_metrics.py:calculate_benchmark_relative_metrics.docs/product/BACKTEST_CENTER.md&BACKTEST_CENTER_CN.md:Test plan
pytest backend_api_python/tests/test_backtest_metrics.pypasses (31/31 tests)pytest backend_api_python/tests/test_strategy_v2_service.pypasses (30/30 tests)ruff check app/services/backtest/metrics.py tests/test_backtest_metrics.pypasses with zero violationspython backend_api_python/scripts/backend_quality_check.pypassesgit diff --checkpasses with zero whitespace or line-ending issues