Skip to main content

List Functions

Functions that take a list of values as input

abs

Transforms all values of the input variable to absolute (positive) values.

Works with:

Syntax

abs(var)

Examples

Timeseries
at = TimeSeries("DAILY")
at.add("2020-11-01", 12.5)
at.add("2020-11-02", -12.75)
at.add("2020-11-03", 12.9)
at.add("2020-11-04", -11.5)
at.add("2020-11-05", 11.9)
absat = abs(at)
print absat.values
[
{"2020-11-01": 12.5},
{"2020-11-02": 12.75},
{"2020-11-03": 12.9},
{"2020-11-04": 11.5},
{"2020-11-05": 11.9}
]
List
testarray = [-1,6,0,-2]
print abs(testarray)
Curve
expiry = ExpiryCalendar(BusinessCalendar())
expiry.addRule("go back 1 day using calendar")
ondate = CurveDate(Date("2020-12-01"), expiry)
c1 = Curve(ondate)
c1.add(Contract(ondate, "2021M01", 12.5))
c1.add(Contract(ondate, "2021M02", -12.75))
c1.add(Contract(ondate, "2021M03", 13.0))
print abs(c1)
Scalar
print abs(-2)
2

acos

Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.

Special case: If the argument is NaN or its absolute value is greater than 1, then the result is NaN.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

Syntax

acos(var)

asin

Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2.

Special cases:

  • If the argument is NaN or its absolute value is greater than 1, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

Works with:

Syntax

asin(var)

atan

Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2.

Special cases:

  • If the argument is NaN or its absolute value is greater than 1, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

atan(var)

atan2

Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi.

Special cases:

  • If either argument is NaN, then the result is NaN.
  • If the first argument is positive zero and the second argument is positive, or the first argument is positive and finite and the second argument is positive infinity, then the result is positive zero.
  • If the first argument is negative zero and the second argument is positive, or the first argument is negative and finite and the second argument is positive infinity, then the result is negative zero.
  • If the first argument is positive zero and the second argument is negative, or the first argument is positive and finite and the second argument is negative infinity, then the result is the double value closest to pi.
  • If the first argument is negative zero and the second argument is negative, or the first argument is negative and finite and the second argument is negative infinity, then the result is the double value closest to -pi.
  • If the first argument is positive and the second argument is positive zero or negative zero, or the first argument is positive infinity and the second argument is finite, then the result is the double value closest to pi/2.
  • If the first argument is negative and the second argument is positive zero or negative zero, or the first argument is negative infinity and the second argument is finite, then the result is the double value closest to -pi/2.
  • If both arguments are positive infinity, then the result is the double value closest to pi/4.
  • If the first argument is positive infinity and the second argument is negative infinity, then the result is the double value closest to 3*pi/4.
  • If the first argument is negative infinity and the second argument is positive infinity, then the result is the double value closest to -pi/4.
  • If both arguments are negative infinity, then the result is the double value closest to -3*pi/4.

The computed result must be within 2 ulps of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

atan2(ordinate, abscissa)

cbrt

Returns the cube root of a double value. For positive finite x, cbrt(-x) == -cbrt(x); that is, the cube root of a negative value is the negative of the cube root of that value's magnitude.

Special cases:

  • If the argument is NaN, then the result is NaN.
  • If the argument is infinite, then the result is an infinity with the same sign as the argument.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

cbrt(var)

cos

Returns the trigonometric cosine of an angle.

Special cases:

  • If the argument is NaN or an infinity, then the result is NaN.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

cos(var)

cosh

Returns the hyperbolic cosine of a double value. The hyperbolic cosine of x is defined to be (ex + e-x)/2 where e is Euler's number.

Special cases:

  • If the argument is NaN, then the result is NaN.
  • If the argument is infinite, then the result is positive infinity.
  • If the argument is zero, then the result is 1.0.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

cosh(var)

cave

Returns the cumulative average of the values of a List or Timeseries

Syntax

cave(list)
cave(timeseries)
cave(timeseries, calendar)

If you supply a Timeseries and a Calendar - the output will be cumulative average of the values aligned to the output calendar

Example

