How do you check for market holidays (any modules)?

Discussion in 'App Development' started by lime, Jun 20, 2024.

  1. lime

    lime

    Market days do not necessarily coincide with public holidays.

    For programs that relate to historical dates, such as getting historical data or backtesting, is there some DateTime/Calendar class or module (Java or Python) for US trading days, so I can check if a date is open or not?

    Manual checking dates on NYSE website then writing a MarketDate class is cumbersome and error-prone.
     
    murray t turtle likes this.
  2. NorgateData

    NorgateData Sponsor

    An easy way is to use an index symbol - eg. $SPX or $DJI. When that has data, then the market was open.
     
  3. traider

    traider

    chatgpt
     
  4. newbunch

    newbunch

    If you are using IB, you can check the schedule for each instrument in TWS or via the API. This will give you the holidays (when markets are closed). However, sometimes a market may be open on a holiday (e.g., some futures), in which case it trades but volume will be light.
     
    lime likes this.
  5. mervyn

    mervyn

    lol. you don't need to know. connect to the exchange datafeed, if it moves, the exchange is open, holidays have nothing to do with it.
     
    murray t turtle and newbunch like this.
  6. LOL
    %%
    Exactly;
    except many US exchanges close for thee TX holy day yesterday:D:D
    I GOOG or duck duck go it for market holidays
     
  7. Peter8519

    Peter8519

  8. Yes.

    For me, on stock index futures, my application skips every day that's shorter than 6 1/2 hours.
     
  9. d08

    d08

    Did you try searching for this? Because in Python there's pandas_market_calendars which does what you want. Has been mentioned on ET multiple times as well.
     
    GamblerTraderInvestor likes this.
  10. Can vouch for pandas market calendars I use it extensively. Just install the module using pip and set it to NYSE for american markets. An example function i wrote:
    ```
    def_get_next_trading_day(self, date: datetime) -> datetime:
    '''
    Takes a date and returns the next trading day using pandas_market_calendars

    param date: datetime object

    :return: datetime object of the next trading day
    '''
    nyse = mcal.get_calendar('NYSE')
    schedule = nyse.schedule(start_date=date, end_date=date + pd.Timedelta(days=10))
    next_trading_day = schedule[schedule.index > date].index[0]
    returnnext_trading_day​
    ```
     
    #10     Jun 23, 2024