Skip to content

Strike prices > 1k are returned as strings #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aisthesis opened this issue Feb 8, 2016 · 3 comments · Fixed by #169
Closed

Strike prices > 1k are returned as strings #168

aisthesis opened this issue Feb 8, 2016 · 3 comments · Fixed by #169

Comments

@aisthesis
Copy link

When trying to pull call strikes from Yahoo! Finance, I'm getting for 'GOOGL' as strike:

minputstrike = straddle['strike'] - straddle['price']
    TypeError: unsupported operand type(s) for -: 'str' and 'float'

When I print out the value for straddle['strike'], which is the df pulled from yahoo finance, I get: 1,040.00. It looks like the comma from Yahoo is not allowing casting as float.

@femtotrader
Copy link
Contributor

Here is a way to reproduce:

from pandas_datareader import data
opt = data.Options("GOOG", "yahoo")
opt.get_call_data()  # opt.get_all_data()
opt.calls180119.index.levels[0] + 0.5

it raises

TypeError: Can't convert 'float' object to str implicitly

We might have a look at
http://stackoverflow.com/questions/6633523/how-can-i-convert-a-string-with-dot-and-comma-into-a-float-number-in-python

There is two way to fix this

  • replace ',' by ''
  • use locale (locale.atof)

We ever have some problems with locale see #63

This issue could be an occasion to fix it!

Maybe we should use a context manager to save user local, set user locale to english and performs string to number conversion and then go back to user local.

I'm aware that's not the easiest way to fix this issue but that's probably the cleanest.

@aisthesis
Copy link
Author

While I haven't looked at the code that initially creates the options DataFrame, I don't see how it could be otherwise than having strike be a string in the early stages of the creation process. I would think the easiest (and adequately performant) way to do it would be just to strip commas out of the string before attempting to convert to float.

If valstr is guaranteed to be a string, then you could do maybe something like float(valstr.replace(',', '')). Since the performance bottleneck on all of this is going to be data transfer by wire plus yahoo's internal process of getting it from their databases, that's probably performant enough. But I'm all for it, if there's a way that is faster.

@gliptak
Copy link
Contributor

gliptak commented Feb 28, 2016

In the Google options processing, I decided to process as float(row['p'].replace(',', ''))
#183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants