numeraire.core.data.TimeSeriesView#
- class numeraire.core.data.TimeSeriesView(returns: DataFrame, features: DataFrame | None = None, *, blocks: Sequence[Block] | None = None, horizon: int = 1, risk_free: Series | None = None, excess: str = 'simple')[source]#
Bases:
objectA point-in-time view: a returns (decision) calendar + one or more aligned feature blocks.
- Parameters:
returns –
(date x asset)returns; its index is the decision/rebalance calendar. Excess by default; ifrisk_freeis given they are treated as raw and converted to excess internally. A return indexed attis realized over the period ending att. One column = market timing.features – Convenience single-block input: a
(date x feature)frame sharing the returns index, wrapped as onelag=0FeatureBlock. Mutually exclusive withblocks. Omit bothfeaturesandblocksfor a returns-only view (market-timing / moment-based strategies that read only the returns block):feature_namesis then empty andfeatures_frame()/aligned()yield a zero-columnX.blocks – Explicit list of
FeatureBlock— each with its own calendar and availability lag. Use this to combine heterogeneous macro sources (e.g. FREDlag=1+ anotherlag=2+ a no-vintage source) as predictors. Mutually exclusive withfeatures.horizon (int) – Forecast horizon
hin calendar steps; features attpair with the return realized over(t, t+h].h >= 1;h = 0(contemporaneous) is rejected.risk_free – Optional raw→excess conversion (see
_to_excess()).excess – Optional raw→excess conversion (see
_to_excess()).
Notes
With
features, that frame must share the returnsDatetimeIndex(the original behaviour). Withblocks, each block keeps its own calendar and is aligned to the returns calendar by its own lag-awareFeatureBlock.asof(). With neither, the view is returns-only: no feature blocks, so everyXis shaped(T x 0)andalignedyields the returns targets alone.- __init__(returns: DataFrame, features: DataFrame | None = None, *, blocks: Sequence[Block] | None = None, horizon: int = 1, risk_free: Series | None = None, excess: str = 'simple') None[source]#
Methods
__init__(returns[, features, blocks, ...])aligned([horizon])Supervised
(dates, X, Y)over the calendar:Xattpaired with(t, t+h].between(start, end)Test-fold view: data truncated to
<= end, calendar restricted to(start, end].Feature vector known as of
t, concatenated lag-aware across all blocks.The
(date x feature)features block over the calendar (lag-aware; raw eject).The
(date x asset)returns block over the calendar (raw eject).tail(k)Restrict the calendar to its last
kobservations (rolling window; data unchanged).target_asof(t[, horizon])Return realized over
(t, t+h]per asset, ornanif not yet realized in-view.window(end)View restricted to information available up to
end(data and calendar both <= end).Attributes
Asset (returns-column) names.
Rebalancing / observation timestamps (the prediction calendar).
Feature (predictor-column) names, concatenated across blocks in order.
- property calendar: DatetimeIndex#
Rebalancing / observation timestamps (the prediction calendar).
- window(end: object) TimeSeriesView[source]#
View restricted to information available up to
end(data and calendar both <= end).No look-ahead: returns and every feature block are truncated to dates
<= end. Used for train folds —aligned()then only forms pairs whose target is realized byend.
- between(start: object, end: object) TimeSeriesView[source]#
Test-fold view: data truncated to
<= end, calendar restricted to(start, end].Predictions are formed only at calendar dates strictly after
start; each usesfeatures_asof(t)(data<= t). Realized P&L is computed by the engine from the full view, so the model never sees future returns.
- property feature_names: list[str]#
Feature (predictor-column) names, concatenated across blocks in order.
- tail(k: int) TimeSeriesView[source]#
Restrict the calendar to its last
kobservations (rolling window; data unchanged).
- features_frame() DataFrame[source]#
The
(date x feature)features block over the calendar (lag-aware; raw eject).
- features_asof(t: object) NDArray[float64][source]#
Feature vector known as of
t, concatenated lag-aware across all blocks.
- target_asof(t: object, horizon: int | None = None) NDArray[float64][source]#
Return realized over
(t, t+h]per asset, ornanif not yet realized in-view.Compounds simple returns over the
hdata periods strictly aftert.
- aligned(horizon: int | None = None) tuple[DatetimeIndex, NDArray[float64], NDArray[float64]][source]#
Supervised
(dates, X, Y)over the calendar:Xattpaired with(t, t+h].Only pairs whose target is fully realized within this view’s data are kept — so on a
window(end)view the last usable feature datetsatisfiest + h <= end(the horizon purge that kills the contemporaneous leak).Xrows are lag-aware and concatenated across feature blocks.