quantlab.dataset.base.bar_after_on#
- quantlab.dataset.base.bar_after_on(bars, date, n, caller)[source]#
Return the bar
nbars afterdateon the barsbarsgives, or the last bar there is.The arithmetic behind
BaseDataset.bar_afterandFactor.bar_after(quantlab.factor.base), the forward counterpart ofbar_before_on: the bars afterdateare those stamped strictly later,n=1is the first of them,n=0returnsdateitself, and when fewer thannbars followdatethe last bar is returned,dateitself when none follow, so the result is never beforedate.- Parameters:
- barscallable
Called with
dateas apd.Timestampand returning the sorted bar timestamps, at least every one afterdate, as apd.DatetimeIndex. Called only when the bars are needed, son=0reads nothing.- datestr, datetime.date or pd.Timestamp
The date to count forward from.
- nint
How many bars to count forward; non-negative.
- callerstr
The class name the error message starts with (
"<caller>.bar_after(): ...").
- Returns:
- pd.Timestamp
The timestamp of that bar.
- Raises:
- ValueError
If
nis negative.
Examples
>>> bars = pd.DatetimeIndex(["2024-01-05", "2024-01-08", "2024-01-09"]) >>> bar_after_on(lambda _: bars, "2024-01-05", 1, "Demo") Timestamp('2024-01-08 00:00:00') >>> bar_after_on(lambda _: bars, "2024-01-05", 5, "Demo") # fewer follow: the last bar Timestamp('2024-01-09 00:00:00')