split_sessionsΒΆ
Defined in fynance.data
- split_sessions(X, ts, open='09:30', close='16:00', utc_offset=0.0, weekdays_only=True)[source]
Split
Xinto one chunk per trading session.- Parameters:
- Xndarray
Array aligned with
tsalong its first axis.- tsndarray of int64 or float64
Non-decreasing epoch-second (UTC) timestamps, shape
(n,).- open, close, utc_offset, weekdays_only
See
session_mask.
- Returns:
- list of ndarray
One slice of
Xper session, in session order. Bars outside every session (session_id == -1) are skipped, so concatenating the result along axis 0 reproducesX[session_mask(ts, ...)].
- Raises:
- ValueError
Same as
session_mask.
Examples
>>> import numpy as np >>> from fynance.data.sessions import split_sessions >>> ts = np.array([9 * 3600, 10 * 3600, 17 * 3600, 33 * 3600, 34 * 3600]) >>> X = np.arange(5) >>> split_sessions(X, ts, open="09:30", close="16:00") [array([1]), array([4])]