input = TimeSeries("DAILY")
input.add("2020-10-30", 10)
input.add("2020-10-31", 10)
input.add("2020-11-01", 11)
input.add("2020-11-02", 12)
input.add("2020-11-03", 12.9)
input.add("2020-11-04", 11.5)
input.add("2020-11-05", 11.9)
v = cave(input)
print v.values

v = cave(input, MonthlyCalendar())
print v.values

testarray = [-1,6,0,-2]
print cave(testarray)
[
2020-10-30 10.0
2020-10-31 10.0
2020-11-01 10.333333
2020-11-02 10.750000
2020-11-03 11.180000
2020-11-04 11.233333
2020-11-05 11.328571
]
[
2020-10-01 10
2020-11-01 11.328571
]
[
-1.0
2.500000
1.666667
0.750000
]

cmax

Returns the cumulative maximum of the values of a List or Timeseries

Syntax

cmax(list)
cmax(timeseries)
cmax(timeseries, calendar)

If you supply a Timeseries and a Calendar - the output will be cumulative maximum of the values aligned to the output calendar

Example

input = TimeSeries("DAILY")
input.add("2020-10-30", 10)
input.add("2020-10-31", 10)
input.add("2020-11-01", 11)
input.add("2020-11-02", 12)
input.add("2020-11-03", 12.9)
input.add("2020-11-04", 11.5)
input.add("2020-11-05", 11.9)
v = cmax(input)
print v.values

v = cmax(input, MonthlyCalendar())
print v.values

testarray = [-1,6,0,-2]
print cmax(testarray)
[
2020-10-30 10.0
2020-10-31 10.0
2020-11-01 11.0
2020-11-02 12.0
2020-11-03 12.900000
2020-11-04 12.900000
2020-11-05 12.900000
]
[
2020-10-01 10
2020-11-01 12.900000
]
[
-1.0
6.0
6.0
6.0
]

cmin

Returns the cumulative minimum of the values of a List or Timeseries

Syntax

cmin(list)
cmin(timeseries)
cmin(timeseries, calendar)

If you supply a Timeseries and a Calendar - the output will be cumulative minimum of the values aligned to the output calendar

Example

input = TimeSeries("DAILY")
input.add("2020-10-30", 10)
input.add("2020-10-31", 10)
input.add("2020-11-01", 11)
input.add("2020-11-02", 9.9)
input.add("2020-11-03", 12.9)
input.add("2020-11-04", 11.5)
input.add("2020-11-05", 11.9)
v = cmin(input)
print v.values

v = cmin(input, MonthlyCalendar())
print v.values

testarray = [-1,6,0,-2]
print cmin(testarray)
[
2020-10-30 10.0
2020-10-31 10.0
2020-11-01 10.0
2020-11-02 9.900000
2020-11-03 9.900000
2020-11-04 9.900000
2020-11-05 9.900000
]
[
2020-10-01 10
2020-11-01 9.900000
]
[
-1.0
-1.0
-1.0
-2.0
]

csum

Returns the cumulative sum of the values of a List or Timeseries

Syntax

csum(list)
csum(timeseries)
csum(timeseries, calendar)

If you supply a Timeseries and a Calendar - the output will be cumulative sums of the values aligned to the output calendar

Example

input = TimeSeries("DAILY")
input.add("2020-10-30", 10)
input.add("2020-10-31", 10)
input.add("2020-11-01", 11)
input.add("2020-11-02", 12)
input.add("2020-11-03", 12.9)
input.add("2020-11-04", 11.5)
input.add("2020-11-05", 11.9)
sum = csum(input)
print sum.values

sum = csum(input, MonthlyCalendar())
print sum.values

testarray = [-1,6,0,-2]
print csum(testarray)
[
2020-10-30 10.0
2020-10-31 20.0
2020-11-01 31.0
2020-11-02 43.0
2020-11-03 55.900000
2020-11-04 67.400000
2020-11-05 79.300000
]
[
2020-10-01 20
2020-11-01 79.300000
]
[
-1.0
5.0
5.0
3.0
]

exp

Returns Euler's number e raised to the power of a double value.

Special cases:

  • If the argument is NaN, the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is negative infinity, then the result is positive zero.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

exp(var)

geomean

Returns the geometric average value from a list of values.

