factor_agent.gate.stages#

The stage split: a candidate’s recorded graph as the graphs it runs as, and the stage rules it breaks.

A candidate of an intraday family is one graph in two stages. Every session aggregation (factor_agent.aggregations) and what it depends on is its intraday stage, computed on each session’s intraday bars; everything above the aggregations is its daily stage, computed on one value per stock and day. split gives the daily graph, each aggregation subtree replaced by an Input of its session column, named after what the subtree computes (session_column, computation_hashes), and the intraday graphs by those names, each ending in its aggregation: two aggregations that compute the same values, in one graph or in two, are one column, and two that compute different values are two, even when their canonical hashes are one (x + 1e8 - 1e8 is x to the Gate but not in float32). The daily family’s bar mask, which quantlab’s NaN-preserving stand-ins add to what they compute, is left out of the intraday stage: a bar there is an intraday bar. A graph without an aggregation or an intraday field is its own daily graph.

Every window of an intraday graph stays within the session: each time-series operator outside a loop body, and each reduction of a loop, is wrapped in WithinSession by the bars it reaches back, its inputs’ windows included, so it is missing on a session’s first bars until it fits and never reads the session before. A session column is named after the intraday graph so rewritten, what runs. Cross-sectional operators rank across all the symbols of each bar.

The rules split checks, each broken one a reason with a hint, how to write it instead, for the proposer:

  • an intraday field reaches the daily stage only through an aggregation;

  • the intraday stage reads no daily field;

  • an aggregation’s inputs are intraday: no aggregation of a daily value (inputs reading no intraday field), none nested in another;

  • each operator is used only in the stages its operator-file entry names (OpSpec.stages);

  • a window or a lag (window_kind) is one of its stage’s set: in the intraday stage the intraday family’s windows and lags (Vocabulary.intraday_windows, intraday_lags), lags chained included; in the daily stage the operator file’s set of the attribute.

The Gate, the Evaluator and the export all split a graph here; nothing else knows how its stages are found.

Classes

Staged

A graph split into its stages; see the module docstring.

Functions

is_aggregation

Whether node of graph is a session aggregation.

is_staged

Whether graph runs in two stages: it holds a session aggregation or reads an intraday field.

session_column

The name of the session column of an aggregation subtree, from the hash of what it computes.

split

Return graph's daily and intraday graphs and the stage rules it breaks; see the module docstring.

window_kind

"lag" for an attribute of op in the lag set, "window" for another named window, else None.