From eb16ed61392c4a8502b8fc7566dca433cf168e4f Mon Sep 17 00:00:00 2001 From: Eric Jurio Date: Thu, 24 Apr 2025 18:18:58 -0300 Subject: [PATCH 1/2] Fix test_sortino_ratio (np.nan) AttributeError: `np.NaN` was removed in the NumPy 2.0 release. --- tests/test_quants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_quants.py b/tests/test_quants.py index f791694..1bea518 100644 --- a/tests/test_quants.py +++ b/tests/test_quants.py @@ -41,7 +41,7 @@ def test_sharpe_ratio(): def test_sortino_ratio(): - assert sortino_ratio(0.5, 0.0, 0.02) is np.NaN + assert sortino_ratio(0.5, 0.0, 0.02) is np.nan assert sortino_ratio(0.005, 8.5, 0.005) == 0.0 From 1d5e4e3cb61bf5bb58e1c8fe473b615adf409ed2 Mon Sep 17 00:00:00 2001 From: Eric Jurio Date: Thu, 24 Apr 2025 18:27:47 -0300 Subject: [PATCH 2/2] Fix _yfinance_request and _get_stocks_data_columns. --- finquant/portfolio.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/finquant/portfolio.py b/finquant/portfolio.py index 9a570f5..6604183 100644 --- a/finquant/portfolio.py +++ b/finquant/portfolio.py @@ -940,7 +940,7 @@ def _yfinance_request( # unlike quandl, yfinance does not have a prefix in front of the ticker # thus we do not need to correct them try: - resp: pd.DataFrame = yfinance.download(names, start=start_date, end=end_date) + resp: pd.DataFrame = yfinance.download(names, start=start_date, end=end_date, auto_adjust=False) if not isinstance(resp.columns, pd.MultiIndex) and len(names) > 0: # for single stock must make the dataframe multiindex stock_tuples = [(col, names[0]) for col in list(resp.columns)] @@ -982,11 +982,11 @@ def _get_stocks_data_columns( reqnames: List[str] = _correct_quandl_request_stock_name(names) # get current column labels and replacement labels reqcolnames: List[str] = [] - colname: str # if dataframe is of type multiindex, also get first level colname firstlevel_colnames: List[str] = [] for idx, name in enumerate(names): for col in cols: + colname: str # differ between dataframe directly from quandl and # possibly previously processed dataframe, e.g. # read in from disk with slightly modified column labels @@ -1013,6 +1013,10 @@ def _get_stocks_data_columns( raise ValueError( "Could not find column labels in the second level of MultiIndex pd.DataFrame" ) + else: + raise ValueError( + "Could not find column labels in the MultiIndex pd.DataFrame" + ) # else, error else: raise ValueError("Could not find column labels in the given dataframe.")