Reputation: 489
I'm coding a script that fetches information from the Yahoo finance API and even though the API is pretty slow it works for what I'm going to use it for. During testing of the script I found out that I got an IndexOutOfBounds exception and up on investigation I see that Yahoo Finance is returning stock quote information for the stocks I have except that its missing one day for one of the stocks, and I suspect that when using a wider time period it will miss more days as I have got that exception before when using a wider time period, but I thought it was something in my code that I could just fix later.
That the Yahoo finance API is missing entire days of stock quote information makes the API useless for me. Has anyone else experienced this, and is there any solution to it ? I'm guessing I would need to use another way to get the data.
Right now I'm using this python module https://pypi.python.org/pypi/yahoo-finance.
Yahoo finance is the only API I've currently found that contains the information I need and support the stock exchange I need to query data for.
Update: Yes, I can re-produce the problem. Below is the code to re-produce:
>>> import datetime as dt
>>> import yahoo_finance as yf
>>>
>>> quote = yf.Share('GJF.OL')
>>> date_from = str(dt.date.today() - dt.timedelta(days=5))
>>> date_to = str(dt.date.today())
>>> quote_his = quote.get_historical(date_from, date_to)
>>> import pprint
>>> pprint.pprint(quote_his)
[{'Adj_Close': '156.50',
'Close': '156.50',
'Date': '2016-10-14',
'High': '156.50',
'Low': '153.10',
'Open': '153.50',
'Symbol': 'GJF.OL',
'Volume': '487600'},
{'Adj_Close': '153.60',
'Close': '153.60',
'Date': '2016-10-13',
'High': '153.60',
'Low': '152.50',
'Open': '153.30',
'Symbol': 'GJF.OL',
'Volume': '508800'}]
>>>
This code should print out the stock information for Monday (2016-10-17), but it does not. If I choose another stock I get the stock information for Monday in the dictionary as well.
Update 2: I tried another module named ystockquote and got the same result. I get information for thursday and friday, but not monday. If i ask for a different quote i get info from all three days. When i got to the yahoo finance site it has the stock information from monday in graphs etc.
Update 3: The data is now found for the GJF.OL which probably would have been related to a delay in the stock prices for the historical tables in the API as pointed out below in an answer. However, I was still able to receive stock price information from other stocks for the dates I did not receive stock price information from for the GJF.OL stock.
While I'm now receiving stock price information for the GJF.OL stock I tried to get the last 165 days of stock price information from the stocks, but there is 1 day missing from the NAS.OL stock meaning the dictionary returned does not contain any data for that day while the other stocks have that information. The stock is NAS.OL and the date is 3rd of August 2016 where the data is missing. Any ideas why this data is missing ?
Upvotes: 3
Views: 8985
Reputation: 1
Might it be the time zone difference? Try experimenting with different YFINANCE date ranges. e.g. add an extra day to your end date etc... There seems to be something odd with the returned data. Also I'm only seeing data from 10 AM and not from 9:30 AM. That's also puzzling.
Upvotes: 0
Reputation: 7576
This probably has nothing to do with the Python bindings, and it's entirely Yahoo data. If you read through the bindings, the command that runs is essentially
curl -G 'https://query.yahooapis.com/v1/public/yql' \
--data-urlencode 'env=store://datatables.org/alltableswithkeys' \
--data-urlencode 'format=json' \
--data-urlencode 'q=select * from yahoo.finance.historicaldata where symbol = "GJF.OL" and startDate = "2016-10-13" and endDate = "2016-10-18"'
When I rant it for myself, I got data for 13th, 14th, 17th, and 18th. The table you're accessing is called historical data, so it's not unreasonable for there to be a 24-hour for the data to show up.
If you see a discrepancy between that endpoint and the Python bindings, you might be onto something, but the code for those bindings is pretty straightforward, and it seems to just pass the date range along.
Upvotes: 1