Skip to content

Fix custom benchmark plotting for selected portfolio columns#859

Merged
polakowo merged 2 commits into
polakowo:masterfrom
Whning0513:fix-custom-benchmark-cum-returns-726
Jun 29, 2026
Merged

Fix custom benchmark plotting for selected portfolio columns#859
polakowo merged 2 commits into
polakowo:masterfrom
Whning0513:fix-custom-benchmark-cum-returns-726

Conversation

@Whning0513

Copy link
Copy Markdown
Contributor

Fixes #726.

plot_cum_returns() handled a custom benchmark_rets input by broadcasting it against self.obj, but Portfolio doesn't have that attribute. That raises an AttributeError as soon as you pass custom benchmark returns while plotting a selected column.

I changed the broadcast target to self.wrapper.dummy(group_by=group_by), which matches the portfolio shape the method is about to select from. I also added a regression test that exercises pf_multi.plot_cum_returns(column="a", benchmark_rets=pf_multi["b"].returns()).

Verified with:

  • python -m pytest tests/test_plotting.py -k "cum_returns"
  • direct repro script from the issue now returns successfully instead of raising AttributeError

@polakowo

polakowo commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Thanks, the fix works. To make your test consistent with the surrounding tests, please shorten the name of the test method or include the test in already existing test methods, and I'll merge the PR.

@Whning0513

Copy link
Copy Markdown
Contributor Author

Updated the regression to live alongside the existing cum-returns plotting tests and shortened the test name to match the surrounding style.

@polakowo polakowo merged commit 4d257e0 into polakowo:master Jun 29, 2026
1 check 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.

Plotting with custom benchmark_rets got error (VectorBT used undefined attribute 'obj')

2 participants