Cumulative sum (CSUM#)

This calculates the cumulative sum of values in a series from a specified start date to the end date for the display period. The calculations use the display or request frequency.

Formats

CSUM#(Expression,Start Date)

Where Start Date defines the start date for the calculation. When a start date is used no Datastream function can be nested inside. The start date must be earlier than, or the same as, the display period end date. Actual dates are typed in using either the standard DD/MM/YY format or the displacement date formats. The displacement date format uses the request end date as offset date. As the date parameter one can also use YRE, HFE, QTE, MTE, WKE, LYE, BDATE, BDATEXXF, MIN, MAX

CSUM#(Expression)

As above. If you do not specify a start date, the default is the start date on the input screen.

CSUM#(Expression,MIN), CSUM#(Expression,MAX)

Functions MIN and MAX can be a parameter to determine where the summation begins and null values are output before that start date.

CSUM#(Expression, Date Parameter, Restart parameter)

The trailing parameter allows the cumulative sum to restart periodically.

Possible values are here WY, MY, QY, YR for weekly, monthly, quarterly and yearly restarts, respectively. It is also possible to use for example 15D for a restart every 15 days, etc.

If the parameter is for example 2M the number of days used for 2M is determined at start date and used throughout the request. Adding an M, that is 2MM means that the number of days is recalculated at each point in time when a restart is due.This calculation looks 2M forward and if that date is a non-working day the restart will be on the first following day, but the non-working day will serve as offset for the next restart.

CSUM#(Expression, Date Parameter, Restart parameter,Sign parameter)

The last parameter will set the cumulative sum equal to zero if Expression is not positive for parameter value POS; or if Expression is not negative for parameter value NEG.

 

Examples

CSUM#(UKCURACBB,01/01/90)

This calculates the cumulative monthly UK current account balance from January 1990.

CSUM#(UKCURACBB)

This default format calculates the cumulative monthly UK current account balance for the period between the start and end dates for the display period.

CSUM#(MKS(VO),-1Y,QY)

This calculates from start date -1Y the cumulative volume using calendar quarterly restarts.

CSUM#(IF#(ACH#(S&PCOMP,1D),GE,ZERO),,,POS)

This calculates the number of consecutive days without the index declining.

0-CSUM#(IF#(ACH#(S&PCOMP,1D),GE,ONE),,,NEG)

This calculates the number of consecutive days with the index declining.

See also

Sum functions