exchange_calendars icon indicating copy to clipboard operation
exchange_calendars copied to clipboard

First session is alway 20 years in the past

Open pjmcdermott opened this issue 7 months ago • 6 comments

Today:


Python 3.10.12 (main, Mar 22 2024, 16:50:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import exchange_calendars
>>> xlon=exchange_calendars.get_calendar("XLON")
>>> xlon.first_session
Timestamp('2004-07-22 00:00:00')

But when I did this yesterday I got:

>>> xlon.first_session
Timestamp('2004-07-21 00:00:00')

First session appears to always be 20 years in the past.

I can understand (and my assumption was) that there might be a constraint to first_session based on the available data (and that this may vary by exchange). But this response suggests that first_session is always driven by an arbitrary 20 year window.

This is an issue for anyone doing longer-run analysis/research. It also suggests that this package isn't making the most of the historical data that is does have available.

The definition of first_session in exchange.py:

    @property
    def first_session(self) -> pd.Timestamp:
        """First calendar session."""
        return self.sessions[0]

suggests that self.sessions is a list of timestamps. While there may be an argument for not generating too large a list I feel that this could be left in the control of the user by allowing them to specify and overall session start date (or a start and end date, or a window duration) before building this sessions list.

Alternatively, first_session could return a computed first session date based on the available data per exchange, rather than returning the value of a pre-computed list.

pjmcdermott avatar Jul 22 '24 12:07 pjmcdermott