Python how-to

Market holidays in pandas

pandas' business-day offsets skip weekends, not exchange holidays, and USFederalHolidayCalendar is the wrong calendar for the NYSE (it closes on Good Friday and trades on Columbus Day). Load the real exchange holidays from a free JSON endpoint and hand them to CustomBusinessDay.

Trading days for the NYSE

Needs pandas and requests. No key: two keyless calls.

import pandas as pd
import requests

BASE = "https://settledate.dev/v1"

def market_holidays(cal, years):
    rows = []
    for y in years:
        r = requests.get(f"{BASE}/calendars/{cal}/holidays", params={"year": y}, timeout=10)
        r.raise_for_status()
        rows += r.json()["holidays"]
    df = pd.DataFrame(rows)
    df["date"] = pd.to_datetime(df["date"])
    return df

hol = market_holidays("XNYS", [2026, 2027])
print(hol.tail(4).to_string(index=False))

# A business-day offset that skips weekends and NYSE holidays
nyse = pd.offsets.CustomBusinessDay(holidays=hol["date"])

days = pd.date_range("2026-11-20", "2026-12-04", freq=nyse)
print(len(days), "trading days:", ", ".join(d.strftime("%m-%d") for d in days))
print("2026-11-25 + 1 trading day =", (pd.Timestamp("2026-11-25") + nyse).date())

Real output:

      date         name weekday
2027-07-05     July 4th     Mon
2027-09-06    Labor Day     Mon
2027-11-25 Thanksgiving     Thu
2027-12-24    Christmas     Fri
10 trading days: 11-20, 11-23, 11-24, 11-25, 11-27, 11-30, 12-01, 12-02, 12-03, 12-04
2026-11-25 + 1 trading day = 2026-11-27

Thanksgiving (11-26) is skipped, so a Wednesday plus one trading day lands on Friday. Swap XNYS for XLON, XETR or XTKS; the response also lists early_closes (half days).

T+1 settlement dates in a DataFrame

US settlement needs both the NYSE and the Federal Reserve open. The Fed closes on Columbus Day and Veterans Day while stocks trade, so join the two holiday lists:

import pandas as pd
import requests

BASE = "https://settledate.dev/v1"

def holidays(cal, year):
    r = requests.get(f"{BASE}/calendars/{cal}/holidays", params={"year": year}, timeout=10)
    r.raise_for_status()
    return [h["date"] for h in r.json()["holidays"]]

# US T+1 needs the NYSE and the Federal Reserve open (Columbus Day, Veterans Day)
closed = pd.to_datetime(holidays("XNYS", 2026) + holidays("us-fed", 2026)).unique()
t1 = pd.offsets.CustomBusinessDay(holidays=closed)

trades = pd.DataFrame({"trade_date": pd.to_datetime(["2026-10-09", "2026-11-06", "2026-11-25", "2026-12-24"])})
trades["settles"] = trades["trade_date"].map(lambda d: d + t1)
print(trades.to_string(index=False))

Real output:

trade_date    settles
2026-10-09 2026-10-13
2026-11-06 2026-11-09
2026-11-25 2026-11-27
2026-12-24 2026-12-28

Friday Oct 9 settles Tuesday Oct 13 because of Columbus Day; Christmas Eve settles the next Monday. Each date matches /v1/settlement-date, which you can call per trade instead if you'd rather not hold the calendar yourself (T+1 settlement date API).

That ran without a key. Keyless access covers NYSE, Nasdaq, London, Xetra, Tokyo, the Fed, TARGET2, UK payments and every country calendar, 60 calls an hour per IP. For scripts, notebooks and schedules, a free key gives 5,000 calls a month (no card). Paid plans add the other 24 exchanges.

Get a free key Docs

Questions

Does pandas know NYSE holidays?

No. pandas ships USFederalHolidayCalendar, which includes Columbus Day and Veterans Day (the NYSE trades) and misses Good Friday (the NYSE closes). You need an exchange calendar.

Do I need an API key?

No. The holidays endpoint answers without a key for NYSE, Nasdaq, London, Xetra, Tokyo and the payment calendars, 60 calls an hour per IP. A free key gives 5,000 calls a month.

Which years are covered?

2020 through 2030 for most exchanges; fetch each year you need and concatenate.

Related: NYSE holidays 2027 · T+1 settlement date API · API docs