The following manipulator C++ Sequence methods take a variety of sequence arguments and produce result sequences as described below:
Sequence<T> reverse() constReverses the elements of the input sequence.Sequence<T> concat(Sequence<T> const& other) constalso
operator,(Sequence<T> const& other) constConcatenates two sequences of any type by appending sequence right to sequence left. The result sequence will be of the same type as left and right.
Sequence<T> limit(mco_seq_no_t from, mco_seq_no_t till) constalso
Sequence<T> operator()(mco_seq_no_t from, mco_seq_no_t till) constCopies to the result sequence the subsequence from the input using sequence positions from and till.
void get(std::vector<T>& result)Extracts data from the input sequence to the buffer result.Sequence<T> unique() constCopies to the result sequence only the unique elements in the ordered sequence input by "collapsing duplicates".
Sequence<double> norm() constReturns in result the normalized input sequence, i.e., divides each sequence element by the square root of the sum of squares of all elements.
Sequence<T> thin(mco_size_t origin, mco_size_t step) constCopies the input sequence to result, selecting elements with the specified origin and step.
Sequence<T> diff() constReturns in result the differences between pairs of sequence elements in input.Sequence<T> combine(Sequence<T> const& other, mco_seq_order_t order) constReturns in result the union of the two ordered sequences left and right using the specified order. Note that result will contain different elements from both input sequences.
Sequence<T> map(Sequence<mco_seq_no_t> const& positions) constalso
Sequence<T> operator[](Sequence<mco_seq_no_t> const& positions) constReturns in result the elements extracted from the input sequence using the positions specified in the positions sequence. The positions should be provided in ascending order.
Sequence<T> repeat(int nTimes) constReturns in result each element of the input sequence repeated nTimes times.Sequence<T> stretch(Sequence<TS> const& ts1, Sequence<TS> const& ts2, T filler) constReturns in result the elements of the values sequence stretched to the length of the ts1 sequence by repeating the elements of values while the corresponding timestamp in sequence ts2 is larger than the timestamp from ts1. Uses the filler values for elements where the corresponding timestamp in sequence ts2 is less than the timestamp from ts1.
For example, assume ts1 =
{1,2,3,4,5}, ts2 ={2,4}, values ={1.1,2.2}and filler =1.0. With these input sequences, the result will be{1.1,2.2,2.2,1.0,1.0}.(This method can be used to calculate a split-adjusted price where it is necessary to reverse a time series of splits, calculate the cumulative product and multiply by the price.)
Sequence<T> stretch0(Sequence<TS> const& ts1, Sequence<TS> const& ts2, T filler) constReturns in result the elements of the values sequence and filler by injecting the elements of values where the corresponding timestamps in sequence ts2 match the timestamp from ts1. Uses filler for elements where the timestamp in sequence ts1 has no matching timestamp in ts2.
For example, assume ts1 =
{1,2,3,4,5}, ts2 ={2,3,4}, values ={1.1,1.2,1.3}and filler =0.0. With these input sequences, the result will be{0.0,1.1,1.2,1.3,0.0}.Sequence<T> asofJoin(Sequence<TS> const& ts1, Sequence<TS> const& ts2) constReturns in result the elements of the values sequence corresponding to the timestamp of ts2 closest to the timestamp of ts1.
For example, assume ts1 =
{4,9}, ts2 ={1,3,6,10}, and values ={0.1,0.3,0.6,1.0}. With these input sequences, the result will be{0.3,1.0}.Sequence<mco_seq_no_t> cross(int first_cross_direction) constReturns in result the positions in the input sequence where it crosses zero. If the integer argument first_cross_direction is positive, then the result sequence starts with the first crossing above zero; if negative, it starts with the first crossing below zero; if first_cross_direction is zero, then the first crossing can be above or below zero.
Sequence<mco_seq_no_t> extrema(int first_extremum) constReturns in result the positions of extrema (local minima and maxima) in the input sequence. If the integer argument first_extremum is positive, then the result sequence starts with the first local maximum; if negative, it starts with the first local minimum; if first_extremum is zero, then either can come first.
Example
Following is an example code snippet demonstrating a sequence manipulator 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 window (moving) aggregates. Find the dates // when the 20-day moving average crosses over the // 5-day moving average print_sequence(quote, quote.day_map( (quote.close_iterator().windowAggAvg(20) - quote.close_iterator().windowAggAvg(5)).cross(1))); } mco_trans_rollback(trans); } }