mcdallas / wallstreet

Real time stock and option data.
MIT License
1.33k stars 201 forks source link

ValueError when there is only call or only put in the most recent expiration date #7

Closed MollyZhang closed 7 years ago

MollyZhang commented 7 years ago

jnj = wallstreet.Call("JNJ", source="yahoo")

gives this error:

ValueError: ('Possible expiration dates for this stock are:', ['13-04-2017', '21-04-2017', '05-05-2017', '12-05-2017', '19-05-2017', '26-05-2017', '16-06-2017', '21-07-2017', '20-10-2017', '19-01-2018', '15-06-2018', '18-01-2019'])

And that's because on expiration 13-04-2017, there is only put option, no call option. For the rest of the expiration dates, there are both calls and puts. screen shot 2017-04-10 at 5 05 32 pm

Is there anyway to not throw ValueError, and instead find the nearest date that do have calls? Thanks!

mcdallas commented 7 years ago

@MollyZhang I can't find an example to test it but 9982345f06bfcbc897e1774ffd9c189f732f736b should take care of the issue

MollyZhang commented 7 years ago

Here is an example "WOOF", http://finance.yahoo.com/quote/WOOF/options?p=WOOF&date=1495152000

WOOF has calls for may 19 2017, june 16 2017, july 21 2017 and sep 15, 2017 while only has puts for june 16 2017, july 21 2017 and sep 15, 2017 (not may 19 2017).

after updating with your newest commit, wallstreet.Put("WOOF", source="yahoo") still gives this error:

screen shot 2017-04-15 at 3 54 50 pm
mcdallas commented 7 years ago

Ok I see what the issue is now. I've added a dictionary to keep track of dates that are listed as expiration dates but do not contain both calls and puts and remove them from the expirations list for the given type

MollyZhang commented 7 years ago

Thanks for the update! I tried again, now getting this error saying it can't find option for this stock at all.

screen shot 2017-04-16 at 10 27 26 am

and

screen shot 2017-04-16 at 10 27 06 am
mcdallas commented 7 years ago

@MollyZhang You'll have to use the source='yahoo' parameter since Google finance has no option data for this company

MollyZhang commented 7 years ago

@mcdallas You are right I forgot to add source="yahoo", I just checked it, yes it works as expected now. Thank you! I am closing this issue.