TSRunningSum function

The TSRunningSum function computes a running sum over SMALLFLOAT or DOUBLE PRECISION values.

Syntax

TSRunningSum(value      smallfloat, 
              num_values integer) 
returns smallfloat;

TSRunningSum(value      double precision, 
              num_values integer) 
returns double precision;
value
The input value to include in the running sum.
num_values
The number of values to include in the running sum, k.

Description

A running sum is the sum of the last k values, where k is supplied by the user. If a value is NULL, the previous value is used.

This function runs over a fixed number of elements, not over a fixed length of time; therefore, it might not be appropriate for irregular time series.

This function is useful only when used within the Apply function.

Returns

A SMALLFLOAT or DOUBLE PRECISION running sum of the last k values.

Example

The following function calculates the volume accumulation percentage. The columns represented by a through e are: high, low, close, volume, and number_of_days, respectively:
create function VAP(a float, b float,c float,d float, e int) returns int;
return cast(100 * TSRunningSum(d * ((c - b) - (a - c))/
(.0001 + a - b), e)/(.0001 + TSRunningSum(d,e)) as int);
end function;

Copyright© 2018 HCL Technologies Limited