GBERESEARCH / volvisualizer

Extract and visualize implied volatility from option chain data
MIT License
30 stars 9 forks source link

Cannot convert non-finite values (NA or inf) to integer #4

Closed igaloly closed 2 months ago

igaloly commented 3 months ago

Hey, Now I'm getting:

    imp = Volatility(ticker='^SPX', start_date='2021-8-18', wait=1, monthlies=True, q=0.013)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/volvisualizer/volatility.py", line 100, in __init__
    params, tables = Data.create_option_data(params=params, tables=tables)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/volvisualizer/market_data.py", line 100, in create_option_data
    params, tables = DataPrep.transform(params=params, tables=tables)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/volvisualizer/market_data_prep.py", line 151, in transform
    tables = cls._trade_columns(tables=tables)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/volvisualizer/market_data_prep.py", line 190, in _trade_columns
    tables['data']['Volume'].replace('-',0).astype(int))
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/generic.py", line 6643, in astype
    new_data = self._mgr.astype(dtype=dtype, copy=copy, errors=errors)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 430, in astype
    return self.apply(
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/internals/managers.py", line 363, in apply
    applied = getattr(b, f)(**kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/internals/blocks.py", line 758, in astype
    new_values = astype_array_safe(values, dtype, copy=copy, errors=errors)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/dtypes/astype.py", line 237, in astype_array_safe
    new_values = astype_array(values, dtype, copy=copy)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/dtypes/astype.py", line 182, in astype_array
    values = _astype_nansafe(values, dtype, copy=copy)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/dtypes/astype.py", line 101, in _astype_nansafe
    return _astype_float_to_int_nansafe(arr, dtype, copy)
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/dtypes/astype.py", line 145, in _astype_float_to_int_nansafe
    raise IntCastingNaNError(
pandas.errors.IntCastingNaNError: Cannot convert non-finite values (NA or inf) to integer
GBERESEARCH commented 3 months ago

Hi. Thanks for pointing this out. I had fixed in a data only version I'm working on just to serve data to React but I hadn't applied the same here. Fixed in version 1.1.14 that I just uploaded