quantlab.portfolio.decision_inputs#

The decision inputs of a portfolio construction rule, assembled in one place.

A rule decides one bar from its decision inputs: the predictions at the bar, which symbols are tradable there, the recent valuation prices (as a return window and each symbol’s staleness), the values of the factors it declares, the exposures of the factor risk model it declares, and the weights currently held. DecisionInputs assembles them from a price dataset for the research backtester and for an event-driven executor alike, so a rule holds no assembly code and only decides (PortfolioConstructor.construct / decide).

Each bar reads a bounded window: the last history_bars raw valuation prices up to and including it, a number the rule declares. What a rule reads is one value, its InputDeclaration (declared_inputs()), asked once. The return window is forward-filled within it and a symbol’s staleness counted within it, so a decision depends only on what is known at its bar, never on where a longer price history starts.

The weights held are not a decision input. weights replays them through the Execution module (quantlab.execution.rules) with the run’s delisting marks; context takes them from the caller, an executor’s own account. The rebalance schedule lives here as well, once: every rebalance_periods bars of the dataset’s calendar from the anchor (the first bar of the prediction panel a run decided on), before end. rebalances(t) asks it for one bar and weights for a panel, whose last bar it never decides. weights records, beside the weights, which bars were scheduled and which of them the rule decided (the rebalance record): a scheduled bar it did not decide is a held bar. Every reader of a run’s rebalances (turnover, win rates, attribution, the report) takes them from that record.

panel gives a block of decision bars’ inputs at once (a DecisionPanel: their predictions, tradability, declared factors and a declared risk model’s exposures and estimate rows, read as the per-bar context reads them; all but the predictions once over many blocks with panel_reads) for the approximate backtest (quantlab.backtest.approximate); scheduled names the scheduled bars of many timestamps at once.

DecisionInputs.from_run rebuilds the inputs of a recorded backtest run, read through quantlab.runs.backtest_run.BacktestRun.

A replay that builds a context per bar can read its window once: inside preloaded(start, end) every context of a bar in the window is sliced from what was read there, and equals the one read bar by bar. A live run, deciding one new bar at a time, does not preload.

A factor risk model’s exposures are taken from the model (FactorRiskModel.exposures: its exposures factor’s store under exposure_data_strategy="read", computed under "cal"), the source its stores, factor attribution and bias statistics read, never computed as a declared factor. Its estimate store’s rows (the factor covariance and specific risks forecast at each bar) are read here as well, beside the exposures, so a covariance estimator turns the context into the model’s forecast and reads no store itself.

This module imports the portfolio and data base classes, the Execution module and the backtest-run reader, never the backtest, model, factor or label layers.

Classes

DecisionInputs

Assemble a rule's decision inputs from a price dataset and decide with it.

PanelReads

What DecisionInputs.panel reads besides the predictions and prices, for a range of bars.