Feature Engineering
q.feature defines reproducible columns intended for model training, batch materialization, and equivalent online computation. It does not own every calculation that might eventually become a feature.
Use q.indicator for single-instrument market measurements, q.cross_section for cross-sectional values, and q.preprocess for transformations fitted on training data.
Definitions
sma_20 = q.feature.Feature(
name="sma_20",
version="1",
function=q.indicator.sma,
inputs={"series": "close"},
params={"window": 20},
entity_keys=("symbol",),
timestamp="datetime",
lookback=20,
available_at="bar_close",
)
daily = q.feature.FeatureSet([sma_20], name="daily_prices", version="1")A feature definition maps callable arguments to source columns. It carries the metadata needed to reproduce and audit the output but does not fetch data or schedule execution.
Compute and materialize
frame = q.feature.compute(daily, source)
q.feature.materialize(daily, source, duckdb_connection, table="daily_features")Computation is isolated by entity_keys, retains keys and timestamps, requires ordered history, and never silently sorts the source. Materialization accepts a sink with write(data, table=...), including qrt’s DuckDB connection.
Generic operations
q.feature.ops provides column-building primitives that do not have market semantics or fitted state:
lags = q.feature.ops.lags(prices["close"], [1, 5, 21])
rank = q.feature.ops.pct_rank(prices["close"], window=60)Calling an operation directly does not register or persist a feature. Wrap a scalar operation in Feature when it needs a stable model-input identity.