Parsing¶
qex(expression) reads an expression and returns a Signal: the expression's tree, ready to evaluate. Nothing is
computed yet.
The expression is checked as it is read: an unknown operator, a misplaced label, a negative delay and the other
mistakes listed in Syntax raise ValueError or TypeError with a message,
before any data is touched.
Multi-line expressions are ordinary Python strings:
# comments run to the end of their line, so a multi-line expression can be commented line by line
(Syntax).
alpha() is the same function under its older name, and QexParser is the class behind both.
API reference¶
qex ¶
Parse and return signal from string expression.
This is the primary entry point for qex expressions.
Example
signal = qex("rank(-returns(20) / volatility(60))")
QexParser ¶
Parse string expressions into Signal objects.
Supports variable bindings with let...in syntax: let s = returns(20) in rank(delta(s, 20)) * s
Multiple bindings can be comma-separated
let mom = returns(20), vol = volatility(60) in rank(mom / vol) * sign(mom)
Later bindings can reference earlier ones
let mom = returns(20), sharpe = mom / volatility(60) in rank(sharpe) * sign(mom)
parse ¶
Parse string expression into Signal tree.
Handles let...in syntax for variable bindings before parsing.