rsheftel/pandas_market_calendars

date_range 1min ranges from 9:31am to 4pm instead of 9:30am to 3:59pm

ab-qf opened this issue · 3 comments

ab-qf commented

I am using version 4.3.1 with pandas 2.0.3.

CleanShot Cursor 2023-11-14 at 104552@2x

The following code results in a range from 9:31am til 4:00pm instead of 9:30am til 3:59pm.

Can I somehow change this behaviour? Is it intended?

Of course, I can subtract 1 minute from every entry. I am just looking for a better way.

That is the intended behavior. The timestamp on the bar represents the time at the end of the bar. So the first 1min bar of the trading day goes from 9:30am to 9:31am, so the timestamp is 9:31am.

ab-qf commented

FWIW, you can get the index you're after from the exchange_calendars calendar which is (I believe) the source of the data for the 'XNYS' schedule...

import exchange_calendars as xcals
cal = xcals.get_calendar("XNYS")
index = cal.trading_index(
    "2010-01-04",
    "2023-10-31",
    "1T",
    intervals=False,
    closed="left"
).tz_convert("US/Eastern")

Here the 'close' parameter effectively lets you choose which side of the bar you want to represent. Takes from:

  • 'left' (default) gives you what you're after
  • 'right' would give you what you were getting
  • 'both' will include both the 09:00 and 16:00 minutes
  • 'neither' will exclude both the 09:00 and 16:00 minutes