yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

previous_close not working on some stock symbols

Open FrknKAYA opened this issue 2 years ago • 4 comments

not working stock icon `import yfinance as yf

ticker = yf.Ticker('SOKE.IS').fast_info previous_close = ticker['previous_close']

print(previous_close)`

working stock icon `import yfinance as yf

ticker = yf.Ticker('MAVI.IS').fast_info previous_close = ticker['previous_close']

print(previous_close)`

traceback: Traceback (most recent call last): File "D:\Python\PyCharm\yfinancetesting\main.py", line 4, in <module> previous_close = ticker['previous_close'] ~~~~~~^^^^^^^^^^^^^^^^^^ File "D:\Python\PyCharm\yfinancetesting\venv\Lib\site-packages\yfinance\base.py", line 110, in __getitem__ return getattr(self, k) ^^^^^^^^^^^^^^^^ File "D:\Python\PyCharm\yfinancetesting\venv\Lib\site-packages\yfinance\base.py", line 247, in previous_close self._prev_close = float(prices["Close"].iloc[-2]) ~~~~~~~~~~~~~~~~~~~~^^^^ File "D:\Python\PyCharm\yfinancetesting\venv\Lib\site-packages\pandas\core\indexing.py", line 1073, in __getitem__ return self._getitem_axis(maybe_callable, axis=axis) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python\PyCharm\yfinancetesting\venv\Lib\site-packages\pandas\core\indexing.py", line 1625, in _getitem_axis self._validate_integer(key, axis) File "D:\Python\PyCharm\yfinancetesting\venv\Lib\site-packages\pandas\core\indexing.py", line 1557, in _validate_integer raise IndexError("single positional indexer is out-of-bounds") IndexError: single positional indexer is out-of-bounds

  • yfinance version = 0.2.9
  • Python version = 3.11.1
  • Windows 11

FrknKAYA avatar Jan 30 '23 12:01 FrknKAYA

Interesting ticker. Yahoo normally calculates "previous close" as before last trading day, but Yahoo only has trading data for today. What do you think the previous close should be?

ValueRaider avatar Jan 30 '23 12:01 ValueRaider

Previous close is wrong for majority of data.

For example: adidas AG (ADS.DE) On summary tab Previous Close is 148.30 fast_info.previous_close returns 145.28

Data on historical data are not the same as data on summary tab.

playinlab avatar Jan 30 '23 12:01 playinlab

Interesting ticker. Yahoo normally calculates "previous close" as before last trading day, but Yahoo only has trading data for today. What do you think the previous close should be?

I just wanted to pull the previous closing info.

FrknKAYA avatar Jan 30 '23 12:01 FrknKAYA

OK I got solutions:

'SOKE.IS'

Fall back to accessing info. No other way to access it.

'ADS.DE'

That previous close is in post-market, and Yahoo wasn't returning in a interval="1d" prepost=True fetch (some exchanges they do). A interval="1h" prepost=True fetch returns correct close.

ValueRaider avatar Jan 30 '23 13:01 ValueRaider

Can close? @ValueRaider

asafravid avatar Feb 01 '23 22:02 asafravid

Not yet, want confirmation is fixed.

A fix is available is PIP pre-release and dev branch.

ValueRaider avatar Feb 01 '23 22:02 ValueRaider

Ticker.info is fixed and fast_info deprecated in latest release

ValueRaider avatar Apr 11 '23 20:04 ValueRaider