JohnDoe
JohnDoe

Reputation: 31

yfinance API incorrect historical data

I want to use yfinace to build a historical stock database to test some strategies. No i came across a problem with some historical data while using the api. It mainly happens for stocks which are not traded not a US market.

For example if I get the historical data for 'BOE.L' using:

boel = yf.Ticker("BOE.L")
boelHist = boel.history(period='max')

The earliest Close price returned is for 2001-06-11, which is: 2.191053e-06 While, on the yahoo website, this value is: 2,347.00 (for this date)

Does anyone know what is going on here?

Upvotes: 3

Views: 3913

Answers (1)

JohnDoe11
JohnDoe11

Reputation: 11

Observed similar behaviour with share 'SAP.DE'.

ticker = yf.Ticker("SAP.DE")
hist = ticker.history(start="2019-04-16", end="2021-04-16")

Going back e.g. the last 2 years from now (2021-04-16), the prices seems to be correct until dividends are payed. In this case, dividends have been payed on 2020-05-22 (1,58), 2020-05-21 (1,58) and 2019-05-15 (1,50). The difference correlates almost (but not 100%) to the amount of the dividend.

Following screenshot is showing the differences with the "Open" prices:

comparison yfinance - yahoo - SAP.DE

https://finance.yahoo.com/quote/SAP.DE/history?period1=1514764800&period2=1618617600&interval=1d&filter=history&frequency=1d&includeAdjustedClose=true

You can observe the difference for "Open", "High", "Low" and "Close*", but "Adj Close**" seems to be correct.

comparsion 2 - SAP.DE

If you use parameter interval="1h", the "Open" price (108,36) is correct (2020-05-21):

hist = ticker.history(interval="1h", start="2020-05-19", end="2020-05-25")

2020-05-21 108.360001 108.360001 107.599998 107.739998 175957
2020-05-21 107.900002 108.040001 107.300003 107.680000 416473
2020-05-21 107.459999 107.839996 107.300003 107.400002 433919
2020-05-21 107.580002 107.639999 107.120003 107.300003 158440
2020-05-21 107.480003 107.559998 107.059998 107.320000 227438
2020-05-21 107.379997 108.019997 107.199997 107.739998 189142
2020-05-21 107.500000 108.339996 107.500000 107.879997 336406
2020-05-21 108.059998 108.339996 107.120003 107.279999 454079
2020-05-21 107.779999 107.779999 106.400002 106.720001 542355

Maybe the following can explain the differences:

1.) Calculation of Adjusted Close: https://help.yahoo.com/kb/SLN28256.html

2.) Source: https://finance.zacks.com/adjusted-closing-price-vs-closing-price-9991.html

While dividends are good for stockholders, they actually decrease the value of each company stock. The decrease is caused by the fact that paying out dividends reduces the value of the company because they are transferring money or stocks into the hands of shareholders instead of investing it back into the company. Unlike closing price, adjusted closing price reflects devaluation caused by dividend disbursement.

Further discussion about this:

How does Yahoo Finance calculate Adjusted Close stock prices?

Seems, that there is a parameter "back_adjust=True", which should provide adjusted values, but was not able to get adjustes values?

hist = ticker.history(interval="1d", start="2020-05-19", end="2020-05-23", back_adjust=True)

https://github.com/ranaroussi/yfinance/issues/687

Upvotes: 1

Related Questions