factor_agent.gate.vocabulary#

The Vocabulary: the fields, operators and parameter values a campaign’s candidates may write with.

It is built from files only (Vocabulary.load): one field file per input family and one operator file, named by the campaign config. The framework holds no field, column or operator of its own; it keeps the rules a file picks from (the dimension rules of _dimension, the input kinds, the syntax of _checks), the Input a graph reads a column with, and the Builder of window loops.

A field file lists its family’s fields. A field reads a column of the price dataset, in a unit that is a product of powers of dollars and shares, or is derived: a formula over the family’s earlier fields, checked under the syntax rules of candidate code and built with the operators. A family with bar: true makes a missing value in any of its columns a missing bar: candidate code runs inside quantlab’s missing_bars_only over those columns, so the NaN-preserving stand-ins of quantlab.factor.kunquant_nan keep such a bar NaN.

A field file marked intraday is the campaign’s intraday family: its fields read columns of the intraday dataset (the bars of each session, the session inputs factor_agent.session adds among them), not of the price dataset, and it gives the window lengths and the lags, in bars, its stage may use (intraday: {windows: [...], lags: [...]}; without lags, the operator file’s lag set). A campaign opens one at most. Candidate code reaches the daily stage from its fields only through a session aggregation (factor_agent.gate.stages).

A family may declare a period lag (period_lag): the column pattern of its lags ({column} and {k} fill it, "{column}__q{k}" as quantlab’s FundamentalAlpha names its report lags), the allowed k and what a period is: the dataset column holding the period end of the report a bar shows (key), the spacing of consecutive periods in days and the tolerance on it, and the most bars a period spans. Candidate code then calls PeriodLag(x, k) on a field of the family that reads a column; it reads the lag column of the field, which factor_agent.period_lag computes from the field’s column and the key when the factor is computed. The lags of a field count as the field itself, toward the field limit and in dimensions.

The operator file lists each operator’s class (a KunQuant OpBase subclass, what a graph records), the callable candidate code calls under its name (the class, or a stand-in such as kunquant_nan.Max), its signature, argument and parameter kinds, dimension rule and prompt description, plus the parameter value sets, the fixes (each a regular expression an operator library’s refusal matches, with how to write it instead) and, in the repository’s example file, every other operator class with why it is excluded. A class or a callable must come from KunQuant, quantlab.factor or a module the config lists in operator_modules: the path is checked before it is imported, no attribute hop may go through another module, and the object must be defined under one of them. Each operator names the stages it may be used in (stages): a list of intraday and daily, daily alone when it names none; a session aggregation (factor_agent.aggregations) is its own kind, [aggregation]. An operator of unbounded memory (a KunQuant state without a window, as ExpMovingAvg’s) may not name intraday.

load reports every problem of the files at once (VocabularyError). The sandbox rebuilds the same vocabulary from sources, the files’ text.

Classes

Field

One field: its name, family, the column it reads or the formula it is derived by, and its description.

OpSpec

One registered operator; see the module docstring.

PeriodLag

A family's declared period lag; see the module docstring.

Vocabulary

What candidates may write with; build it with load, or from_sources in the sandbox.

Functions

resolve

Import the object at path: the longest importable module prefix, then attributes.

resolve_classes

The operator class at each path, by name, as Vocabulary.class_paths gave them.