stefan-jansen / pyfolio-reloaded

Portfolio and risk analytics in Python
https://pyfolio.ml4trading.io/
Apache License 2.0
387 stars 110 forks source link

NumPy 2.x compatibility, `np.NINF` was removed #50

Open ajjoslin opened 1 month ago

ajjoslin commented 1 month ago

Problem Description

To reproduce:

import pyfolio as pf
import yfinance as yf

history = yf.Ticker("MGK").history("max")
returns = history.Close.pct_change()
pf.create_returns_tear_sheet(returns, live_start_date="2020-1-1")

Traceback:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\FamilyStuff\BudgetFinance\portfolio\env-portfolio\Lib\site-packages\empyrical\stats.py", line 741, in sortino_ratio
    else downside_risk(returns, required_return, period, annualization)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\FamilyStuff\BudgetFinance\portfolio\env-portfolio\Lib\site-packages\empyrical\stats.py", line 821, in downside_risk
    np.NINF,
    ^^^^^^^
  File "c:\FamilyStuff\BudgetFinance\portfolio\env-portfolio\Lib\site-packages\numpy\__init__.py", line 414, in __getattr__
    raise AttributeError(
AttributeError: `np.NINF` was removed in the NumPy 2.0 release. Use `-np.inf` instead.

Additional info:

Versions

ajjoslin commented 1 month ago

Looks like the folks at empyrical-reloaded are already tracking this issue: https://github.com/stefan-jansen/empyrical-reloaded/issues/32

I've installed numpy==1.26.4 and it seems to work fine. This might be a good workaround until empyrical pushes a fix.