session_boundsΒΆ
Defined in fynance.data
- session_bounds(ts, open='09:30', close='16:00', utc_offset=0.0, weekdays_only=True)[source]
First/last bar index of each trading session.
- Parameters:
- tsndarray of int64 or float64
Non-decreasing epoch-second (UTC) timestamps, shape
(n,).- open, close, utc_offset, weekdays_only
See
session_mask.
- Returns:
- ndarray of int64
Shape
(n_sessions, 2); rowkis(first_index, last_index)(both inclusive, intots) of sessionk. Empty (shape (0, 2)) if no bar falls in a session.
- Raises:
- ValueError
Same as
session_mask.
Examples
>>> import numpy as np >>> from fynance.data.sessions import session_bounds >>> ts = np.array([9 * 3600, 10 * 3600, 17 * 3600, 33 * 3600, 34 * 3600]) >>> session_bounds(ts, open="09:30", close="16:00") array([[1, 1], [4, 4]])