Window Aggregate C++ Sequence Methods

Like Grid Aggregate methods, all C++ Sequence Window Aggregate methods take an integer interval argument and produce a result sequence containing the calculated aggregate for each interval. The difference in how Window Aggregate methods determine their sliding window interval is described in the Window versus Grid Aggregate page. The result of all Window Aggregate methods is returned in the result sequence as the calculated aggregate for each interval. As with Grid Aggregate methods, the object's sequence is split into intervals based on the value of the interval argument (of type uint8) which determines the maximum number of elements in the group, though there may be fewer. So the input sequence will be divided into blocks of interval elements on which the operation is performed.

Sequence<T> windowAggMax(mco_size_t interval) const Returns the sequence with the maximum value for each window of elements
Sequence<T> windowAggMin(mco_size_t interval) const Returns the sequence with the minimum value for each window of elements
Sequence<R> windowAggSum(mco_size_t interval) const Returns the sequence with the sum of each window of elements
Sequence<double> windowAggAvg(mco_size_t interval) const Returns the sequence with the average of each window of elements
Sequence<double> windowAggVar(mco_size_t interval) const Returns the sequence with the variance of each window of elements
Sequence<double> windowAggVarSamp(mco_size_t interval) const Returns the sequence with the sample variance of each window of elements
Sequence<double> windowAggDev(mco_size_t interval) const Returns the sequence with the standard deviation of each window of elements
Sequence<double> windowAggDevSamp(mco_size_t interval) const Returns the sequence with the sample standard deviation of each window of elements

Example

Following is an example code snippet demonstrating a window aggregate method:

         
    {
        mco_trans_h trans;
        mco_cursor_t quote_cursor;
        Quote quote;
        MCO_RET rc;
        ...
        rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &trans);
        if ( MCO_S_OK == rc )
        {
         
            for (rc = mco_cursor_first(trans, &quote_cursor); 
                rc != MCO_S_CURSOR_END; 
                rc = mco_cursor_next(trans, &quote_cursor)) 
            {
                quote.from.cursor(trans, &quote_cursor);
                 
                // Calculate window (moving) aggregates. Find the dates when the 20-day moving 
                // average crosses over the 5-days moving average
                print_sequence(quote, quote.day_map((quote.close_iterator().windowAggAvg(20) - 
                        quote.close_iterator().windowAggAvg(5)).cross(1)));
            }
            mco_trans_rollback(trans);
        }
    }