session_mask¶
Defined in fynance.data
- session_mask(ts, open='09:30', close='16:00', utc_offset=0.0, weekdays_only=True)[source]
Flag timestamps that fall inside a trading session.
- Parameters:
- tsndarray of int64 or float64
Non-decreasing epoch-second (UTC) timestamps, shape
(n,).- open, closestr, default “09:30”, “16:00”
Local session open/close,
"HH:MM".close < open(orclose == open) models an overnight session, e.g."18:00"->"17:00".- utc_offsetfloat, default 0.0
Fixed exchange-clock offset from UTC, in hours (e.g.
-5.0for NYSE standard time). A single fixed offset – DST is out of scope, see the module docstring.- weekdays_onlybool, default True
Exclude sessions that OPEN on a Saturday/Sunday (local calendar day of the session’s open, not of every individual bar – see
session_id).
- Returns:
- ndarray of bool
Truewheretsfalls in[open, close)local time (and, ifweekdays_only, the session opened on a weekday).
- Raises:
- ValueError
If
open/closeare not well-formed"HH:MM"strings,tsis not 1-D, ortsis not non-decreasing.
Examples
>>> import numpy as np >>> from fynance.data.sessions import session_mask >>> ts = np.array([9 * 3600, 10 * 3600, 17 * 3600]) # 09:00, 10:00, 17:00 UTC >>> session_mask(ts, open="09:30", close="16:00") array([False, True, False])