User Defined Analytics

Declarative stateful math expressions evaluated in real-time


The analytics processor provides a rich set of features that enable developers to define and execute analytics. This feature is idea for executing an event based analytic expression using attributes present within the event, linked reference data and passed variables.

Currently only Javascript and Python expressions are supported

Key features

  • Expression evaluation and execution

  • Scripting and function execution

  • Stateful analytics

  • Analytic result memory

Processor architecture

The key analytic processor objective is to provide analytic deployment flexibility for the developer. The ambition is to enable a quick test, learn and refine cycle that reduces time to production deployment.

Execution models

  • Expression only

  • Script and expression

See User Defined Scripts documentation for the script based execution models.

Expression only

When you only want to execute an expression that can be defined as a mathematical formula use this method to execute independent event based calculations. provide the expression along with the required core attributes, see below.

  expression: (bid - ask) / scalar
  assign to: new_event_variable

Expression and State

This example demonstrates how you would use provided constants for a calculation. This same method can be used to prime a calculation with a starting value for the initial calculation and then being it replaced with updated values by using the same assign to variable.

  expression: "(ask + (bid - ask) / 2.0) / scaled_price"
  assign to: scaled_price
      scaled_price : 120.21
      assign to: scaled_price
      memory capacity: 1

See Stateful variables for further documentation.

Expression and script

Use this option when you have pre-existing scripts which you want to leverage within a stream processing context.

  script: ./scripts/js/preExistingFunctions.js
  expression: bid - squareRoot(`${ask}` / `${bid}`)
  assign to: new_event_variable

Javascript function

export function squareRoot(num) {
    if (num < 0) return NaN;
    return Math.sqrt(num);

The above example would apply the bid and ask event attributes to the expression. Note the current implementation requires the script to be provided using the js extension due to the way the above expression is defined.


Variables and the event are passed in to the execution context per event, including stateful variables, see below. This example demonstrates how you would use a constant as a scaling factor for a calculation.

  expression: (highest_price - lowest_price) / scaling_factor
  assign to: scaled_price
      scaling_factor : 120.21 

Variables are provided as a map of key and numerical values.

Stateful variables

Stateful variables provide a key function whereby the previous value/s can be used within the current calculation context.

  expression: (ask + (bid - ask) / 2.0) / Math.avg(scaled_price)
  assign to: scaled_price
      scaled_price : 100.00
      assign to: scaled_price
      memory capacity: 25  

The above example primes the first calculation with a starting value for the initial calculation and thereafter replaced with the computed values from the stateful memory. This is achieved using the same assign to variable set within the variables section.

DSL Attributes

The following section details the DSL attributes supported.

Core Attributes

The follow attributes are used for expression and scripting.

AttributeDescriptionData TypeRequired


Language runtime to use to execute required execution definitions. Currently Javascript (js) and Python (python) are supported

String Default: js

assign to

Assignment variable for the evaluated expression result

String Default: result


Map of constants and seed values for the expression to use. This is an optional variable.

Map<String, Number>


Store previous computed values for next computation cycle

assignment datatype

Data type to cast too for the assignment variable. See scripting supported data types section

DataType Default: Double

Execution Attributes

These attributes define what is need to execute analytical functions over a stream events.

AttributeDescriptionData Type


Math expression without an assignment variable. Required if method has not been provided.



Path of the script to loaded within the Joule processing context


Stateful Attributes

Store previous computed values for next computation cycle. Honours the groupby definition. The previous computed value can be used on the next calculation.

AttributeDescriptionData TypeRequired

assign to

Assignment variable for the


memory capacity

Number of rolling elements to store within a FIFO array

Integer Default: 10

attach memory

Attach a copy of the array contents to the computed event

Boolean Default: false

Last updated