Skip to content

Fix MultiBacktest mixed no-trade results#1366

Open
elpolini wants to merge 1 commit into
kernc:masterfrom
elpolini:fix/multibacktest-no-trade-results
Open

Fix MultiBacktest mixed no-trade results#1366
elpolini wants to merge 1 commit into
kernc:masterfrom
elpolini:fix/multibacktest-no-trade-results

Conversation

@elpolini

@elpolini elpolini commented Jul 7, 2026

Copy link
Copy Markdown

Summary

Fixes #1344.

MultiBacktest._mp_task_run() currently returns None for datasets whose strategy produced zero trades. When a MultiBacktest run mixes datasets with trades and datasets with no trades, MultiBacktest.run() then receives a mixed list of pd.Series and None, which can either raise TypeError: object of type 'NoneType' has no len() or produce nested/odd DataFrame values depending on ordering.

Backtest.run() already returns a complete stats series for zero-trade strategies, so this change keeps those stats instead of replacing them with None.

Changes

  • Always return filtered stats from _mp_task_run(), including zero-trade stats.
  • Add a regression test for mixed trade/no-trade datasets.
  • Assert zero-trade datasets report # Trades == 0 and do not produce nested Series values.

Test plan

python -m unittest backtesting.test._test.TestLib.test_MultiBacktest_handles_mixed_no_trade_results
python -m unittest backtesting.test._test.TestLib.test_MultiBacktest
python -m unittest backtesting.test._test.TestBacktest.test_run backtesting.test._test.TestUtil.test_as_str
python -m compileall -q backtesting
flake8 backtesting setup.py

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