Grand Aggregate C Variation and Deviation Functions

The mco_seq_agg_var_TYPE()and mco_seq_agg_dev_TYPE()functions compute the variance and standard deviation for the input sequence and return a double value result as a single element in the result sequence. The variance is always a positive number; the smaller the value the closer the values of the sequence elements are to the mean. The standard deviation returned by mco_seq_agg_var_TYPE() is the square root of the variance. The mco_seq_agg_var_samp_TYPE() and mco_seq_agg_dev_samp_TYPE() functions perform the sample variance and sample standard deviation calculations for the sequence elements.

Example

Following is an example code snippet demonstrating these functions:

 
 
    void grand_aggregate(mco_db_h db)
    {
        mco_trans_h trans;
        mco_cursor_t quote_cursor;
        Quote quote;
        mco_seq_iterator_t close_iterator, var_iterator, dev_iterator;
        mco_seq_iterator_t var_samp_iterator, dev_samp_iterator;
        MCO_RET 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, &quote);
 
                /* Initialize iterators */
                Quote_close_iterator(&quote, &close_iterator));
 
                /* Construct operator's pipeline */
                mco_seq_agg_var_float(&var_iterator, &close_iterator);
                mco_seq_agg_dev_float(&dev_iterator, &close_iterator);
                mco_seq_agg_var_samp_float(&var_samp_iterator, &close_iterator);
                mco_seq_agg_dev_samp_float(&dev_samp_iterator, &close_iterator);
                 ...
             
            }
    }