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.") 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