factor_agent.session#
Session columns: intraday graphs computed on intraday bars, one value per stock and session.
SessionFactor is a quantlab KunQuant factor over an intraday dataset
(one-minute trade bars cut by session). Each of its graphs ends in a session
aggregation (factor_agent.aggregations) and is one output; at a
session’s last bar the output holds the aggregation of that session’s bars
and every other bar is NaN, so resampled to "1d" with "last" the
factor is one value per stock and session:
daily = SessionFactor(config).resample("1d", "last").compute(start, end)
KunQuant has no notion of a session, so the factor adds the session inputs
before the graph runs, as quantlab’s IntradayStats computes them
(quantlab.factor.predefined.intraday.session_inputs): a bar’s position in
its session (session_position, 0 for the first bar), the bars left to the
session’s last (session_bars_left, 0 for the last) and the last trade
price at or before the bar within the session (last_price, from the
bars’ close). A graph reads them as it reads the bars’ own columns.
Nothing assumes a number of bars per session: a session is the bars the
dataset cuts into one "1d" bar (resample_labels).
Each aggregation is expanded into KunQuant accumulators: running values
that restart at each session’s first bar and skip a missing value, sums
(the count, the sum, sums of powers) or folds (the first, last, least and
greatest value present). Moments are sums of the values less the session’s
first value, as quantlab’s session statistics compute them, so that in
float32 a price’s deviations are not lost to its level. An accumulator is
named after what it accumulates, the hash of what the aggregation’s input
subgraph computes (computation_hashes; of each input’s, joined, for
two) and the kind
(<hash>_count, <hash>_first, <hash>_shifted_sumsq…): one
function builds one accumulator per name, and KunQuant’s expression folding
merges two accumulators only when their names are the same, so two
aggregations of one subgraph in one function, in one graph or in two, share
their sums (SessionMean(x) and SessionStd(x): the count, the first
value and the shifted sums of x and of its square).
All the graphs of one factor are one KunQuant function, and an operator
that computes what an earlier one computes (in the same graph or another:
the same computation_hashes) is that operator, so a subtree two
candidates share is computed once, and a graph’s values are the same
whichever graphs it is computed with.
SessionColumns is the provider of session columns to a daily factor
(factor_agent.derived): it computes the intraday graphs of a stage split
(factor_agent.gate.stages) with SessionFactor, in chunks of sessions,
and puts each session’s value on its day of the daily panel.
Classes
The session columns of intraday graphs, filled for a daily factor from an intraday dataset. |
|
Intraday graphs, each ending in a session aggregation, on an intraday dataset; see the module docstring. |
Functions
One KunQuant function with an output per graph, named after it: its value at each session's last bar. |