Geometric mean, sometimes referred to as compounded annual growth rate or time-weighted rate of return, is the average rate of return of a set of values calculated using the products of the terms.

Geometric mean is an important tool for calculating portfolio performance for many reasons, but one of the most significant is it takes into account the effects of compounding.

Syntax

var = geomean(List or TimeSeries)

Result

A number representing the geometric average value from the input List or TimeSeries

Example

data = [1,2,3]
print geomean(data)
1.817121

log

Returns the natural logarithm (base e) of a double value.

Special cases:

  • If the argument is NaN or less than zero, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is positive zero or negative zero, then the result is negative infinity.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

log(var)

log10

Returns the base 10 logarithm of a double value.

Special cases:

  • If the argument is NaN or less than zero, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is positive zero or negative zero, then the result is negative infinity.
  • If the argument is equal to 10n for integer n, then the result is n.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

log10(var)

log1p

Returns the natural logarithm of the sum of the argument and 1. Note that for small values x, the result of log1p(x) is much closer to the true result of ln(1 + x) than the floating-point evaluation of log(1.0+x).

Special cases:

  • If the argument is NaN or less than -1, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is negative one, then the result is negative infinity.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

log10(var)

max

Returns the largest value from a list of values.

Syntax

var = max(List or TimeSeries)

Result

A number representing the largest value from the input List or TimeSeries

Example

data = [5,6.7,-2]
print max(data)
6.7

mean

Returns the arithmetic average value from a list of values

Returns the arithmetic average value from a list of values using the formula:

Syntax

var = mean(List or TimeSeries)

Result

A number representing the arithmetic average value from the input List or TimeSeries

Example

data = [1,2,3]
print mean(data)
2

min

Returns the smallest value from a list of values.

Syntax

var = min(List or TimeSeries)

Result

A number representing the smallest value from the input List or TimeSeries

Example

data = [5,6.7,-2]
print min(data)
-2

pow

Returns the value of the first argument raised to the power of the second argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

pow(base, exponent)

sin

Returns the trigonometric sine of an angle.

Special cases:

  • If the argument is NaN or an infinity, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

sin(var)

sinh

Returns the hyperbolic sine of a double value. The hyperbolic sine of x is defined to be (ex - e-x)/2 where e is Euler's number.

Special cases:

  • If the argument is NaN, then the result is NaN.
  • If the argument is infinite, then the result is an infinity with the same sign as the argument.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

sinh(var)

sqrt

Returns the correctly rounded positive square root of a double value.

Special cases:

  • If the argument is NaN or less than zero, then the result is NaN.
  • If the argument is positive infinity, then the result is positive infinity.
  • If the argument is positive zero or negative zero, then the result is the same as the argument.
  • Otherwise, the result is the double value closest to the true mathematical square root of the argument value.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

sqrt(var)

tan

Returns the trigonometric tangent of an angle.

Special cases:

  • If the argument is NaN or an infinity, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.

The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

tan(var)

tanh

Returns the hyperbolic tangent of a double value. The hyperbolic tangent of x is defined to be (ex - e-x)/(ex + e-x), in other words, sinh(x)/cosh(x). Note that the absolute value of the exact tanh is always less than 1.

Special cases:

  • If the argument is NaN, then the result is NaN.
  • If the argument is zero, then the result is a zero with the same sign as the argument.
  • If the argument is positive infinity, then the result is +1.0.
  • If the argument is negative infinity, then the result is -1.0.

The computed result must be within 2.5 ulps of the exact result. The result of tanh for any finite input must have an absolute value less than or equal to 1. Note that once the exact result of tanh is within 1/2 of an ulp of the limit value of ±1, correctly signed ±1.0 should be returned.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

tanh(var)

toDegrees

Converts an angle measured in radians to an approximately equivalent angle measured in degrees. The conversion from radians to degrees is generally inexact; users should not expect cos(toRadians(90.0)) to exactly equal 0.0.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

toDegrees(var)

toRadians

Converts an angle measured in degrees to an approximately equivalent angle measured in radians. The conversion from degrees to radians is generally inexact.

Works with:

  • Scalars
  • Timeseries
  • Curves
  • Lists/Arrays

Syntax

toRadians(var)