Skip to content
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

Undocument raw parameter in get_options_chain trigger exception #88

Open
mdelvaux opened this issue Jun 5, 2022 · 0 comments
Open

Undocument raw parameter in get_options_chain trigger exception #88

mdelvaux opened this issue Jun 5, 2022 · 0 comments

Comments

@mdelvaux
Copy link

mdelvaux commented Jun 5, 2022

I know the parameter is undocumented, but cleaning up as what raw=False would need seems very useful, but it fails in some cases. I think there are two problems in the current code

  • the code fails if the column was numeric, i.e. there were none of the special cases present
  • the code fails when a value contains a comma

I can solve the two issues above with the following code where I also added support to transform column "Implied Volatility" that has a % format similar to "% Change"

    for cp, chain in chains.items():
        # some columns can have "-" to indicate no data
        # the code in get_options_chain normally has a parameter "raw" that would make the conversion but
        # it generates exceptions on str called on non string column, can be used as blueprint though
        #         calls["% Change"] = calls["% Change"].str.strip("%").map(force_float)
        #         calls["% Change"] = calls["% Change"].map(lambda num: num / 100 if isinstance(num, float) else 0)
        #         calls["Volume"] = calls["Volume"].str.replace("-", "0").map(force_float)
        #         calls["Open Interest"] = calls["Open Interest"].str.replace("-", "0").map(force_float)
        for col in ["% Change", "Implied Volatility"]:
            if chain[col].dtype == object:
                chain[col] = pd.to_numeric(chain[col].str.strip("%").str.replace("-","0").str.replace(",","")) / 100
        for col in ["Volume", "Open Interest"]:
            if chain[col].dtype == object:
                chain[col] = pd.to_numeric(chain[col].str.replace("-", "0").str.replace(",",""))
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

No branches or pull requests

1 participant