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

Deprecated code in stats.py expected_return() #335

Open
kartiksubbarao opened this issue Feb 23, 2024 · 0 comments · May be fixed by #336
Open

Deprecated code in stats.py expected_return() #335

kartiksubbarao opened this issue Feb 23, 2024 · 0 comments · May be fixed by #336

Comments

@kartiksubbarao
Copy link
Contributor

The expected_return() function in stats.py has deprecated code, which causes the following warning when generating a tearsheet with a benchmark:

/path/to/python/lib/python3.12/site-packages/numpy/core/fromnumeric.py:86: FutureWarning: The behavior of DataFrame.prod with axis=None is deprecated, in a future version this will reduce over both axes and return a scalar. To retain the old behavior, pass axis=0 (or do not pass axis)
  return reduction(axis=axis, out=out, **passkwargs)

Here is the deprecated code:

return _np.product(1 + returns) ** (1 / len(returns)) - 1

The corrected version is this:

return _np.prod(1 + returns, axis=0) ** (1 / len(returns)) - 1

In addition to explicitly specifying axis=0 to fix the FutureWarning, it also changes _np.product to _np.prod to fix another deprecation issue:
https://github.com/numpy/numpy/blob/maintenance/1.26.x/numpy/core/fromnumeric.py#L3837-L3839

I will submit a pull request.

kartiksubbarao added a commit to kartiksubbarao/quantstats that referenced this issue Feb 23, 2024
fix _np.prod deprecations, closes ranaroussi#335
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 a pull request may close this issue.

1 participant