The following collapse C++ Sequence methods operate on the object's and the input sequences, left and right, to produce the computed scalar result of type
double
.The method signatures are of the following form (where
op
is the indicated operation):double op(Sequence<T> const& weights) const;The following table lists the available collapse methods:
double wsum(Sequence<T> const& weights) const The first element of the result sequence is the weighted sum of the two sequences: left and right double wavg(Sequence<T> const& weights) const The first element of the result sequence is the weighted average of the two sequences: left and right double cov(Sequence<T> const& other) const The first element of the result sequence is the covariance of the two sequences: left and right double corr(Sequence<T> const& other) const The first element of the result sequence is the correlation of the two sequences: left and right Example
Following is an example code snippet demonstrating a collapse function:
{ 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, "e_cursor); rc != MCO_S_CURSOR_END; rc = mco_cursor_next(trans, "e_cursor)) { quote.from.cursor(trans, "e_cursor); // Calculate and display the correlation between low and high printf("%s: {%.3f}\n", (char*)symbol, quote.low_iterator().corr(quote.high_iterator())); } mco_trans_rollback(trans); } }