TSAddPrevious function

The TSAddPrevious function sums all the values it is called with and returns the current sum every time it is called. The current argument is not included in the sum.

Syntax

TSAddPrevious(current_value smallfloat) 
returns smallfloat;

TSAddPrevious(current_value double precision) 
returns double precision;
current_value
The current value.

Description

Use the TSAddPrevious function within an AggregateBy or Apply function. The TSAddPrevious function can take parameters that are columns of a time series. Use the same parameter format as the AggregateBy or Apply function accepts.

Returns

The sum of all previous values returned by this function.

Example

The following example uses the TSAddPrevious function to calculate the summation of the average dollars into or out of a market or equity:
select Apply('TSAddPrevious($vol * (($final - $low) - ($high - $final) / (.0001
+ $high - $low)) * (($high + $low + $final) / 3))',
      '2011-01-03 00:00:00.00000'::datetime year to fraction(5),
      '2011-01-08 00:00:00.00000'::datetime year to fraction(5),
      stock_data)::TimeSeries(one_real)
from daily_stocks
where stock_name = 'IBM';