trader.replay.sessions module¶
Trading sessions, as the app’s own bars define them.
The horizon in issue #7’s scoring rule is counted in trading days, off the distinct 1d bar dates this app already holds — never off a weekday rule, which is wrong at every market holiday and would silently shorten the horizon.
- trader.replay.sessions.session_grid(bars)[source]¶
The sorted, deduplicated trading days these bars cover.
- Parameters:
bars (Sequence[Bar])
- Return type:
list[date]
- trader.replay.sessions.session_offset(grid, start, n)[source]¶
The session n places after start on grid, or None past the end.
None rather than the last available day: clamping would quietly shorten the horizon for rows near the end of the window and inflate every long-N result. The caller drops the row instead.
- Raises:
ValueError – start is not on the grid, which means the caller built a decision date the bars do not support.
- Parameters:
grid (Sequence[date])
start (date)
n (int)
- Return type:
date | None
- trader.replay.sessions.trading_date(stamp)[source]¶
Which trading day a bar timestamp (or decision instant) names.
- Raises:
ValueError – stamp is naive. Guessing the zone would move the bar by a day for four months of the year, which is exactly the error this function exists to prevent.
- Parameters:
stamp (datetime)
- Return type:
date