Table of Contents

Class WindowAlgorithms

Namespace
Virtufin.Base.Behavior
Assembly
Virtufin.Base.dll

Pure, LINQ-based algorithms over a materialized window — the f in indicator.Take(n).Map(f) / indicator.TimeWindow(...).Map(f). Not a new abstraction: ordinary LINQ (.Average(), .Sum(), a custom .Aggregate(...)) already works directly on those combinators' ImmutableArray<T> results, since it implements IEnumerable<T>. This class only adds the named, reusable, non-trivial ones.

public static class WindowAlgorithms
Inheritance
WindowAlgorithms
Inherited Members

Methods

ShannonEntropy<T>(IReadOnlyCollection<T>, double)

The empirical Shannon entropy of a window, treating each element as a discrete symbol (grouped by Equals(object)) — -Σ p·log(p) over the window's observed symbol frequencies.

public static double ShannonEntropy<T>(this IReadOnlyCollection<T> window, double logBase = 2)

Parameters

window IReadOnlyCollection<T>

The window to compute entropy over.

logBase double

The logarithm base — 2 (bits, the default), e (nats, via E), or any other base.

Returns

double

0 for an empty window or a window of a single repeated symbol; up to log(distinct symbol count, logBase) for a uniform distribution.

Type Parameters

T

The window element type.

Remarks

For continuous-valued sources (raw prices, raw returns), bucket or quantize into a small symbol set before calling this — entropy over all-distinct values is degenerate (every symbol appears once, so the result is always the meaningless maximum for the window size).