quantlab.utils.resample.session_labels#
- quantlab.utils.resample.session_labels(timestamps, freq, sessions, owner)[source]#
Return each timestamp’s bar inside its trading session.
Bars here are labelled at their end, as
NbboResamplerlabels them, so a source timestamp belongs to the session whoseopen < t <= close."1d"labels the whole session with its date at midnight, so a daily panel lines up with daily stores. Any other frequency cuts the session into right-closed bars from its open, labelled at their end; a partial last bar is labelled at the session close.- Parameters:
- timestampsnp.ndarray
Source timestamps, naive UTC.
- freqstr
A
ResampleFrequencytoken.- sessionspd.DataFrame
Columns
date,openandclose(naive UTC), one row per session, sorted byopen.- ownerstr
Class name quoted in error messages.
- Raises:
- ValueError
If a timestamp falls in no session.
Examples
>>> sessions = pd.DataFrame({ ... "date": [pd.Timestamp("2024-01-24").date()], ... "open": [pd.Timestamp("2024-01-24 14:30")], ... "close": [pd.Timestamp("2024-01-24 21:00")], ... }) >>> ts = pd.to_datetime(["2024-01-24 14:31", "2024-01-24 21:00"]) >>> session_labels(ts, "1d", sessions, "Demo").astype("datetime64[D]").tolist() [2024-01-24, 2024-01-24]