quantlab.portfolio.base.InputDeclaration#
- class quantlab.portfolio.base.InputDeclaration(lookback_bars=0, history_bars=None, factors=(), risk_model=None)[source]#
Bases:
objectWhat 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();DecisionInputsbuilds every context from it alone. A rule holding parts merges their declarations (merged).- Attributes:
- lookback_barsint
Bars of one-bar returns each context’s
returnswindow 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.
DecisionInputsreads thehistory_bars - 1bars before a panel as its warm-up. At leastlookback_bars + 1, the default (the window’s first return needs the price before it).- factorstuple of Factor
The
Factorpanels whose values at each bar the rule reads fromcontext.factors; each is computed over the window with its ownwarmup_bars. AnyFactorqualifies (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_exposuresandcontext.risk_estimate, taken from the model (FactorRiskModel.exposures, itsestimatestore), never computed as a factor.
- Raises:
- ValueError
If
lookback_barsis negative orhistory_barsbelowlookback_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