portfolio-backtest-python icon indicating copy to clipboard operation
portfolio-backtest-python copied to clipboard

Adj. Close

Open minhvo-cloud opened this issue 6 months ago • 1 comments

The “Adj. Close” column in the downloaded data from yfinance no longer exists. Please modify the column name to “Close” so that the Backtest function can function properly.

minhvo-cloud avatar May 21 '25 21:05 minhvo-cloud

code from pypi

from portfolio_backtest import Backtest
Backtest(tickers=["VTI", "AGG", "GLD"]).run()

result

KeyError                                  Traceback (most recent call last)
[/usr/local/lib/python3.11/dist-packages/pandas/core/indexes/base.py](https://localhost:8080/#) in get_loc(self, key)
   3804         try:
-> 3805             return self._engine.get_loc(casted_key)
   3806         except KeyError as err:

index.pyx in pandas._libs.index.IndexEngine.get_loc()

index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'Adj Close'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
7 frames
[/usr/local/lib/python3.11/dist-packages/pandas/core/indexes/base.py](https://localhost:8080/#) in get_loc(self, key)
   3810             ):
   3811                 raise InvalidIndexError(key)
-> 3812             raise KeyError(key) from err
   3813         except TypeError:
   3814             # If we have a listlike key, _check_indexing_error will raise

KeyError: 'Adj Close'

best regards

sugizo avatar Jul 11 '25 13:07 sugizo