Skip to content

Preserve caller benchmark columns in CAPM return estimates - #772

Open
galafis wants to merge 1 commit into
PyPortfolio:mainfrom
galafis:fix-capm-benchmark-mutation
Open

galafis wants to merge 1 commit into
PyPortfolio:mainfrom
galafis:fix-capm-benchmark-mutation

Conversation

@galafis

@galafis galafis commented Oct 24, 2026

Copy link
Copy Markdown

capm_return(..., returns_data=True) currently renames the caller’s benchmark DataFrame columns to mkt. Copy the supplied benchmark before applying the internal name, matching the copy already made for asset returns.

The regressions use the repository’s stock and benchmark fixtures, check that both input frames remain unchanged, and compare estimates with the price-input path for arithmetic and compounded returns. Both cases fail before the fix on the benchmark column mutation.

Validation: all 21 expected-returns tests pass (10 existing NumPy invalid-reduce warnings). Black and git diff --check pass. Windows, Python 3.12.14, pandas 3.1.0, NumPy 2.5.4, SciPy 1.18.1, cvxpy 1.9.3.

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.

1 participant