quantlab.portfolio.base.InputDeclaration#

class quantlab.portfolio.base.InputDeclaration(lookback_bars=0, history_bars=None, factors=(), risk_model=None)[source]#

Bases: object

What a rule reads at each bar besides its predictions and holdings: its decision inputs, declared.

One value a rule (and a covariance estimator) gives through declared_inputs(); DecisionInputs builds every context from it alone. A rule holding parts merges their declarations (merged).

Attributes:
lookback_barsint

Bars of one-bar returns each context’s returns window holds.

history_barsint

Raw valuation prices up to and including a bar that its context is built from: the window’s prices are forward-filled within these alone, and a symbol without a real price in them has NaN staleness, so a decision does not depend on where the caller’s history starts. DecisionInputs reads the history_bars - 1 bars before a panel as its warm-up. At least lookback_bars + 1, the default (the window’s first return needs the price before it).

factorstuple of Factor

The Factor panels whose values at each bar the rule reads from context.factors; each is computed over the window with its own warmup_bars. Any Factor qualifies (KunQuant, Polars, a plain one such as a one-hot industry exposure).

risk_modelFactorRiskModel or None

The factor risk model whose exposures and estimate row at each bar the rule reads from context.risk_exposures and context.risk_estimate, taken from the model (FactorRiskModel.exposures, its estimate store), never computed as a factor.

Raises:
ValueError

If lookback_bars is negative or history_bars below lookback_bars + 1.

Examples

>>> InputDeclaration(lookback_bars=60).history_bars
61
>>> InputDeclaration(lookback_bars=60, history_bars=66).merged(
...     InputDeclaration(lookback_bars=20)
... ).history_bars
66
merged(other)[source]#

Return the declaration of what either reads.

The longer window and price history, the factors of both (one declared by both is listed once), and the risk model either names.

Raises:
ValueError

If both name a risk model and they differ.

Examples

>>> InputDeclaration(lookback_bars=5).merged(InputDeclaration(lookback_bars=9)).lookback_bars
9