dougransom / vix_utils

vix_utils provides command line tools and a a Python API for preparing data for analysing the VIX Futures and Cash Term structures. Term Structure data can be exported to excel (.xslx), csv, and pickle formats.
MIT License
41 stars 9 forks source link

missing futures data front 2nd month, and before same futures when it's was 3rd month... data is NaN? #31

Closed githubbla closed 1 month ago

githubbla commented 2 months ago

Screenshot 2024-04-24 at 13 48 02

githubbla commented 2 months ago

@dougransom could you please look into issue?

gnzsnz commented 1 month ago

seems to be related to the url generated to download VX_M4

vu.download_vix_futures.generate_monthly_url_date(2024,6) is returning https://cdn.cboe.com/data/us/futures/market_statistics/historical_data/VX/VX_2024-06-19.csv which is invalid

the valid url is https://cdn.cboe.com/data/us/futures/market_statistics/historical_data/VX/VX_2024-06-18.csv

So VX_M4 is missing from vix_utils.async_load_vix_term_structure()

image

somehow the expiration date is set to 2024-06-18 which is a Tuesday. pandas_market_calendars is not listing 2024-06-19 as valid day. but vix_futures_dates.vix_futures_expiry_date_monthly somehow is missing it

image

interestingly the weekly expiration is working fine, and the file 2024-06-18.w* is downloaded

hope this helps @dougransom

githubbla commented 1 month ago

@dougransom, @gnzsnz

https://en.wikipedia.org/wiki/Juneteenth 19-Jun US public holiday from 2021!! 🤯

gnzsnz commented 1 month ago

I think i found the bug,

https://github.com/dougransom/vix_utils/blob/6a4cca930528379de61ef8852ff36b2708bfcde9/src/vix_utils/vix_futures_dates.py#L84

it should be

    futures_expiry_date = option_expiry_date - dt.timedelta(days=30)
    # also check for a holiday on the 30 days before the 3d friday
    if friday_expiration and not any(_valid_cfe_days.isin([futures_expiry_date])):
        futures_expiry_date = futures_expiry_date - dt.timedelta(days=1)

current code is checking for an exchange holiday using the options expiration date, and should use the futures expiry date. by changing this the if statement will be true and take one day before. which will solve the issue (I think)

dougransom commented 1 month ago

@dougransom, @gnzsnz

https://en.wikipedia.org/wiki/Juneteenth 19-Jun US public holiday from 2021!! 🤯

https://github.com/rsheftel/pandas_market_calendars/issues/261

dougransom commented 1 month ago

@gnzsnz Thanks for fixing it, I have merged it in, along with a unit test and a requirement for latest pandas market calendars.

Though this error was mine, we get similar errors when the Pandas market calendars miss a holiday.

dougransom commented 1 month ago

Fixed in release 0.1.6 on PyPi.