Syntax
Syntax
Section titled “Syntax”QuantFlow is not Python. It uses a deliberately small syntax that the host can validate and execute with a restricted function registry.
Expressions
Section titled “Expressions”A single expression is an implicit return:
math.abs($.price - $.reference)Expressions support null, true, false, decimal numbers, quoted strings,
object paths, registered function calls, and parentheses.
| Operators | Meaning |
|---|---|
!, unary - |
Logical and numeric negation |
*, / |
Multiplication and division |
+, - |
Addition and subtraction |
>, >=, <, <= |
Ordering |
==, != |
Equality |
&&, ` |
Runtime numbers use decimal arithmetic. The compiler does not silently convert between strings, booleans, and numbers for arithmetic.
Read input values
Section titled “Read input values”Use $. to read from the value supplied by the host. Dotted paths traverse
objects, and zero-based numeric path segments traverse arrays:
symbol = $.run_input.symbollast_price = $.arguments.data.0.lastreturn last_priceIf a path cannot be resolved, execution reports the requested path, the missing segment, and the deepest path that was resolved.
Assignments and programs
Section titled “Assignments and programs”A standard expression program supports assignments, dotted object-path
assignments, indented if/else blocks, for loops over arrays, conditional
expressions, and return. Every expression program must return a value.
Strategy bot programs use a host-specific effect form with a fn main() entry
point and annotated event handlers; see Bot strategy programs.
price = $.pricerisk = math.abs(price - $.reference)
if risk > $.max_risk: return None
return riskUse for name in expression: to visit each item in an array. The loop body must
be indented with spaces; tabs are not supported. The expression is evaluated
once before iteration, and a non-array value produces a runtime error:
total = 0for position in $.positions: total = total + position.notionalreturn totalAll loops in one Program execution share a limit of 10,000 total iterations, including iterations in nested loops. A loop over an array with more than 10,000 items fails immediately, and nested loops can reach the shared limit even when each individual array is smaller. Exceeding the limit produces a runtime error.
The loop variable is temporarily bound for the loop. If a variable with the
same name already existed, its previous value is restored afterward; otherwise
the loop variable is removed. Other assignments made in the loop body remain
in the Program’s shared variable scope after the loop. A return in the body
returns from the Program.
A variable can refer to the current input with $. Dotted assignments update
the local program value:
value = $value.signal.direction = $.run_input.directionreturn valueConditional expressions use Python-like order:
target = requested if requested != "auto" else default_targetreturn targetFunction names can include a namespace, but calls are not object methods. Use
str.upper(value), not value.upper().
Return an explicit error
Section titled “Return an explicit error”Use return Err("message") to stop execution with an explicit error:
if $.arguments.quantity <= 0: return Err("quantity must be positive")
return $.arguments.quantityErr takes exactly one string. The Rust caller receives a
QuantflowError::Raised and can propagate it with ? or handle it.
Deliberate limits
Section titled “Deliberate limits”The standard expression-program form does not support imports, while loops,
classes, function definitions, or arbitrary code execution. for loops are
limited to arrays and the per-execution iteration budget described above.
Programs can call only functions registered by their host. Hosts may provide
different inputs and additional functions, so a program is portable only when
its input and registered-function contract is portable. The bot host’s
quantflow_bot_v1 effect form adds its documented entry point and event
handlers; see Bot strategy programs.
See Built-in functions for functions registered by the standard QuantFlow runtime.