atreadw1492 / yahoo_fin

Scrape stock price history from new (Spring 2017) Yahoo Finance layout
MIT License
286 stars 125 forks source link

options.get_expiration_dates(TICKER) Not Returning Proper Values #53

Open zjorge96 opened 3 years ago

zjorge96 commented 3 years ago

I have been running into an error where the "get_expiration_dates()" will return only a couple dates or an entirely empty list. For example when working it will return this: MOS ['June 25, 2021', 'July 2, 2021', 'July 9, 2021', 'July 16, 2021', 'July 23, 2021', 'July 30, 2021', 'September 17, 2021', 'December 17, 2021', 'January 21, 2022', 'January 20, 2023']

But will occasionally run something like this: MOS ['January 21, 2022', 'January 20, 2023'] or FMC [] Resulting in an error like below because there is no dates in the list. Traceback (most recent call last): File "c:\Users\User\Documents\options.py", line 300, in bo.topFive(chosen_sector) File "c:\Users\User\Documents\options.py", line 116, in topFive call = self.closestCallStrike(sector[i], cur_stock_price, closing_dates[0]) IndexError: list index out of range

zjorge96 commented 3 years ago

Made a quick tester program to check:

from yahoo_fin import options i = 0 while i < 100: closing_dates = options.get_expiration_dates("MOS") print(closing_dates) i += 1

After 39 iterations of it working correctly, the loop slows down and starts only grabbing the last two dates ['January 21, 2022', 'January 20, 2023']

mathias5986 commented 2 years ago

Hello,

Has this issue been solved ? I am having the same problem. Sometimes it shows 3 expiration dates and sometimes it shows all:

image

image

This is so strange..

thanks,

Mathias