feat(fitness): add RiskAdjustedReturn fitness function (closes #21)#24
Merged
NeuZhou merged 2 commits intoNeuZhou:masterfrom Apr 13, 2026
Merged
Conversation
Implements issue NeuZhou#21. Scores strategies as annual_return / (1 + |max_drawdown|), naturally penalising high-drawdown strategies. Zero-trade results receive a -1.0 penalty. Handles both negative and positive max_drawdown sign conventions via abs(). Adds 11 tests covering formula correctness, ranking behaviour, edge cases (zero drawdown, zero trades, negative returns), and registry auto-discovery.
NeuZhou
approved these changes
Apr 13, 2026
Owner
NeuZhou
left a comment
There was a problem hiding this comment.
Excellent PR. Clean code, thorough tests, and the docstring honestly acknowledges the math correction from the issue spec. CI green.
✅ Highlights
- Formula is simple and correct: \�nnual_return / (1 + |max_drawdown|)\
- Handles both sign conventions for drawdown via \�bs()\ — important since different callers may store it differently
- Zero-trade penalty of -1.0\ is a good choice
- 11 tests covering formula, ranking, edge cases, and registry integration
- Properly uses \FITNESS_CLASSES\ for auto-discovery
- Honest note about the issue example math being off — good attention to detail
Minor suggestion (non-blocking)
The docstring comment about the issue spec's math error is nice for developers. Consider trimming it slightly since it reads like a review discussion — maybe just \Note: abs() normalizes sign convention.\
Approved ✅
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
Closes #21.
Adds a
RiskAdjustedReturnFitnessbuiltin that scores strategies using:This naturally penalises high-drawdown strategies even when their raw return is higher.
max_drawdownin either sign convention (stored negative or positive) viaabs()-1.0penalty scoreFitnessRegistry.auto_discover()viaFITNESS_CLASSESFiles changed
stratevo/fitness_plugins/builtin/risk_adjusted_return.pytests/test_fitness_risk_adjusted_return.pyTest plan
test_formula_standard— verifiesannual_return / (1 + dd_abs)arithmetictest_formula_positive_drawdown_convention—abs()handles positive dd valuestest_drawdown_penalises_high_return— 30%/90%DD loses to 20%/10%DDtest_same_return_lower_drawdown_wins— same return, lower DD scores highertest_zero_trades_penalty— returns-1.0test_zero_drawdown— denominator = 1, score = annual_returntest_negative_return— negative returns produce negative scorestest_large_drawdown— formula still finite at 80% drawdowntest_auto_discover_registers_it— registry finds the class automatically