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: object

A 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; if risk_free is given they are treated as raw and converted to excess internally. A return indexed at t is realized over the period ending at t. One column = market timing.

  • features – Convenience single-block input: a (date x feature) frame sharing the returns index, wrapped as one lag=0 FeatureBlock. Mutually exclusive with blocks. Omit both features and blocks for a returns-only view (market-timing / moment-based strategies that read only the returns block): feature_names is then empty and features_frame() / aligned() yield a zero-column X.

  • blocks – Explicit list of FeatureBlock — each with its own calendar and availability lag. Use this to combine heterogeneous macro sources (e.g. FRED lag=1 + another lag=2 + a no-vintage source) as predictors. Mutually exclusive with features.

  • horizon (int) – Forecast horizon h in calendar steps; features at t pair 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 returns DatetimeIndex (the original behaviour). With blocks, each block keeps its own calendar and is aligned to the returns calendar by its own lag-aware FeatureBlock.asof(). With neither, the view is returns-only: no feature blocks, so every X is shaped (T x 0) and aligned yields 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: X at t paired with (t, t+h].

between(start, end)

Test-fold view: data truncated to <= end, calendar restricted to (start, end].

features_asof(t)

Feature vector known as of t, concatenated lag-aware across all blocks.

features_frame()

The (date x feature) features block over the calendar (lag-aware; raw eject).

returns_frame()

The (date x asset) returns block over the calendar (raw eject).

tail(k)

Restrict the calendar to its last k observations (rolling window; data unchanged).

target_asof(t[, horizon])

Return realized over (t, t+h] per asset, or nan if not yet realized in-view.

window(end)

View restricted to information available up to end (data and calendar both <= end).

Attributes

assets

Asset (returns-column) names.

calendar

Rebalancing / observation timestamps (the prediction calendar).

feature_names

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 by end.

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 uses features_asof(t) (data <= t). Realized P&L is computed by the engine from the full view, so the model never sees future returns.

property assets: list[str]#

Asset (returns-column) names.

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 k observations (rolling window; data unchanged).

returns_frame() DataFrame[source]#

The (date x asset) returns block over the calendar (raw eject).

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, or nan if not yet realized in-view.

Compounds simple returns over the h data periods strictly after t.

aligned(horizon: int | None = None) tuple[DatetimeIndex, NDArray[float64], NDArray[float64]][source]#

Supervised (dates, X, Y) over the calendar: X at t paired 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 date t satisfies t + h <= end (the horizon purge that kills the contemporaneous leak). X rows are lag-aware and concatenated across feature blocks.