Conditional Operators

AMPS contains support for a ternary conditional IF operator which allows for a Boolean condition to be evaluated to true or false, and will return one of the two parameters. The general format of the IF statement is:

IF (BOOLEAN_CONDITIONAL, VALUE_TRUE, VALUE_FALSE)

In this example, the BOOLEAN_CONDITIONAL will be evaluated, and if the result is true, the VALUE_TRUE value will be returned otherwise the VALUE_FALSE will be returned.

Function or OperatorParametersDescription

IF

Conditional expression

Value to return if conditional expression is true

Value to return if conditional expression is false

Evaluate the conditional expression and return one of the two input values based on the results of the expression.

The AMPS expression engine can conditionally evaluate the terms provided to the IF statement in version 5.3.4 and greater.

In previous versions of AMPS, all expressions provided to the IF statement were fully evaluated before the IF statement was evaluated.

For example:

SUM( IF(( (/FIXML/Order/OrdQty/@Qty > 500) AND
          (/FIXML/Order/Instrmt/@Sym ='MSFT')), 1, 0 ))

The above example returns a count of the total number of orders that have been placed where the symbol is MSFT and the order contains a quantity more than 500.

The IF operator can also be used to evaluate results to determine if results are NULL or NaN. This is useful for calculating aggregates where some values may be NULL or NaN. The NULL and NaN values are discussed in more detail in the AMPS Data Types section.

For example:

SUM(/FIXML/Order/Instrmt/@Qty * IF(
    /FIXML/Order/Instmt/@Price IS NOT NULL, 1, 0))

Last updated

Copyright 2013-2024 60East Technologies, Inc.