Top-N Sequence Methods in C#

Top methods return the highest or lowest values in a sequence, or the positions of those values.

In the C# API, analytics operate on Sequence values obtained from OrderedSequence<T> searches, direct ordered-sequence iteration, UnorderedSequence<T>.All, or positional projections such as quote.Close[dayRange].

For an overview see page The C# Sequence Class

Operations

source.TopMax(int top)
Returns the top n maximum values.
source.TopMin(int top)
Returns the top n minimum values.
source.TopPosMax(int top)
Returns the positions of the top n maximum values.
source.TopPosMin(int top)
Returns the positions of the top n minimum values.

Example

This example uses TopPosMax together with Tee and Map to retrieve the top close prices and their matching volumes.

    Sequence[] topPositions = quote.Close.All.TopPosMax(10).Tee();
    using (Sequence topClose = quote.Close.Map(topPositions[0]))
    using (Sequence topVolume = quote.Volume.Map(topPositions[1]))
    {
        while (topClose.Next(out float price) && topVolume.Next(out uint volume))
        {
            printf("%s: price=%.3f, volume=%u\n",
                   __arglist(quote.Symbol, (double)price, volume));
        }
    }

    foreach (Sequence positionSequence in topPositions)
    {
        positionSequence.Dispose();
    }