gerrymanoim / exchange_calendars

Calendars for various securities exchanges.
Apache License 2.0
425 stars 135 forks source link

NYSE future schedule ends at 2025-07-18 #404

Open LaurensBosscher opened 2 months ago

LaurensBosscher commented 2 months ago

Admittedly this is a bit of an edge case (I'm extrapolating an existing timeseries where timing is an element) but it seems that the trading schedule is limited to 2025-07-18:

File ~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:97, in get_trading_days(exchange, start, end)
     [86](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:86)     good_fridays = [
     [87](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:87)         date
     [88](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:88)         for date in arrow.Arrow.range("day", arrow_start, arrow_end)
     [89](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:89)         if date.isocalendar()[1] == arrow.get(date.year, 4, 1).floor("month").shift(weeks=2).isocalendar()[1]
     [90](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:90)         and date.weekday() == FRIDAY
     [91](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:91)     ]
     [93](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:93)     return [day.date() for day in business_days if day not in good_fridays]
     [95](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:95) return [
     [96](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:96)     trading_session.date()
---> [97](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:97)     for trading_session in xcals.get_calendar(exchange).sessions_in_range(start, end).to_pydatetime()
     [98](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/libraries/SavexHelpers/savex_helpers/trading_calendar/get_trading_schedule.py:98) ]

File ~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2200, in ExchangeCalendar.sessions_in_range(self, start, end, _parse)
   [2182](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2182) def sessions_in_range(
   [2183](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2183)     self, start: Date, end: Date, _parse: bool = True
   [2184](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2184) ) -> pd.DatetimeIndex:
   [2185](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2185)     """Return sessions within a given range.
   [2186](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2186) 
   [2187](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2187)     Parameters
   (...)
   [2198](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2198)         Sessions from `start` through `end`.
   [2199](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2199)     """
-> [2200](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2200)     slc = self._get_sessions_slice(start, end, _parse)
   [2201](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2201)     return self.sessions[slc]

File ~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2177, in ExchangeCalendar._get_sessions_slice(self, start, end, _parse)
   [2175](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2175) def _get_sessions_slice(self, start: Date, end: Date, _parse=True) -> slice:
   [2176](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2176)     """Slice representing a range of sessions."""
-> [2177](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2177)     start, end = self._parse_start_end_dates(start, end, _parse)
   [2178](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2178)     slice_start = self.sessions_nanos.searchsorted(start.value, side="left")
   [2179](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2179)     slice_end = self.sessions_nanos.searchsorted(end.value, side="right")

File ~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2173, in ExchangeCalendar._parse_start_end_dates(self, start, end, _parse)
   [2171](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2171) if not _parse:
   [2172](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2172)     return start, end
-> [2173](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/exchange_calendar.py:2173) return parse_date(start, "start", self), parse_date(end, "end", self)

File ~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/calendar_helpers.py:393, in parse_date(date, param_name, calendar, raise_oob)
    [391](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/calendar_helpers.py:391)         raise ValueError("`calendar` must be passed if `raise_oob` is True.")
    [392](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/calendar_helpers.py:392)     if calendar._date_oob(ts):
--> [393](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/calendar_helpers.py:393)         raise errors.DateOutOfBounds(calendar, ts, param_name)
    [395](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/laurens/develop/savex/projects/investment_decision_support_system/notebooks/CVX_recon_with_BBG_tickets/~/develop/savex/projects/investment_decision_support_system/.venv/lib/python3.12/site-packages/exchange_calendars/calendar_helpers.py:395) return ts

DateOutOfBounds: Parameter `end` receieved as '2054-12-31 00:00:00' although cannot be later than the last session of calendar 'XNYS' ('2025-07-18 00:00:00').

I can imagine that this was chose due to memory/performance reasons but perhaps it's possible to implement this with a generator so that exchange_calendars can support infinite timeseries at a constant memory usage?

maread99 commented 2 weeks ago

Hi @LaurensBosscher, sorry about the tardiness of this reply...

By default a calendar ends one year into the future. This can be changed by passing the 'end' option when creating the calendar. For example:

import exchange_calendars as xcals
cal = xcals.get_calendar("XNYS", end="2050")
cal.last_session

outputs...

Timestamp('2049-12-31 00:00:00')