Skip to content

Expression Syntax


How to use the expression engine in Everysk

The expression engine is one of the powerful features within Everysk that enables fast development with little to no code required. It serves as an internal language capable of performing a wide array of customized tasks including mathematical equations, compliance checks, blending benchmarks, and data exploration. This guide will walk you through the syntax and various use cases of the expression engine within Everysk. Please see the pdf linked below for reference.


Robots That Use the Expression Engine

The expression engine's versatility is showcased through a variety of use cases, empowering you to perform complex calculations and logical operations within Everysk. Here are some prominent digital robots that utilize the expression language:

Datastore Explorer Robot

  • Filter and manipulate data from datastores using unique expressions in the Datastore Explorer.

Example 1: Return the symbol for each position in a portfolio.

The Datastore Explorer always references one or more datastores and uses the expression engine to define properties that it outputs in a report or workflow. A simple function, single_text(), is used to cast a value from the datastore as a text value with a unique value. This type of property is often used to label data returned from a datastore exploration. Examples include symbols, labels, or custom tags.

The blue colored portions of the syntax are functions and the green are columns in the datastore. In order to find the available columns in your specific use case, review the available keys in the datastore you are working with. This can be done via API or by entering "Edit" mode using the toggle at the bottom of the datastore viewer in the UI.

Example 2: Scale daily Value at Risk (VaR) to monthly VaR and calculate it as a percentage of the portfolio's net liquidating value (NLV).

This expression is referencing a datastore that contains portfolio data and calculations including VaR. The expression engine understands standard math functions like sqrt() for applying the square root to the monthly scalar. sum() is used to aggregate the security-level contributional VaR numbers from every position in the datastore and the port_attribute() function is used to select special variables like date and NLV that are typically a single value across every row in a datastore.

Example 3: Sum the exposure of two specific asset classes.

The filter () function is the standard way the expression engine selects a subset of data from a datastore. Here, the filter() function is nested inside a math function, sum(), in order to sum specific positions. The in() function is used as the filter condition to specify two explicit values of a custom field, 'sec_attribute_instrument_type', so any position that matches the values will have their market values summed.

Compliance Rule Solver Robot

  • Evaluate compliance rules, such as checking if a calculated value meets a specific condition.

Example: Check if the sum of market value for two instrument types is greater than or equal to 70% of the portfolio's Net Liquid Value (NLV).

Filter: 'instrument_type' == "Bond" or 'instrument_subtype' == "Sovereign"

Expression: sum('sec_attribute_market_value')/port_attribute('port_nlv')

The Compliance Solver references a datastore that contains itemized rules, each with their own filters and mathematical expressions. Logical expressions such as ==, "or" and >= can be used to define filter conditions. The expression, criteria, and limit are specified in separate fields. Note, single quotes are used for variables and double quotes are used for fixed values.

Expression Solver Robot

  • Perform arithmetic operations using up-stream variables from a workflow and user specified calculations.

Example: Calculate a daily two sigma shock value for an index.

Certain robots such as the Expression Solver allow users to define variables in the robot itself rather than referencing fields in a datastore. In this example, the annualized standard deviation is retrieved from a previous robot, defined as a variable, 'std' and used in the formula.

Time Series Operator Robot

  • Compute statistics on time series data, such as averages, z-scores, total returns, volatilities, scaling and many other measures

Example: Calculate the average monthly return of a portfolio for the last day of each month.

The Time Series Operator works off a series of date-value tuples, so in this example 'return' represents a history of cumulative month-to-date returns stored with their corresponding dates. In this case, a date function, is_last_day_of_month(), is used as the filter condition.

Custom Benchmark Generator Robot

  • Design and calculate custom benchmarks by crafting expressions that combine and weight different market indices or data sources.

Example: Create a blended benchmark by applying a 70/30 weighting to the ACWI and the AGG indices.

Here, returns history for two indices are fed in as inputs to create a blended benchmark.


Syntax and Functions

The expression engine's power comes from its ability to interpret expressions based on intuitive grammatical rules and a library of different functions. Expressions can encompass variables, operators, function calls, and literal values. See below for examples of the most common elements of the expression syntax:

Expression Example
Absence of Value None
Integer 7
Float 7.7
String "Everysk"
Boolean True or False
Variable my_var or 'my_other_var'
Array [None, 7, 7.7, "Everysk", True, my_var]
Function my_function(arg_1, arg_2, …, arg_n)
Not not my_var
Negation -my_var
Multiplication my_var * my_other_var
Division my_var / my_other_var
Addition my_var + my_other_var
Subtraction my_var - my_other_var
Within "Cash" in ["Equity", "Future", "Cash"]
Not within my_var not in my_other_var
Equal my_var == "Everysk"
Not Equal my_var != None
Less Than my_var < my_other_var
Greater Than my_var > my_other_var
Less or Equal my_var <= my_other_var
Greater or Equal my_var >= my_other_var
Logical Or my_var or my_other_var
Logical And my_var and my_other_var
Conditional value1 if expr_1 else value2 if expr_2 else default

See the Function Reference pages in the sidebar for the full function library, organized by category:

  • General — value retrieval, formatting, conditional logic
  • String — casting, searching, manipulation, case
  • Math — aggregation, statistics, rounding, risk metrics
  • Date — component extraction, period boundaries, format conversion, date arithmetic
  • List — slicing, filtering, mapping, transformation

Conclusion

The expression engine in Everysk offers an exceptional toolset for performing calculations, logic checks, and data manipulations for professional investors. Its flexible library and intuitive syntax enable you to craft complex expressions to customize your workflows.