Skip to content

Use actual winning and losing counts in backtest summaries - #646

Merged
MDUYN merged 2 commits into
coding-kitties:mainfrom
jackiectl2:fix-summary-trade-populations
Nov 24, 2026
Merged

MDUYN merged 2 commits into
coding-kitties:mainfrom
jackiectl2:fix-summary-trade-populations

Conversation

@jackiectl2

Copy link
Copy Markdown
Contributor

Multi-window summaries estimate winning and losing populations by dividing win_rate by 100, although the metric producer returns a fraction. In the two-window example from #641, mean loss is -55.1809 instead of -91. Treating every non-winner as a loser also misweights breakeven trades.

Use the existing positive/negative trade counts for both the absolute and percentage averages. Accept legacy saved [count, percentage] pairs; an unavailable population remains undefined. Correct the related fixtures to decimal win rates. The tests use the actual win-rate/count producers and check saved-metric recomputation without changing stored optimizer observations.

Fixes #641.

Validation (CPU, Python 3.12):

  • The new regressions fail on the original aggregation.
  • All backtesting domain tests: 92 passed, plus 5 subtests (one SQLAlchemy deprecation warning).
  • Flake8 passes for the changed production files and the new test file.
  • Full production Flake8 passes.

The complete application/native suite and other Python versions were not run. No GPU is required.

@codecov-commenter

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Compute winning and losing counts whenever their trade averages are requested so summaries remain defined for selective metric calculations. Cover absolute and percentage averages, saved metric recomputation, and caller list preservation.

Co-authored-by: Copilot <[email protected]>
@MDUYN

MDUYN commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the fix and the regression tests! Using the actual winning/losing counts also correctly handles breakeven trades.

I added a follow-up commit for selective metric calculations: requesting a trade average now automatically computes its required population count.

Thanks again!

@MDUYN
MDUYN merged commit 6e22937 into coding-kitties:main Nov 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix multi-window losing-trade weights for fractional win rates

3 participants