Skip to content

Fix MultiBacktest when some runs make no trades#1358

Open
BerqiaMouad wants to merge 1 commit intokernc:masterfrom
BerqiaMouad:fix/multibacktest-zero-trades
Open

Fix MultiBacktest when some runs make no trades#1358
BerqiaMouad wants to merge 1 commit intokernc:masterfrom
BerqiaMouad:fix/multibacktest-zero-trades

Conversation

@BerqiaMouad
Copy link
Copy Markdown

Summary

  • keep the existing public stats series for zero-trade runs instead of replacing it with None
  • add regression coverage for all-zero and mixed zero/non-zero MultiBacktest runs

Why

Backtest.run() already returns meaningful public stats when a strategy makes zero trades.
Dropping those results to None makes MultiBacktest.run() either raise when a batch mixes Series and None, or return a one-row frame of None values.

Fixes #1344.

Validation

  • python -m unittest -v backtesting.test._test.TestLib.test_MultiBacktest backtesting.test._test.TestLib.test_MultiBacktest_keeps_zero_trade_runs
  • flake8 backtesting setup.py

Notes

  • On my local macOS / Python 3.11.14 / pandas 3.0.2 setup, python -m backtesting.test still hits the pre-existing test_FractionalBacktest failure (ValueError: output array is read-only).

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.

MultiBacktest.run errors out when tested strategy sometimes never enters a position

1 participant