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.
An easy way is to use an index symbol - eg. $SPX or $DJI. When that has data, then the market was open.
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.
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.
LOL %% Exactly; except many US exchanges close for thee TX holy day yesterday I GOOG or duck duck go it for market holidays
Can try this...(at the bottom of the page) 2024 Economic Calendar (econoday.com) and this... NYSE: Holidays and Trading Hours
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.
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```