Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing edge case bug for change in universe #114

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

leonardojoau
Copy link
Contributor

Caught this subtle bug for change in universe. It is necessary to include assets that were in index before in the 'joined' variable to assert that PnL doesn't change.
For example:
start with index composition A, B, C
then A leaves the index -> current_universe = B, C
if D gets in the index -> new_universe = B, C, D and current_universe = B, C -> joined = B, C, D
then in the line self._h.reindex(columns = joined) it ends up dropping column A from _h, which changes NAV for all days that had non zero dollar position in A.

@coveralls
Copy link

coveralls commented Oct 30, 2023

Coverage Status

coverage: 98.424%. remained the same when pulling 41d15f6 on leonardojoau:master into ddb1605 on cvxgrp:master.

@enzbus
Copy link
Collaborator

enzbus commented Oct 31, 2023

Thanks for catching bugs on this (again)! I need to write another test case.

@enzbus
Copy link
Collaborator

enzbus commented Oct 31, 2023

Ok, merging this now; will write a test case, maybe refactor if the simpler fix is equivalent, and make a PyPI revision probably tonight.

@enzbus enzbus merged commit 731f8c8 into cvxgrp:master Oct 31, 2023
10 checks passed
@enzbus
Copy link
Collaborator

enzbus commented Oct 31, 2023

It should be fixed; if you have time please confirm that this test case

(env)$ python cvxportfolio/tests/test_simulator.py TestSimulator.test_backtest_with_ipos_and_delistings

targets the right edge case.

enzbus added a commit that referenced this pull request Oct 31, 2023
@leonardojoau
Copy link
Contributor Author

I just ran the new test and it targets that edge case well. Looks alright and also the _change_universe function is now more clearly written. Thanks!

enzbus added a commit that referenced this pull request Oct 31, 2023
This revision contains bug fixes regarding edge cases of back-tests with changing universes, which have been provided by github PRs #113 and #114. New test cases have been made for those edge cases. Then, we migrated the Python packaging to the new pyproject.toml system and are updating the rest of the development suite. We are improving the code quality overall using pylint (https://pylint.readthedocs.io/), an advanced Python syntax parser and static analysis system. The current Cvxportfolio overall pylint score is 9/10 (was a bit more than 8/10 for the last revision). We aim for maximum score, which ensures the highest code quality, readability, and maintainability. We are also improving test coverage, which is now at about 99%. Html documentation is also being improved and will eventually cover the whole library, including all internal interfaces and low-level objects. Lastly, we are sadly aware than Cvxportfolio can't currently be installed on Python 3.12, due to the removal of distutils from the Standard Library which broke the packaging of a sub-dependency package (see cvxpy/cvxpy#2269, bodono/scs-python#70, bodono/scs-python#69). A workaround exists, see cvxpy/cvxpy#2269. We are monitoring the situation and may redesign Cvxportfolio's dependency graph.
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.

3 participants