examples icon indicating copy to clipboard operation
examples copied to clipboard

incorrect dates?

Open carstenf opened this issue 3 years ago • 1 comments

Beautiful pice of code!

I'm downloading the vix data from https://www.cboe.com/us/futures/market_statistics/historical_data/ and one needs to know the expiring date to be able to get the file:

urlStr = 'https://www.cboe.com/us/futures/market_statistics/historical_data/products/csv/VX/2014-03-18' urllib.request.urlretrieve(urlStr)

I found only three issues between 2014 and today: 2014-03-19 -> should be 2014-03-18 2019-03-20 -> should be 2020-03-18 2022-03-16 -> should be 2022-03-15

I check regarding valid business days and all days are valid.

end = start = '2014-03-18' len(nyse.valid_days(start_date=start, end_date=end))

some idea how to fix it?

carstenf avatar Jan 30 '22 16:01 carstenf

looks like I found a solution, you might try this:

import pandas_market_calendars as mcal

nyse = mcal.get_calendar('NYSE')
def check_if_business_day(day):
    end =  start = day
    return len(nyse.valid_days(start_date=start, end_date=end))>0

than inside: def get_expiry_date_for_month(curr_date):

........

    # TODO: Incorporate check that it's a trading day, if so move the 3rd
    # Friday back by one day before subtracting

    if check_if_business_day(third_friday_next_month) == False:
        third_friday_next_month = third_friday_next_month - one_day   

    return third_friday_next_month - thirty_days

carstenf avatar Jan 30 '22 19:01 carstenf