test(backtesting): correct wrong oracles in performance metric tests (#14)#38
Open
bradsmithmba wants to merge 1 commit into
Open
test(backtesting): correct wrong oracles in performance metric tests (#14)#38bradsmithmba wants to merge 1 commit into
bradsmithmba wants to merge 1 commit into
Conversation
Three tests asserted incorrect expected values and passed/failed for the wrong reasons: - test_win_rate_calculation: pnl [100,-50,200,150,-75,300,-25,180,-100,250] is 6 wins / 4 losses = 0.6, but the comment said "7 wins" and it asserted 0.7. Corrected to 0.6. - test_sharpe_ratio_calculation: used a constant return series (zero std), which the calculator maps to Sharpe 0 — so `sharpe_ratio > 10` could never hold. Give the series small, deterministic volatility so it genuinely exercises the high-Sharpe case, and replace the nonsensical `annualized_return > 10` (>1000%) with `> 0.10`. - test_annualization: 252 freq='D' rows span only 251 calendar days, so a 20% total return correctly annualizes to ~30%, not the asserted 20%. Use a full calendar year of dates so 20% total annualizes to ~20%. All seven tests in the file now pass and assert correct values. Closes cloudtrainerwork#14 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Three tests in
tests/backtesting/test_performance.pyasserted incorrect expected values — they were green/red for the wrong reasons and didn't actually validate the metrics. Fixing the oracles so the tests assert what's correct.Closes #14.
The three fixes
test_win_rate_calculation— the pnl series[100, -50, 200, 150, -75, 300, -25, 180, -100, 250]has 6 positive entries, not 7. Win rate is 0.6.test_sharpe_ratio_calculation— the test used a constant return series (np.full(252, 0.001)). A constant series has zero standard deviation, which_calculate_sharpecorrectly maps to0.0(undefined Sharpe), soassert sharpe_ratio > 10could never pass. The "no volatility → high Sharpe" premise is backwards. Give the series small deterministic volatility so it genuinely exercises the high-Sharpe case, and replaceassert annualized_return > 10(which asserted >1000%) with> 0.10.test_annualization— 252freq='D'rows span only 251 calendar days (~0.69 yr). Since the calculator annualizes by elapsed calendar time, a 20% total return over 251 days correctly annualizes to ~30%, so asserting ~20% was wrong. Use a full calendar year of dates so a 20% total return annualizes to ~20% (computed: 0.2008).Result
(Previously: 3 failed — the three above — and 4 passed.)
Note
This file is also touched by the PR for #12 (#37), which adds a separate bar-count annualization test. The two were verified to merge cleanly (no conflict) in either order.
🤖 Generated with Claude Code