Investment Studio > Expressions > Functions > Matrix > EXTREMA

float array[*][3] extrema(float array[*][*] table, integer column, boolean include_end_points = FALSE)

Returns a three-column array listing all local extrema in the specified column of table.

If the value in column column, row n of the table array is an extremum, the result table will contain a row with the following entries:

Column # Content
1 The value in column 1, row n of the table array.
2
-1 if the value in column column, row n of the table array is a local minimum (i.e. it's lower than both its neighbours, or if it's an end point, than its only neighbour)
0 if the value in column column, row n of the table array is a local plateau (i.e. it's equal to at least one of its neighbours)
+1 if the value in column column, row n of the table array is a local maximum (i.e. it's higher than both its neighbours, or if it's an end point, than its only neighbour)
3 The value in column column, row n of the table array.

If include_end_points is TRUE, the first and last row of the table array are included in the result. By default, include_end_points is FALSE.

If no extrema are found, the result is an error (#VALUE!).

Examples

Given the array

_table = {{-1, 2, 3}, {-4, 5, 6}, {-7, 8, 7}, {-6, 5, 7}, {-3, 2, 1}}

the expression

=extrema(array(_table), 2)

returns {{-7, 1, 8}}. This tells us that, excluding the end points, column 2 of _table (values 2, 5, 8, 5, 2) contains one extremum: a local maximum (hence the 1 in the result) with value 8. It also tells us that in the table row containing this maximum, the value of column 1 is -7.

The expression

=extrema(array(_table), 1)

returns {{-7, -1, -7}}: again excluding the end points, column 1 of _table (values -1, -4, -7, -6, -3) contains a local minimum (hence the -1 in the result) with value -7.

The expression

=extrema(array(_table), 3)

returns {{-7, 0, 7}, {-6, 0, 7}}: still excluding the end points, column 3 of _table (values 3, 6, 7, 7, 1) contains two plateau points (hence the 0s in the result) with value 7, in the rows containing values -7 and -6 in column 1.

See also crosses, msort, sync.