CumProduct


CumProduct(X, I)

Returns an array with each element being the product of all of the elements of «X» along dimension «I» up to, and including, the corresponding element of «X».

Syntax:

CumProduct(X: Array[I]; I: Index, passNull: optional Boolean, reset: optional Array)

Examples

I :=
[1, 2, 3, 4, 5, 6, 7]
X :=
Array(I, [8, 2, 1, 5, -3, 0, 4])
CumProduct(X, I) →
[8, 16, 16, 80, -240, 0, 0] { indexed by I}

Library

Array functions

Optional Parameters

PassNull

«PassNull» is an optional boolean parameter that defaults to False. When it is omitted or explicitly set to False, CumProduct ignores Null values. In that case they have essentially the same effect as a one, unless they happen to be the first value in «X», in which case they are passed since no numeric values are yet obtained.

When «passNull» is explicitly set to true, then Null values are passed through as Null in the result.

X :=
[«null», «null», 4, 2, «null», «null», 2, -1, 3, 2, «null»]
CumProduct(X, I) →
[«null», «null», 4, 8, 8, 8, 16, -16, -48, -96, -96]
CumProduct(X, I, passNull: false) →
[«null», «null», 4, 8, 8, 8,16, -16, -48, -96, -96]
CumProduct(X, I, passNull: true) →
[«null», «null», 4, 8, «null», «null», 16, -16, -48, -96, «null»]

Reset

The optional «reset» parameter accepts an array of boolean values indexed by «I». At the positions where «reset» is true, CumProduct starts over. This sets the sum of all previous values to zero, so that the value at that position will be the same as the value in «X».

I :=
[1, 2, 3, 4, 5, 6, 7]
X :=
[8, 2, 1, 5, -3, 7, 5]
R :=
[0, 0, 1, 0, 0, 1, 0]
CumProduct(X, I, reset: R) →
[8, 16, 1, 5, -15, 7, 35]

«Reset» can be used to restart the cumulation each time some state change occurs. In such a scenario, the «reset» parameter is set to True at the first instant (along «I») that the system is in the new state.

Suppose IntRate is the monthly interest rate, indexed by Month. We'll assume the elements of Month are numeric dates corresponding to the first of each month. The following would compute the interest accrued up through the end of each month so far in the current year:

CumProduct((1 + IntRate), Month, Reset: DatePart(Month,"M") = 1 ) - 1

See Also

Comments


You are not allowed to post comments.