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, return_type: 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. Simple returns by default — passreturn_type="log"to declare log-return inputs, which are converted to simple returns once at ingestion (seereturn_typebelow).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()). When given,risk_freeis declared in the same convention asreturns(return_type); a"log"rf is converted to simple alongside the returns before the excess subtraction.return_type – Convention of the input
returns(andrisk_free):"simple"(default) or"log". Log input is a declared input convention only — declared log returns are converted to simple returns once at ingestion viaexpm1and the conversion is stamped intoprovenance. Everything downstream (targets, strategy P&L, evaluators) then operates on a single simple-return representation, so cross-sectional portfolio arithmetic (weighted sums) and multi-period compounding (prod(1 + r) - 1) are always correct.
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, return_type: 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.
Ingestion provenance (e.g. a log→simple return conversion); empty for simple inputs.
- property calendar: DatetimeIndex#
Rebalancing / observation timestamps (the prediction calendar).
- property provenance: dict[str, str]#
Ingestion provenance (e.g. a log→simple return conversion); empty for simple inputs.
Merge into a backtest
config(config={**view.provenance, ...}) to make the return convention hash-visible in every result row’sconfig_hash.
- 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.