CUMSUM

Purpose:

Calculates the cumulative sum of a series.

Syntax:

CUMSUM(series, dim, "naflag")

series

-

A series or array, the input series.

dim

-

Optional. An integer or string, the computation dimension.

1

:

calculate column-wise (default)

2

:

calculate row-wise

"naflag"

-

Optional. A string, the NA handling method.

"includenan"

:

include NA values (default)

"omitnan"

:

ignore NA values

Returns:

A series or table.

Example:

cumsum({20, 15, 30, 10, 25})

 

returns {20, 35, 65, 75, 100}.

Example:

W1: integ(gnorm(1000, 1))

W2: cumsum(W1)

 

sum(W1) == W2[end]

 

The last point of CUMSUM is the overall sum of the input data.

 

Example:

W1: {{1, 2, 3},

     {4, 5, 6},

     {7, 8, 9}}

 

W2: cumsum(w1)

W3: cumsum(w1, 1)

W4: cumsum(w1, 2)

 

W2 == {{ 1,  2,  3},

       { 5,  7,  9},

       {12, 15, 18}}

 

W3 == {{ 1,  2,  3},

       { 5,  7,  9},

       {12, 15, 18}}

 

W4 == {{1,  3,  6},

       {4,  9, 15},

       {7, 15, 24}}

 

Both W2 and W3 compute the cumulative sum along the columns.

 

W4 computes the cumulative sum along the rows.

 

Example:

W1: {{1,   2, 3},

     {nan, 5, 6},

     {7,   8, 9}}

 

W2: cumsum(w1)

W3: cumsum(w1, 1)

W4: cumsum(w1, 2)

 

W2 == {{  1,  2,  3},

       {nan,  7,  9},

       {nan, 15, 18}}

 

W3 == {{  1,  2,  3},

       {nan,  7,  9},

       {nan, 15, 18}}

 

W4 == {{  1,   3,  6},

       {nan, nan, nan},

       {  7,  15, 24}}

 

The NaN value is included in the computations by default.

Example:

W1: {{1,   2, 3},

     {nan, 5, 6},

     {7,   8, 9}}

 

W2: cumsum(w1, "omitnan")

W3: cumsum(w1, 1, "omitnan")

W4: cumsum(w1, 2, "omitnan")

 

W2 == {{1,  2,  3},

       {1,  7,  9},

       {8, 15, 18}}

 

W3 == {{1,  2,  3},

       {1,  7,  9},

       {8, 15, 18}}

 

W4 == {{1,   3,  6},

       {0,   5, 11},

       {7,  15, 24}}

 

Same as above except the NaN value is omitted from the computations.

Remarks:

The nth value of the output series is equal to the sum of the first n points of the input series:

 

image\cumsum01.svg

 

or by the equivalent difference equation:

 

image\cumsum02.svg

 

CUMSUM calculates the cumulative sum of a series.

 

CUMSUM differs from integration in that the DELTAX information is not incorporated into the calculation.

 

CUMSUM is produces the same results as PARTSUM.

 

See CUMAVG to compute the cumulative average.

 

See CUMPROD to calculate the cumulative product.

See Also:

CUMAVG

CUMMAX

CUMMIN

CUMPROD

CUMTRAPZ

INTEG

PARTSUM

SUM